顯示具有 Grub 標籤的文章。 顯示所有文章
顯示具有 Grub 標籤的文章。 顯示所有文章

2022年10月1日 星期六

重新安裝 grub 的程序步驟

  1.  以任一款 Linux OS (與你要修復的 Linux OS 同款最好) 的 Live USB 開機。

  2.  查看硬碟分區狀態:
    $sudo fdisk -l

    Disk /dev/sda: 232.89 GiB, 250059350016 bytes, 488397168 sectors
    Disk model: WDC WD2500AAJS-0
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xd273611e

    Device     Boot  Start           End     Sectors     Size  Id        Type
    /dev/sda1  *       2048     206847     204800  100M   ef    EFI (FAT-12/16/32)
    /dev/sda2       206848 61646847 61440000 29.3G   83   Linux

  3. 全程使用超級使用者身分

    home@mint: ~$ sudo -s (或 sudo -i )
    root@mint: /home@mint# cd (注意粗體部份的變化)

  4. 掛載磁區
    root@mint: /home@mint# mkdir /mnt/boot
    root@mint: /home@mint# mkdir /mnt/boot/efi
    root@mint: /home@mint# mount /dev/sda2 /mnt
    root@mint: /home@mint# mount /dev/sda1 /mnt/boot/efi

  5. 將 /mnt 暫時虛擬為根目錄

    為防止在 chroot 时,出現下面的警告:
    chroot: failed to run command '/bin/bash': No such file or directory
    root@mint: ~# for dir in /root /opt /proc /dev /sys /etc /bin /sbin /var /usr /lib /lib64 /tmp; do  mkdir /mnt$dir && mount  -B $dir /mnt$dir; done

    為防止在 grub-install 时,出現下面的警告:
    Installing for x86_64-efi platform.
    grub-install: warning: EFI variables are not supported on this system.
    root@mint: ~# for dir in /sys/firmware/efi/efivars; do mount  -B $dir /mnt$dir; done

    root@mint: ~# chroot /mnt(
    注意粗體部份的變化)

  6. 刪除既有 grub
    root@mint: ~#  dpkg --configure -a
    root@mint: ~# apt-get install -fy
    root@mint: ~# apt-get purge --allow-remove-essential -y grub-com*
    root@mint: ~# apt-get purge --allow-remove-essential -y grub2-com*
    root@mint: ~# apt-get purge --allow-remove-essential -y shim-signed
    root@mint: ~# apt-get purge --allow-remove-essential -y grub-common:*
    root@mint: ~# apt-get purge --allow-remove-essential -y grub2-common:*

  7. 重新安裝 grub
    root@mint: ~# apt-get install -y grub-efi

  8. UEFI 啟動用(有兩個作法都可採用)
    root@mint: ~# grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/sda

    root@mint: ~# grub-install /dev/sda

    如果出現下面,就一切OK
    Installing for x86_64-efi platform.
    Installation finished. No error reported.

  9. 更新 grub 產生/boot/grub/grub.cfg

    /boot/grub/grub.cfg=/etc/grub.d/01~ + /etc/default/grub + others
    先編寫 /etc/grub.d/40_custom,加入 menuentry
    再修改 /etc/default/grub,加入 GRUB_DISABLE_OS_PROBER=false、變動預設啟動順序及選單是 hidden (不出現) 或 menu (出現)

    root@mint: ~# update-grub


    root@mint: ~# grub-mkconfig -o /boot/grub/grub.cfg

  10. 離開
    Ctrl + D 先跳出 chroot /mnt 環境
    Ctrl + D 再跳出超级使用者環境
    reboot
參考資料:Debian Wiki

2020年5月16日 星期六

Grub Customizer ---- 管理 Grub 開機選單設定的圖形化界面軟體

安裝:

  • sudo add-apt-repository ppa:danielrichter2007/grub-customizer
  • sudo apt-get update
  • sudo apt-get install grub-customizer 

移除:

  • sudo apt-get remove --autoremove grub-customizer

Ubuntu 20.04

已納入軟體庫,不必再加入 PPA。

2020年5月15日 星期五

Grub 2.0 引導多重系統開機

Ubuntu 20.04 LTS

Grub 2.0

Windows 10x64 LTS VHDX

請參閱:實作 Windows 原生開機虛擬硬碟 (Boot to VHD)

insmod part_msdos
insmod ntldr
insmod ntfs
set root='hd0,msdos3'
ntldr /bootmgr
boot

Clonezilla Live

請參閱:將Clonezilla Live放在硬碟中

 set root=(hd0,8)
linux /live-hd/vmlinuz boot=live union=overlay live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" keyboard-layouts="" ocs_live_batch="no" locales="" vga=788 ip=frommedia nosplash live-media-path=/live-hd bootfrom=/dev/sda8 toram=filesystem.squashfs
initrd /live-hd/initrd.img

Rescutux

 請參閱:Rescutux/ isolinux/ live.cfg

set root=(hd0,9)
linux /live/vmlinuz1 boot=live config quiet splash locales=en_US.UTF-8 selinux=1 security=selinux enforcing=0 liveid=/LIVEID/6E1D3930/EB45BF1A/6B6C9A04/A4B9DD8D
initrd /live/initrd1.img

2020年2月19日 星期三

Grub 開機選單的操作

 將 Grub 開機選單安裝在指定設備上

在終端機鍵入
sudo update-grub
sudo grub-install /dev/sdx(sdx 代表 sda, sdb, ......)
完成

更改開機選單預設開機順序

開機選單看起來像這個樣子:

注意順序從0開始,由上往下編號,所以 Windows 7 編號是 4
在終端機鍵入
sudo gedit /etc/default/grub
更改下列這一行程式最後的數字,成為你要的編號
GRUB DEFAULT=0

最後在終端機鍵入
sudo update-grub
完成

不讓電腦上其他作業系統加入開機選單

sudo cp /etc/default/grub /etc/default/grub.bak
sudo sed -i '$a GRUB_DISABLE_OS_PROBER=true' /etc/default/grub
sudo update-grub

開機選單上中文亂碼

編輯 /boot/grub/grub.cfg,尋找 font,將 font 指向檔案 unicode.pf2
 編輯 /etc/default/grub.d/60_mint-theme.cfg,尋找 font,將 font 指向檔案 unicode.pf2

2020年1月31日 星期五

boot-repair grub 修復工具

安裝 boot-repair

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair

 
 

2019年1月10日 星期四

關於 GRUB2

你可以自行增加 GRUB 開機選單條目:

  • 編輯 /etc/grub.d/40_custom 這個 GRUB 的設定檔
  • 以讓硬碟中的 ISO 映像檔開機為例,加入以下程式碼:

    menuentry "Ubuntu 13.04 Live" {
     set root=(hd0,1)
     loopback loop /isoimage/ubuntu-13.04-desktop-i386.iso
     linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/isoimage/ubuntu-13.04-desktop-i386.iso noprompt noeject
     initrd (loop)/casper/initrd.lz
    } 

  • 重新開機

以 grml-rescueboot 套件新增 GRUB 選單條目啟動 ISO 檔

grml-rescueboot 是一個用於輔助 update-grub 的套件,它提供一個 update-grub 專用的指令稿(script),讓所有放在 /boot/grml 目錄下的 Grml ISO 映像檔可以自動被加入開機選單中,它的目的就是可以讓使用者在不需要 CD/DVD 或 USB 隨身碟的情況下,使用這些映像檔開機然後進入 Grml 的救援模式。
  • 安裝 grml-rescueboot:
    $ sudo apt install grml-rescueboot
  • 將要用來開機的映像檔複製到 /boot/grml/ 目錄中
  • 更新 GRUB2 的開機選單:$ sudo update-grub
  • 重新開機