51 lines
1.2 KiB
Bash
Executable file
51 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# # Exit if location not specified
|
|
# if [ -z "$1" ]; then
|
|
# echo "chroot folder not specified"
|
|
# exit 1
|
|
# elif [ "$1" = -h ]; then
|
|
# echo "./chroot.sh <chroot-folder>"
|
|
# exit 1
|
|
# fi
|
|
|
|
location=${1:-$(dirname "$(realpath "$0")")/chrooted-slackware/}
|
|
echo "$location"
|
|
cd "$location"
|
|
|
|
# Mounting, basic
|
|
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do
|
|
sudo mount -B $i "$location"$i || exit 1
|
|
done
|
|
|
|
for i in /home/installs; do
|
|
sudo mount -B $i "$location"$i || exit 1
|
|
done
|
|
|
|
mkdir -p "$location"/var/lib/sbopkg/
|
|
rsync -Ha --delete --info=progress2 /var/lib/sbopkg/ "$location"/var/lib/sbopkg/
|
|
|
|
# For internet access
|
|
sudo cp /etc/resolv.conf "$location"/etc/resolv.conf
|
|
|
|
# Finally, chroot
|
|
# Need to ensure correct variables
|
|
# http://www.iitk.ac.in/LDP/LDP/lfs/5.0/html/chapter06/chroot.html
|
|
sudo chroot "$location" \
|
|
/usr/bin/env -i \
|
|
HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
|
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
|
|
/bin/bash --login
|
|
|
|
# Unmounting after exit from chroot
|
|
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do
|
|
sudo umount "$location"$i || exit 1
|
|
done
|
|
|
|
for i in /home/installs; do
|
|
sudo umount "$location"$i || exit 1
|
|
done
|
|
|
|
echo "Done"
|