问题描述
Ubuntu 20.04 系统升级到22.04后,第一次重启无法进入桌面,黑屏进入grub命令行模式,显示如下内容
The GNU GRUB version 2.06
Minimal BAsH-like line editing is supported, For the first word, TAB lists possiblecommand completions. Anywhere else TAB lists possible device or file complet ions.
grub>
按照所说的按下Tab
指令后,输出了一系列grub支持的命令
grub>Possible commands are
[ acpi authent icate background color background_image badram boot break cat chainloader clearconfigfile continue cpuid cryptomount cutmem distrust dump echo exit exportextract
_entries _conf igfile extract _entries_source false fwsetup gettext halt help initrd initrdefiinsmod keystatus linux linuxefi list_env list trusted load_eny loadfont loopback is
lsefi isef immarIsefisystab lsfonts lsmod lssal menuentry net_add_addr net_add_dns net _add_route net_bootpnet_bootp6 net_del_addr net _del_dns net _del_route net _dhcp
net_get_dhcp option net _ipv6 autoconfnet_ls addr net_ls_cards net _is_dns net_ls_routes net_nslookup normal normal exit password pbkdf2play probe reboot regexp return rmmod
save_env search search.file search.fs_label search.fs_uuidset setparams shift sleep smbios source submenu terminal_input terminal_output test true trustunset verify detached zfs-bootfs zfsinfo zfskey
grub>
注意:我的电脑在更新后只有Ubuntu22.04一个系统
解决方案:
方式一:配置引导启动文件的位置
主要参考Linux+Grub启动引导修复错误:Gnu Grub Version 2.04 Minimal BASH-like editing is supported…
有的小伙伴可以通过方式一进入系统,但我没有成功
方式二:手动引导
主要参考:linux 开机如何进入grub 命令行模式,并通过grub命令进入系统
我通过方式二成功进入了系统
具体操作过程如下:
1.首先,查询相关信息,查询方法如附录所示(方式一只需要①,方式二需要①~④)
2.方式一:
grub>search -f /efi/ubuntu/grubx64.efi
(hd1,gpt1)
grub>set root=(hd1,gpt1)
后续可以用boot
或者normal
命令
方法1:boot
grub> chainloader (hd1,gpt1)/efi/ubuntu/grubx64.efi
grub> boot
grub>
方法2:normal
grub> set prefix=(hd1,gpt1)/efi/ubuntu
grub> normal
grub>
3.方式二:
指定Linux内核,及/所在分区
grub> linux (hd1,gpt2)/home/vmlinuz-5.15.0-125-generic ro text root=/dev/nvme0n1p1
initrd命令指定initrd文件
grub> (hd1,gpt2)/home/initrd.img-5.15.0-125-generic
boot引导系统
grub> boot
成功进入系统
附录——查询方法:
①找到Ubuntu安装在哪个磁盘分区
如果用search -f /efi/ubuntu/grubx64.efi
命令搜索后出现多个结果,或者搜索不出来时,可以用下述方法
# 输入ls后,列出磁盘分区,我的磁盘分区信息如下:
grub> ls
(hd0),(hd1),(hd0,gpt1),(hd1,gpt1),(hd1,gpt2)
# 查看各分区的性质, 找到Filesystem type是fat的分区
grub> ls (hd0,gpt1)
Partition hd1,gpt1: Filesystem type fat, UUID 7EA8-ATotalsize 524288KiB
# 然后用ls命令在里面找,找到grub.cfg文件,确认Linux安装在这个分区
grub> ls(hd1,gpt1)/efi/ubuntu/
grubx64.efi shimx64.efi mmx64.efi bootx64.csv grub.cfg
注意,找的时候可以细致一点,每个文件夹都ls
看一下
例如,我的查询过程如下
grub> ls(hd1,gpt1)
Partition hd1,gpt1: Filesystem type fat, UUID 7EA8-ATotalsize 524288KiB
grub>ls(hd1,gpt1)/
efi/
grub> ls(hd1,gpt1)/efi/
ubuntu/ boot/
grub> ls(hd1,gpt1)/efi/ubuntu/
grubx64.efi shimx64.efi mmx64.efi bootx64.csv grub.cfg
grub> ls(hd1,gpt1)/efi/boot/
bootx64.efi fbx64.efi mmx64.efi
②用cat
命令找到根分区所在的磁盘位置,(即/
所在的分区)
输入cat(hd1,gpt2)/etc/fstab
,可以看到/was on /dev/nvme0nlp2
这里也说了/boot/efi was on /dev/nvme0nlp1
,这就意味着在我的系统中,/根分区磁盘位置与ubuntu系统的安装磁盘分区位置不同
(由于照片拍的不全,输入内容并不完整)
grub>cat(hd1,gpt2)/etc/fstab
# /etc/fstab:static file system information.
#
# Use 'blkid' to print the universally unique ident ifier
# device; this may be used with UuID= as a more robust way
# that works even if disks are added and removed. See fsta
#
# <file system> <mount point><type><options><dump><pass>
# / was on /dev/nvme0n1p2 during installation
UUID=8af2f7e8-c1ff-402c-82c4-f2800830edbb
/boot/efi was on /dev/nvme0nlp1 during installation
UUID=7EA8-AF12 /boot/efi vfat umask=0077
/swapf ilenone
/dev/disk/by-uuid/91b4721e-2245-4799-a473-2ff794a00e67 /mnto nosuid,nodev,nofail,x-gvfs-show 0 0
grub>
其实,我在前面查看分区内容时就发现了,我的磁盘分区(hd1,gpt1)
内并没有etc这个文件夹
③找到Linux内核所在的目录
参考的文章里面,都提示了内核在/boot/vmlinuz-xxx-xxx
,但我的不在,用笨办法挨个盘ls找到的,我的在(hd1,gpt2)/home/vmlinuz-xxx-xxx
④找到内核版本对应的initrd.img-xxx-xxx
,一般与内核在同一个目录下