Advertisement
Guest User

Untitled

a guest
Aug 15th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. mount -t proc none /proc
  4. mount -t sysfs none /sys
  5.  
  6. /bin/busybox --install -s
  7.  
  8. # create mtab so that fsck won't complain
  9. /bin/ln -sf /proc/mounts /etc/mtab
  10.  
  11. # wait for slow sdcards
  12. /bin/sleep 5
  13.  
  14. # populate /dev
  15. /sbin/mdev -s
  16.  
  17. ROOTDEV=""
  18. ROOTFSTYPE="ext4"
  19. ROOTFSOPTS="noatime"
  20. RWFS=""
  21. RWFSTYPE=""
  22. RWFSOPTS="noatime"
  23. AUFS=false
  24. AUFSCK=false
  25.  
  26. for x in $(/bin/cat /proc/cmdline); do
  27.     case $x in
  28.     root=*)
  29.         ROOTDEV=${x#root=}
  30.         ;;
  31.     rootfstype=*)
  32.         ROOTFSTYPE=${x#rootfstype=}
  33.         ;;
  34.     rootfsopts=*)
  35.         ROOTFSOPTS=${x#rootfsopts=}
  36.         ;;
  37.     rwfs=*)
  38.         RWFS=${x#rwfs=}
  39.         ;;
  40.     rwfstype=*)
  41.         RWFSTYPE=${x#rwfstype=}
  42.         ;;
  43.     rwfsopts=*)
  44.         RWFSOPTS=${x#rwfsopts=}
  45.         ;;
  46.     aufsck)
  47.         AUFSCK=true
  48.         ;;
  49.     esac
  50. done
  51.  
  52. # check root device
  53. if [ ! -b "${ROOTDEV}" ]; then
  54.     echo "Root partition ${ROOTDEV} missing"
  55.     exec /bin/sh
  56.     exit 0
  57. fi
  58.  
  59. # fsck root partition
  60. echo "Checking root partition ${ROOTDEV}"
  61. /sbin/e2fsck.static -y ${ROOTDEV}
  62.  
  63. # mount root
  64. echo -n "Mounting root partition ${ROOTDEV} "
  65. mount -t ${ROOTFSTYPE} -o ro,${ROOTFSOPTS} ${ROOTDEV} /rootfs
  66. if [ $? -ne 0 ]; then
  67.     echo "failed"
  68.     exec /bin/sh
  69.     exit 0
  70. else
  71.     echo "OK"
  72. fi
  73.  
  74. # check for rw partition
  75. if [ "${RWFS}" = "tmpfs" ]; then
  76.     RWFS="aufs-tmpfs"
  77.     RWFSTYPE="tmpfs"
  78.     RWFSOPTS="rw"
  79. else
  80.     if [ ! -b "${RWFS}" ]; then
  81.         echo "RW partition ${RWFS} missing"
  82.    RWFS=""
  83.     fi
  84. fi
  85.  
  86. if ${AUFSCK} && [ -b "${RWFS}" ]; then
  87.     # fsck rw partition
  88.     echo "Checking RW partition ${ROOTDEV}"
  89.     /sbin/e2fsck.static -y ${RWFS}
  90. fi
  91.  
  92. if [ -n "${RWFS}" ]; then
  93.     # mount rw partition
  94.     echo -n "Mounting RW partition ${RWFS} "
  95.     mount -o ${RWFSOPTS} -t ${RWFSTYPE} ${RWFS} /rw
  96.     if [ $? -ne 0 ]; then
  97.         echo "failed"
  98.         AUFS=false
  99.     else
  100.         echo "OK"
  101.         AUFS=true
  102.     fi
  103. else
  104.     AUFS=false
  105. fi
  106.  
  107. if ${AUFS}; then
  108.     # mount aufs partition
  109.     echo -n "Mounting AUFS "
  110.     mount -t aufs -o dirs=/rw:/rootfs=ro aufs /aufs
  111.     if [ $? -ne 0 ]; then
  112.         echo "failed"
  113.         AUFS=false
  114.     else
  115.         echo "OK"
  116.     fi
  117. fi
  118.  
  119. if ${AUFS}; then
  120.     # mount aufs  as root partition
  121.     # test for mount points on aufs file system
  122.     [  -d /aufs/ro ] || /bin/mkdir /aufs/ro
  123.     [  -d /aufs/rw ] || /bin/mkdir /aufs/rw
  124.  
  125.     # move RO and RW inside aufs
  126.     mount --move /rw /aufs/rw
  127.     mount --move /rootfs /aufs/ro
  128.     # cleanup
  129.     umount /proc
  130.     umount /sys
  131.  
  132.     # Boot the real thing
  133.     exec switch_root /aufs /sbin/init
  134. else
  135.     # revert to normal rootfs
  136.     # remount root rw
  137.     mount -o remount,rw ${ROOTDEV}
  138.     # cleanup
  139.     umount /proc
  140.     umount /sys
  141.  
  142.     # Boot the real thing
  143.     exec switch_root /rootfs /sbin/init
  144. fi
  145.  
  146. echo "Failed to switch_root, dropping to a shell"
  147. exec /bin/sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement