Created
November 15, 2022 14:39
-
-
Save marcs-feh/4db04092bb1d951effd7695466206d46 to your computer and use it in GitHub Desktop.
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 | |
# 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