2016-12-16

How do I run update-grub2 from a LiveCD?

Boot with your Live CD (ex. partedmagic...).
Once it boots, open a terminal and mount your Debian partition on /mnt. I'm assuming the Debian partition is /dev/sda5, but you should determine this yourself (fdisk -l). Let me know if you need help to do this:
sudo mount /dev/sda5 /mnt
Then mount a few more directories that are needed:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
Also, if you have a separate Debian boot partition (pretty uncommon these days, but it may be the case):
sudo mount /dev/sdaX /mnt/boot
How can you tell if you have a boot partition?
Once you have your Debian partition mounted, open /mnt/etc/fstab. If you see an entry for /boot, note which device it is pointing to (/dev/sda4 maybe?). This is the one you have to mount.
Once these are mounted, do chroot to start using the mounted directory as the root partition:
sudo chroot /mnt
You'll get a #/ prompt. First thing to do is confirm that you're using the correct /boot directory. Go to /boot/grub and look at the files there. There should be a bunch of .mod files and a grub.cfg file. If the directory is empty, don't continue, because it means this is NOT your actual boot directory. Look above to see how to determine if you need to mount an additional boot directory.
Once you've confirmed that /boot/ contains the correct files, meaning that it is the correct location, type:
sudo update-grub2
This should rebuild your /boot/grub/grub.cfg file with the menu entries.
Then exit the chroot:
exit
At this point you may want to check that things were correctly updated. For this, cd /mnt/boot/grub and check that grub's files are there, there should be a bunch of .mod files and grub.cfg, the latter should have entries for your Debian kernels. If you only see grub.cfg and no .mod files, it means that this is NOT the correct boot directory, look above for how to mount a separate boot partition.
Unmount the filesystems:
sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/boot #Only if you mounted it earlier
sudo umount /mnt/
And then reboot, hopefully your Grub menu will be restored.

讀不到GRUB

開機時,BIOS 有偵測到硬碟,但是 GRUB 無法執行,所以判定是 GRUB 有問題。

解決方法

  • 用 Live usb 開機
  • Clonezilla UEFI 開機

用 Live Debian 開機,修改GRUB

做好 Live Debian USB 後,先在 BIOS 設定 UEFI 開機,再插入 USB。
進入到 Debian後,開啟 terminal, 查看硬碟的內容,將 /dev/sda2(根目錄分割區) 掛載到 /mnt, 再將 /dev/sda1(EFI 分割區) 掛載到 /mnt/boot/efi。

# fdisk -l   // 看分割區內容
# mount /dev/sda2 /mnt
# for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
# mount /dev/sda1 /mnt/boot/efi
# chroot /mnt
# grub-install /dev/sda

// 如果遇到 efi variable....
// 退出 chroot
# modprobe efivarfs  // 載入 efi 模組
# for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
# chroot /mnt
# grub-install /dev/sda
//安裝成功後
# update-grub
# reboot

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.