Advertisement
Guest User

Untitled

a guest
Aug 12th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. # Local filesystem mounting -*- shell-script -*-
  2.  
  3. pre_mountroot()
  4. {
  5. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
  6. run_scripts /scripts/local-top
  7. [ "$quiet" != "y" ] && log_end_msg
  8. }
  9.  
  10. mountroot()
  11. {
  12. # list of possible userdata partition names
  13. partlist="userdata UDA DATAFS USERDATA"
  14.  
  15. /bin/lvm.static vgscan
  16. /bin/lvm.static vgchange -ay
  17. udevadm settle
  18.  
  19. pre_mountroot
  20.  
  21. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
  22. run_scripts /scripts/local-premount
  23. [ "$quiet" != "y" ] && log_end_msg
  24.  
  25. # Mount root
  26. #
  27. # Create a temporary mountpoint for the bindmount
  28. mkdir -p /tmpmnt
  29.  
  30. # Make sure the device has been created by udev before we try to mount
  31. udevadm settle
  32.  
  33. # find the right partition
  34. for partname in $partlist; do
  35. part=$(find /dev -name $partname|tail -1)
  36. path=$(readlink -f $part)
  37. [ -n "$path" ] && break
  38. done
  39.  
  40. echo "initrd: mounting $path" >/dev/kmsg || true
  41.  
  42. # Mount the data partition to a temporary mount point
  43. mount /dev/store/cm-data /tmpmnt
  44. mount --bind /tmpmnt/ubuntu ${rootmnt}
  45.  
  46. # Loop-mounted flipped model
  47. if [ -e /tmpmnt/system.img ]; then
  48. # Prepare the root filesystem
  49. if [ -e /tmpmnt/.developer_mode ]; then
  50. echo "initrd: mounting system.img (developer mode)" >/dev/kmsg || true
  51. mount -o loop,rw /tmpmnt/system.img ${rootmnt}
  52. mountroot_status="$?"
  53. else
  54. echo "initrd: mounting system.img (user mode)" >/dev/kmsg || true
  55. mount -o loop,ro /tmpmnt/system.img ${rootmnt}
  56. mountroot_status="$?"
  57. fi
  58. mkdir ${rootmnt}/userdata
  59. mount --move /tmpmnt ${rootmnt}/userdata
  60.  
  61. # Mount the android system partition to a temporary location
  62. mkdir -p /android-system /android-initrd
  63. mount /dev/store/cm-system /android-system
  64.  
  65. # Get device information
  66. device=$(grep ^ro.product.device= /android-system/build.prop |sed -e 's/.*=//')
  67. [ -z "$device" ] && device="unknown"
  68. echo "initrd: device is $device" >/dev/kmsg || true
  69.  
  70. # Mount some tmpfs
  71. mount -o rw,size=4096 -t tmpfs none ${rootmnt}/android
  72. mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs ${rootmnt}/run
  73.  
  74. # Create some needed paths on tmpfs
  75. mkdir -p ${rootmnt}/android/data ${rootmnt}/android/system
  76.  
  77. # Prepare the fstab
  78. FSTAB=${rootmnt}/etc/fstab
  79. touch ${rootmnt}/run/image.fstab
  80. mount -o bind ${rootmnt}/run/image.fstab $FSTAB || panic "drop to adb"
  81. echo "/dev/root / rootfs defaults,ro 0 1" >> $FSTAB
  82.  
  83. # Process the list of bind-mounts
  84. # (but don't mount them, mountall will do it)
  85. cat ${rootmnt}/etc/system-image/writable-paths | while read line; do
  86. set -- $line
  87. # Skip invalid/commented entries
  88. ([ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]) && continue
  89. [ "$1" = "#" ] && continue
  90.  
  91. # Skip invalid mount points
  92. dstpath="${rootmnt}/$1"
  93. [ ! -e "$dstpath" ] && continue
  94.  
  95. if [ "$3" = "temporary" ]; then
  96. # Temporary entries are simple, just mount a tmpfs
  97. echo "tmpfs $1 tmpfs defaults 0 1" >> $FSTAB
  98. elif [ "$3" = "persistent" ]; then
  99. # Figure out the source path
  100. if [ "$2" = "auto" ]; then
  101. srcpath="${rootmnt}/userdata/system-data/$1"
  102. path="/userdata/system-data/$1"
  103. else
  104. srcpath="${rootmnt}/userdata/$2"
  105. path="/userdata/$2"
  106. fi
  107.  
  108. if [ ! -e "$srcpath" ]; then
  109. # Process new persistent paths
  110. mkdir -p ${srcpath%/*}
  111. if [ ! -d "$dstpath" ]; then
  112. # Deal with redirected files
  113. if [ "$4" = "transition" ]; then
  114. cp -a $dstpath $srcpath
  115. else
  116. touch $srcpath
  117. fi
  118. else
  119. # Deal with redirected directories
  120. if [ "$4" = "transition" ]; then
  121. cp -aR $dstpath $srcpath
  122. else
  123. mkdir $srcpath
  124. fi
  125. fi
  126. fi
  127.  
  128. # Write the fstab entry
  129. echo "$path $1 none bind 0 1" >> $FSTAB
  130. else
  131. continue
  132. fi
  133. done
  134.  
  135. # Extract the fstab from the android initrd
  136. # NOTE: we should find a faster way of doing that or cache it
  137. OLD_CWD=$(pwd)
  138. cd /android-initrd
  139. cat /android-system/boot/android-ramdisk.img | gzip -d | cpio -i fstab*
  140. cd $OLD_CWD
  141.  
  142. # Mount all the Android partitions
  143. cat /android-initrd/fstab.* | while read line; do
  144. set -- $line
  145.  
  146. # Skip any unwanted entry
  147. echo $1 | egrep -q "^#" && continue
  148. ([ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]) && continue
  149. ([ "$2" = "/system" ] || [ "$2" = "/data" ]) && continue
  150.  
  151. label=$(echo $1 | awk -F/ '{print $NF}')
  152. [ -z "$label" ] && continue
  153. for dir in by-partlabel by-name by-label; do
  154. path="/dev/disk/$dir/$label"
  155. [ -e "$path" ] && break
  156. done
  157. [ ! -e "$path" ] && continue
  158.  
  159. mkdir -p ${rootmnt}/android/$2
  160. echo "initrd: mounting $path as ${rootmnt}/android/$2" >/dev/kmsg || true
  161. mount $path ${rootmnt}/android/$2 -t $3 -o $4
  162. done
  163.  
  164. # system is a special case
  165. echo "initrd: mounting ${rootmnt}/var/lib/lxc/android/system.img as ${rootmnt}/android/system" >/dev/kmsg || true
  166. mount --bind /android-system ${rootmnt}/android/system
  167. mount --bind ${rootmnt}/userdata ${rootmnt}/android/data
  168.  
  169.  
  170. # Apply device-specific udev rules
  171. if [ "$device" != "unknown" ]; then
  172. mount --bind ${rootmnt}/usr/lib/lxc-android-config/70-$device.rules ${rootmnt}/lib/udev/rules.d/70-android.rules
  173. fi
  174.  
  175. # Bind-mount /lib/modules from Android
  176. [ -e /android/system/lib/modules ] && mount --bind /android/system/lib/modules ${rootmnt}/lib/modules
  177.  
  178. # Old flipped model
  179. elif [ -d /tmpmnt/ubuntu ]; then
  180. mount --bind /tmpmnt/ubuntu ${rootmnt}
  181. mountroot_status="$?"
  182.  
  183. # Possibly a re-partitioned device
  184. else
  185. echo "initrd: Couldn't find a system partition." >/dev/kmsg || true
  186. panic "Couldn't find a system partition. Spawning adbd ..."
  187. fi
  188.  
  189. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
  190. run_scripts /scripts/local-bottom
  191. [ "$quiet" != "y" ] && log_end_msg
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement