Initial commit
This commit is contained in:
44
scripts/chroot-rescue
Executable file
44
scripts/chroot-rescue
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
# Mount and chroot a linux system
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
lsblk
|
||||
|
||||
# Set defaults
|
||||
RP="${ROOT_PART:-/dev/nvme0n0p3}"
|
||||
BP="${BOOT_PART:-/dev/nvme0n0p1}"
|
||||
|
||||
read -r -p "Root partition [$RP]: " input_rp
|
||||
RP="${input_rp:-$RP}"
|
||||
read -r -p "Boot partition [$BP]: " input_bp
|
||||
BP="${input_bp:-$BP}"
|
||||
MD="${MOUNT_DIR:-/mnt/${RP##*/}}"
|
||||
[[ -d "$MD" ]] && MD="$MD-$RANDOM"
|
||||
read -r -p "Mount directory [$MD]: " input_md
|
||||
MD="${input_md:-$MD}"
|
||||
|
||||
if [[ ! -e "$RP" || ! -e "$BP" ]]; then
|
||||
echo "[ERROR] Root or boot partition does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Mount and enter the chroot
|
||||
echo "[INFO] Mounting and entering chroot..."
|
||||
sudo mkdir -p "$MD"
|
||||
sudo mount "$RP" "$MD"
|
||||
for i in proc sys dev; do
|
||||
sudo mount --bind "/$i" "$MD/$i"
|
||||
done
|
||||
sudo mount "$BP" "$MD/boot/efi"
|
||||
sudo chroot "$MD"
|
||||
|
||||
# After chroot
|
||||
echo "[INFO] Exiting and unmounting chroot..."
|
||||
sudo umount "$MD/boot/efi"
|
||||
for i in proc sys dev; do
|
||||
sudo umount "$MD/$i"
|
||||
done
|
||||
sudo umount "$MD"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user