Advertisement
Guest User

Untitled

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