Grub
將 chroot 自動化到損壞的系統中
每次您必須使用 live-boot-CD 掛載系統並
chroot
進入系統來修復 grub 時,您必須鍵入這麼多行才能掛載到正確的分區:fdisk -l
例如,找到正確的分區
/dev/sda1
mount /dev/sda1 /mnt/ mount -t proc none /mnt/proc mount -o bind /dev /mnt/dev mount -t sysfs sys /mnt/sys chroot /mnt/
有沒有辦法用一個腳本來優化它?
將此腳本複製
mount-root
到您的 USB 設備上#!/bin/bash if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then echo "You must be root to run this script!"; echo "use 'sudo !!'"; exit 1 fi if [ $# -ne 2 ]; then echo "calling this script with only two options with the device and mountpoint" echo "for example" echo "mount-root /dev/sda1 /media/other/" set -x fdisk -l lsblk -f exit fi D=$(echo $1 | sed 's:/$::') M=$(echo $2 | sed 's:/$::') echo mounting $D to $M mkdir -p $M mount $D $M mount -t proc none $M/proc mount -o bind /dev $M/dev mount -t sysfs sys $M/sys mount --bind /dev/pts $M/dev/pts cp /proc/mounts $M/etc/mtab chroot $M/ /bin/bash