Skip to content

Instantly share code, notes, and snippets.

@vinipsmaker
Created October 5, 2013 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinipsmaker/6840437 to your computer and use it in GitHub Desktop.
Save vinipsmaker/6840437 to your computer and use it in GitHub Desktop.
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
dirs=(/dev /dev/pts /dev/shm /tmp)
case $1 in
start)
stat_busy "Starting Ubuntu chroot"
mount -o loop -t ext4 /path/to/chrootbuntu.sda1.ext4.img /srv/chroot/lucid
for d in "${dirs[@]}"; do
mount -o bind $d /srv/chroot/lucid$d
done
mount -t proc none /srv/chroot/lucid/proc
mount -t sysfs none /srv/chroot/lucid/sys
add_daemon chrootbuntu
stat_done
;;
stop)
stat_busy "Stopping Ubuntu chroot"
for (( i = ${#dirs[@]} - 1; i >= 0; i-- )); do
umount "/srv/chroot/lucid${dirs[i]}"
done
umount /srv/chroot/lucid/{proc,sys}
umount /srv/chroot/lucid
rm_daemon chrootbuntu
stat_done
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment