Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- mount -t proc none /proc
- mount -t sysfs none /sys
- /bin/busybox --install -s
- # create mtab so that fsck won't complain
- /bin/ln -sf /proc/mounts /etc/mtab
- # wait for slow sdcards
- /bin/sleep 5
- # populate /dev
- /sbin/mdev -s
- ROOTDEV=""
- ROOTFSTYPE="ext4"
- ROOTFSOPTS="noatime"
- RWFS=""
- RWFSTYPE=""
- RWFSOPTS="noatime"
- AUFS=false
- AUFSCK=false
- for x in $(/bin/cat /proc/cmdline); do
- case $x in
- root=*)
- ROOTDEV=${x#root=}
- ;;
- rootfstype=*)
- ROOTFSTYPE=${x#rootfstype=}
- ;;
- rootfsopts=*)
- ROOTFSOPTS=${x#rootfsopts=}
- ;;
- rwfs=*)
- RWFS=${x#rwfs=}
- ;;
- rwfstype=*)
- RWFSTYPE=${x#rwfstype=}
- ;;
- rwfsopts=*)
- RWFSOPTS=${x#rwfsopts=}
- ;;
- aufsck)
- AUFSCK=true
- ;;
- esac
- done
- # check root device
- if [ ! -b "${ROOTDEV}" ]; then
- echo "Root partition ${ROOTDEV} missing"
- exec /bin/sh
- exit 0
- fi
- # fsck root partition
- echo "Checking root partition ${ROOTDEV}"
- /sbin/e2fsck.static -y ${ROOTDEV}
- # mount root
- echo -n "Mounting root partition ${ROOTDEV} "
- mount -t ${ROOTFSTYPE} -o ro,${ROOTFSOPTS} ${ROOTDEV} /rootfs
- if [ $? -ne 0 ]; then
- echo "failed"
- exec /bin/sh
- exit 0
- else
- echo "OK"
- fi
- # check for rw partition
- if [ "${RWFS}" = "tmpfs" ]; then
- RWFS="aufs-tmpfs"
- RWFSTYPE="tmpfs"
- RWFSOPTS="rw"
- else
- if [ ! -b "${RWFS}" ]; then
- echo "RW partition ${RWFS} missing"
- RWFS=""
- fi
- fi
- if ${AUFSCK} && [ -b "${RWFS}" ]; then
- # fsck rw partition
- echo "Checking RW partition ${ROOTDEV}"
- /sbin/e2fsck.static -y ${RWFS}
- fi
- if [ -n "${RWFS}" ]; then
- # mount rw partition
- echo -n "Mounting RW partition ${RWFS} "
- mount -o ${RWFSOPTS} -t ${RWFSTYPE} ${RWFS} /rw
- if [ $? -ne 0 ]; then
- echo "failed"
- AUFS=false
- else
- echo "OK"
- AUFS=true
- fi
- else
- AUFS=false
- fi
- if ${AUFS}; then
- # mount aufs partition
- echo -n "Mounting AUFS "
- mount -t aufs -o dirs=/rw:/rootfs=ro aufs /aufs
- if [ $? -ne 0 ]; then
- echo "failed"
- AUFS=false
- else
- echo "OK"
- fi
- fi
- if ${AUFS}; then
- # mount aufs as root partition
- # test for mount points on aufs file system
- [ -d /aufs/ro ] || /bin/mkdir /aufs/ro
- [ -d /aufs/rw ] || /bin/mkdir /aufs/rw
- # move RO and RW inside aufs
- mount --move /rw /aufs/rw
- mount --move /rootfs /aufs/ro
- # cleanup
- umount /proc
- umount /sys
- # Boot the real thing
- exec switch_root /aufs /sbin/init
- else
- # revert to normal rootfs
- # remount root rw
- mount -o remount,rw ${ROOTDEV}
- # cleanup
- umount /proc
- umount /sys
- # Boot the real thing
- exec switch_root /rootfs /sbin/init
- fi
- echo "Failed to switch_root, dropping to a shell"
- exec /bin/sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement