Skip to content

Instantly share code, notes, and snippets.

@Ozymandias42
Last active May 11, 2023 05:04
Show Gist options
  • Save Ozymandias42/6b6c9484001e36e8ebff2d505da04438 to your computer and use it in GitHub Desktop.
Save Ozymandias42/6b6c9484001e36e8ebff2d505da04438 to your computer and use it in GitHub Desktop.
Chroot script for use with locked down Linux based NAS OSes
#!/bin/sh
basepath=$(dirname "${0}")
if [ "${basepath}" = "." ]
then
alpine="${PWD}/alpine"
else
alpine="${basepath}/alpine"
fi
#Folder to check for
folders="proc sys dev "
for i in ${folders}
do
mkdir -p "${alpine}"/"${i}"
done
mount -t proc none "${alpine}/proc"
mount -t sysfs /sys "${alpine}/sys" -o ro
mount --bind /dev "${alpine}/dev"
mount --bind /dev/sda "${alpine}/dev/sda"
mount --bind /dev/sdb "${alpine}/dev/sdb"
if [ -f /etc/resolv.conf ] ; then cp /etc/resolv.conf "${alpine}/etc/resolv.conf" ; fi
chroot "${alpine}" ${1}
umount -R "${alpine}/proc"
umount -R "${alpine}/sys"
umount -R "${alpine}/dev"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment