#! /bin/sh # # move root-filesystem to aufs filesystem { echo -e "\nCopy initramfs to aufs: " mount /proc mount /sys busybox --install -s mdev -s test -e /dev/cdrom -a ! -e /dev/dvd && cp -a /dev/cdrom /dev/dvd # copy root filesystem to tmpfs mkdir /mnt/system mount -n tmpfs /mnt/system -t tmpfs find / -maxdepth 1 ! -wholename / ! -name dev ! -name mnt ! -name proc ! -name sys -exec cp -a {} /mnt/system ";" mkdir -p /mnt/system/dev /mnt/system/mnt /mnt/system/proc /mnt/system/sys chown -Rh root:root /mnt dir=${dir-mld} dev=${dev-$(blkid | grep $id | sed "s/:.*//")} if [ -z "$dev" ];then echo -e "System device not found\n Maybe it's a slow USB device. Try again in 10 Seconds..." sleep 10 dev=$(blkid | grep $id | sed "s/:.*//") if [ -z "$dev" ];then echo -e "System device not found" sh fi fi dev=${dev##*/} echo "Import system directory from /mnt/$dev/$dir: " mkdir /mnt/$dev mount /dev/$dev /mnt/$dev if [ "$(mount | grep /dev/$dev | cut -d " " -f5)" = "ext3" ];then mkdir /mnt/aufs mount -n -t aufs -o dirs=/mnt/$dev/$dir:/mnt/system aufs /mnt/aufs # mount -n -t aufs -o dirs=/mnt/$dev/$dir:/mnt/system,create=tdp:td aufs /mnt/aufs else mkdir /mnt/tmp /mnt/aufs mount -n tmpfs /mnt/tmp -t tmpfs mount -n -t aufs -o dirs=/mnt/tmp:/mnt/$dev/$dir:/mnt/system aufs /mnt/aufs # mount -n -t aufs -o dirs=/mnt/tmp:/mnt/$dev/$dir:/mnt/system,create=tdp:td aufs /mnt/aufs fi mount -n tmpfs /mnt/aufs/tmp -t tmpfs mount -n tmpfs /mnt/aufs/dev -t tmpfs cp -a /dev/* /mnt/aufs/dev/ # make all filesystems available after chroot mkdir -p /mnt/aufs/mnt/$dev mount -n -o move /mnt/$dev /mnt/aufs/mnt/$dev #mkdir -p /mnt/aufs/mnt/system /mnt/aufs/mnt/tmp #mount -n -o move /mnt/system /mnt/aufs/mnt/system #mount -n -o move /mnt/tmp /mnt/aufs/mnt/tmp 2>/dev/null while ! umount /sys; do sleep 1 done umount /proc echo "/mnt/$dev/$dir" > /tmp/sys_dir } 2>&1 | tee -a /var/log/sysinit mv /var/log/sysinit /mnt/aufs/var/log/sysinit export sys_dir=$(cat /tmp/sys_dir) exec run_init /mnt/aufs /sbin/init