Skip to content

Instantly share code, notes, and snippets.

@marcs-feh
Created November 15, 2022 14:39
Show Gist options
  • Save marcs-feh/4db04092bb1d951effd7695466206d46 to your computer and use it in GitHub Desktop.
Save marcs-feh/4db04092bb1d951effd7695466206d46 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Taken mostly from Gentoo's handbok
newRoot="$1"
printf "chroot into '$newRoot'?(y/N) "
read confirm
[ "$confirm" = "y" ] && {
# Mount required filesystems
mkdir -p "$newRoot"
mount --types proc /proc "$newRoot/proc"
mount --rbind /sys "$newRoot/sys"
mount --make-rslave "$newRoot/sys"
mount --rbind /dev "$newRoot/dev"
mount --make-rslave "$newRoot/dev"
mount --bind /run "$newRoot/run"
mount --make-slave "$newRoot/run "
# Check if /dev/shm isn't just a link
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm /run/shm
# Chroot
chroot "$newRoot" /bin/bash
source /etc/profile
export PS1="(*) ${PS1}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment