▶ 原先為 win10 + Ubuntu 雙系統,使用 grub2 作引導,在重裝了 win10 (升到了1803)后系統重寫了引導,啟動項里找不到 Ubuntu,需要修復。
● 參考【https://blog.csdn.net/piaocoder/article/details/50589667】
● 裝一個 Ubuntu 的安裝 U 盤,從U盤啟動,Try Ubuntu without installing,進入以后設法聯網
● 安裝 boot-repair
$sudo su ——輸入密碼 #add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update ——各種確定 #apt-get install -y boot-repair && boot-repair ——各種確定
● 看到窗口如下,點擊 Recommended repair,或者在終端中輸入 #recommended repair 開始修復。中間根據軟件提示,可能需要在終端輸入命令,刪除和重裝某些軟件。

● 修復完成,重啟以后就能以 grub2 的界面選擇啟動項目了。
▶ 時間同步,大意是 windows 將 bios 時間看做當地(Local)時間,而 Linux 將起看做 UTC 時間(然后再加地區偏移),在參考答案中有在 windows 中修正的,也有在 Ubuntu 中修正的,我使用了后一種。
● 參考【https://www.zhihu.com/question/46525639?sort=created】(多個方法),【https://zhuanlan.zhihu.com/p/24762788】(總結了 Ubuntu16 以前改 rcS 的方法和 Ubuntu16 以后的如下方法)
$sudo su ——輸入密碼 #apt-get install ntpdate #ntpdate time.windows.com #hwclock --localtime --systohc
▶ 引導項調整(順序,默認項,等待時間)
● 參考【https://blog.csdn.net/lu_embedded/article/details/44353499】(詳細的 grub 參數含義),【https://www.ssdax.com/2347.html】(正兒八經的修改參考)
● 文件 boot/grub/grub.cfg 是由文件 文件 /etc/default/grub 和 目錄下 /etc/grub.d/ 的文件自動生成的,一旦 update-grub 就會刷新,改了沒用
● 主要涉及調整文件 /etc/default/grub 和文件 /etc/grub.d/25_custom
● /etc/default/grub 的主要部分改成了:
GRUB_DEFAULT=2 # 默認啟動項編號,從 0 開始,我的第 2 項是 windows #GRUB_HIDDEN_TIMEOUT=1 # 單系統時隱藏倒計時,注釋掉的話就不使用 GRUB_HIDDEN_TIMEOUT_QUIET=true # 仍倒計時但不顯示? GRUB_TIMEOUT=0 # 倒計時,小於零則無限等待,等於零則會被強改回等待10秒,在 /boot/grub/grub.cfg 中有一句 if [ "${timeout}" = 0 ]; then set timeout=10 fi GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX="acpi_backlight=vendor"
● /etc/grub.d/25_custom 中把各個啟動模塊全部注釋掉(最重要的 Ubuntu,Ubuntu Advanced 和 Windows Boot Manager 都不是在這里定義的)
#!/bin/sh exec tail -n +3 $0 #menuentry "Windows UEFI bootmgfw.efi" { #search --fs-uuid --no-floppy --set=root 36E1-3F21 #chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi #} #menuentry "Windows Boot UEFI loader" { #search --fs-uuid --no-floppy --set=root 36E1-3F21 #chainloader (${root})/EFI/Boot/bkpbootx64.efi #} #menuentry "EFI/ubuntu/MokManager.efi" { #search --fs-uuid --no-floppy --set=root 36E1-3F21 #chainloader (${root})/EFI/ubuntu/MokManager.efi #} #menuentry "efi/EFI/Boot/bkpbootx64.efi" { #search --fs-uuid --no-floppy --set=root ae416b9e-c4d4-4094-82ee-673b949938db #chainloader (${root})/efi/EFI/Boot/bkpbootx64.efi #} #menuentry "efi/EFI/ubuntu/MokManager.efi" { #search --fs-uuid --no-floppy --set=root ae416b9e-c4d4-4094-82ee-673b949938db #chainloader (${root})/efi/EFI/ubuntu/MokManager.efi #}
● 之后記得在終端里 update-grub。update-grub2命令實際上是指向 update-grub 的,所以輸入兩者等效。
---2020年3月3日---
● NV 顯卡驅動對 Linux 內核版本有上下限制,過高或過低都不能安裝和運行,參考【https://wangcong.net/article/LinuxNvidiaCUDATensorFlowVersion.html】
在某次更新后我的內核變成了 5.3.0(uname -r 獲取信息),nvidia-smi 都沒了,安裝顯卡驅動或 CUDA 時報錯 “The driver installation is unable to locate the kernel source”
查到 CUDA10.0 要求的 Ubuntu 內核版本是 5.0.0,去看 /usr/src 目錄,發現既有原來的 5.0.0-40 內核又有新的 5.3.0內核。重啟時進入 Adanvce mode,選擇原來的低版本內核進入系統,就能正常安裝和運行了。
安裝和刪除內核的辦法: sudo apt-get --purge remove linux-headers-5.3.0* , sudo apt-get install linux-headers-5.0.0-37 linux-headers-5.0.0-37-generic
Grub 默認使用最高版本的內核來啟動系統,換成低版本內核后要刪除殘留的高版本。
