Showing posts with label grub. Show all posts
Showing posts with label grub. Show all posts

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

2015-12-12

How to reinstall GRUB2 EFI?

Reference 1 : How to reinstall GRUB2 EFI?
Reference 2 : Grub EFI Reinstall
Reference 3 : Linux UEFI 開機

Q : After successfully updating my bios, something went wrong and I ended up with a blinking cursor on the top left corner of a black screen. No errors, no nothing. The bios now only listed a SATA: <disc name> boot option in place of the usual UEFI ubuntu one. I'm using a GPT partitioning scheme.
I eventually found that the working solution was to properly reinstall grub-efi-amd64. So, how do I do this ?

PS: Actually, i succeeded to reinstall GRUB2 EFI on my own and will post my answer here as I was unable to find any complete how-to on this.

A : Boot your computer with a live-usb/CD in UEFI mode. I had two boot options <flash_drive> and UEFI: <flash_drive>, the second is needed to expose the efi variables in /sys/firmware/efi/ so that efibootmgr don't fail later on. Booting with the first option gives me the following error:
Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables.
Try 'modprobe efivars' as root.
modprobe efivars did'nt work for me.

chroot into the broken system (similar to the ubuntu grub2 help but with efi specificities):
sudo mount /dev/sda2 /mnt #sda2 is my root partition
sudo mount /dev/sda1 /mnt/boot/efi #sda1 is my efi partition
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc/ #makes the network available after chrooting
modprobe efivars # make sure this is loaded
sudo chroot /mnt

Depending on your linux distribution, you now do different things.
For Ubuntu/Debian:
apt-get install --reinstall grub-efi-amd64
or alternatively:
apt-get install --reinstall grub-efi
update-grub
should the above give you a grub, but not a bootable one (…???…)

For Fedora (up to 16, may work for others):
yum reinstall grub-efi

In the following command, you have to replace sdX with the device which has the EFI partition you want to boot from. In --part Y you have to replace the Y with the number of the EFI partition (as in /dev/sdXY).
efibootmgr -c --disk /dev/sdX --part Y
efibootmgr -v # verify a new record called Linux is there
Now type Ctrl+D to exit chroot, unmount everything and reboot:
for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
sudo umount /mnt/boot/efi #please do this. corrupted efi partitions are not nice
sudo umount /mnt
sudo reboot

2014-03-28

嘗試構建自己的busybox

來源 : http://www.360doc.com/content/13/0829/19/7377734_310794205.shtml

1、一個作為宿主機的Linux;本文使用的是Redhat Enterprise Linux 5.4;
2、在宿主機上提供一塊額外的硬盤作為新系統的存儲盤,為了降低複雜度,這裡添加使用一塊IDE接口的新硬盤;
3、Linux內核源碼,busybox源碼;本文使用的是目前最新版的linux-2.6.34.1和busybox-1.16.1。

說明:本文是一個step by step的實做指南;