Created
February 14, 2012 14:55
-
-
Save krha/1827338 to your computer and use it in GitHub Desktop.
script for pivot_root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# credential: http://www.bluegecko.net/amazon-web-services/ec2-persistent-boots-with-pivot-root/ | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
NEWDEV="/dev/xvdf1" | |
NEWTYP="ext4" | |
NEWMNT="/mnt/ebs" | |
OLDMNT="/mnt/old" | |
OPTIONS="noatime,rw" | |
SLEEP=1 | |
echo "Remounting writable." | |
mount -o remount,rw / | |
[ ! -d $NEWMNT ] && echo "Creating directory $NEWMNT." && mkdir -p $NEWMNT | |
while true ; do | |
echo "waiting for mounting.." | |
sleep $SLEEP | |
echo "Trying to mount $NEWDEV writable." | |
mount -t $NEWTYP -o rw $NEWDEV $NEWMNT || continue | |
echo "Mounted." | |
break; | |
done | |
[ ! -d $NEWMNT/$OLDMNT ] && echo "Creating directory $NEWMNT/$OLDMNT." && mkdir -p $NEWMNT/$OLDMNT | |
echo "Remounting $NEWMNT $OPTIONS." | |
mount -o remount,$OPTIONS $NEWMNT | |
echo "Trying to pivot." | |
cd $NEWMNT | |
pivot_root . ./$OLDMNT | |
for dir in /dev /proc /sys; do | |
echo "Moving mounted file system ${OLDMNT}${dir} to $dir." | |
mount --move ./${OLDMNT}${dir} ${dir} | |
done | |
echo "Chaning directory to new root" | |
cd ~ | |
echo "Tying to chroot and umount $OLDMNT." | |
echo "init argument $*" | |
exec chroot . /bin/sh -c 'umount $OLDMNT; exec /sbin/init $*' < /dev/console > /dev/console 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment