Skip to content

Instantly share code, notes, and snippets.

@nmilosev
Created March 14, 2017 23:07
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 nmilosev/a50c6d545363dd6058c988894d34df6a to your computer and use it in GitHub Desktop.
Save nmilosev/a50c6d545363dd6058c988894d34df6a to your computer and use it in GitHub Desktop.
# chroot into a LXC container
#!/bin/bash
export CONTAINERPATH="/var/lib/lxc/$1"
echo "Entering chroot... at $CONTAINERPATH"
mount -t proc proc "$CONTAINERPATH/rootfs/proc"
mount -t sysfs sys "$CONTAINERPATH/rootfs/sys/"
mount -o bind /dev "$CONTAINERPATH/rootfs/dev"
mount -o bind /dev "$CONTAINERPATH/rootfs/dev/pts"
chroot "$CONTAINERPATH/rootfs" /bin/bash
echo "Exiting chroot..."
umount "$CONTAINERPATH/rootfs/dev/pts"
umount "$CONTAINERPATH/rootfs/dev"
umount "$CONTAINERPATH/rootfs/sys/"
umount "$CONTAINERPATH/rootfs/proc"
echo "Cleaned up..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment