Debian 11克隆镜像部署后Grub配置更新失败的自动化解决方案求助
Debian 11克隆镜像部署后Grub配置更新失败的自动化解决方案求助
各位大佬好,我现在碰到个棘手的问题:用Ansible给一批Debian 11服务器执行更新脚本时,触发了Grub配置错误,具体报错内容如下:
Generating grub configuration file ...", "Found linux image: /boot/vmlinuz-5.10.0-26-amd64", "Found initrd image: /boot/initrd.img-5.10.0-26-amd64", "Found linux image: /boot/vmlinuz-5.10.0-19-amd64", "Found initrd image: /boot/initrd.img-5.10.0-19-amd64", "Warning: os-prober will be executed to detect other bootable partitions.", "Its output will be used to detect bootable binaries on them and create new boot entries.", "done", "Setting up grub-pc (2.06-3~deb11u6) ...", "/dev/disk/by-id/ata-CFS3F-MT_32GB_2122072004900007 does not exist
原因我大概摸清楚了:这些服务器都是通过克隆另一台机器的镜像部署的,所以磁盘的ID和原机器完全不一样。我查了当前服务器的磁盘by-id列表:
sysoperator@server1:~$ ls -l /dev/disk/by-id/ total 0 lrwxrwxrwx 1 root root 9 Jan 3 15:09 ata-CFS3F-MT_32GB_2122072004900022 -> ../../sdb lrwxrwxrwx 1 root root 10 Jan 3 15:09 ata-CFS3F-MT_32GB_2122072004900022-part1 -> ../../sdb1 lrwxrwxrwx 1 root root 9 Jan 3 15:09 ata-Maximus-128GB_20220615100000000127 -> ../../sda lrwxrwxrwx 1 root root 10 Jan 3 15:09 ata-Maximus-128GB_20220615100000000127-part1 -> ../../sda1 lrwxrwxrwx 1 root root 9 Jan 3 15:09 wwn-0x5000000000000006 -> ../../sda lrwxrwxrwx 1 root root 10 Jan 3 15:09 wwn-0x5000000000000006-part1 -> ../../sda1
问题的核心就是:Grub还在尝试调用旧的磁盘ID /dev/disk/by-id/ata-CFS3F-MT_32GB_2122072004900007,但实际应该用当前服务器的 /dev/disk/by-id/ata-CFS3F-MT_32GB_2122072004900022。
我翻了不少文档,都没找到能批量替换这个ID并自动更新Grub的方法,想请教下大家有没有自动化的解决方案?
补充说明:
- 我知道手动可以通过运行
dpkg --configure grub-pc,然后在弹出的对话框里选择正确的磁盘来解决,但我有几百台服务器,手动操作根本不现实... - 另外,服务器本身是能正常启动的,因为启动逻辑用的是UUID:
启动分区是sdb1,对应的UUID是NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sda └─sda1 ext4 1.0 6d68a3a0-c63e-4465-b170-4e0b109d973a 101.9G 2% /home sdb └─sdb1 ext4 1.0 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 20.3G 25% /9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298,而且我查了/boot/grub/grub.cfg里也是正确引用这个UUID的:sysoperator@server1:~$ cat /boot/grub/grub.cfg | grep "root 9" search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298 search --no-floppy --fs-uuid --set=root 9ad5ffb5-1a87-49aa-b90b-ffe5ab77d298
谢谢各位!
备注:内容来源于stack exchange,提问作者user1051676
相关产品推荐
相关产品推荐

