You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

扩展Ubuntu 22.04根逻辑卷后特定硬件机型进入initramfs shell问题求助

扩展Ubuntu 22.04根逻辑卷后特定硬件机型进入initramfs shell问题求助

我用Packer的QEMU builder制作了Ubuntu 22.04.02的镜像,之后把这个raw镜像用dd写到裸机迷你PC上。第一次启动的时候,我会自动执行一个扩展根分区的脚本,让它占满磁盘剩余空间。

这个流程我在6-7种不同硬件配置上都试过,重启后完全没问题,但最近在某一特定型号的迷你PC上,有两台机器在执行完扩展步骤重启后直接掉进了initramfs shell,卡在这里动不了,我实在搞不懂哪里出问题了,来求助大家!

扩展前的磁盘分区状态

执行fdisk -l的输出:

GPT PMBR size mismatch (16777215 != 250069679) will be corrected by write.
The backup GPT table is not on the end of the device.

Disk /dev/nvme0n1: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: Vaseky V900/128GB
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: gpt
Disk identifier: F13F5D26-3087-4728-9C50-8D062F54B00B

Device           Start      End  Sectors  Size Type
/dev/nvme0n1p1    2048  1103871  1101824  538M EFI System
/dev/nvme0n1p2 1103872  4773887  3670016  1.8G Linux filesystem
/dev/nvme0n1p3 4773888 16775167 12001280  5.7G Linux filesystem

扩展后的磁盘分区状态

执行完lvextend后的fdisk -l输出:

Disk /dev/nvme0n1: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: Vaseky V900/128GB
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: gpt
Disk identifier: F13F5D26-3087-4728-9C50-8D062F54B00B

Device           Start       End   Sectors  Size Type
/dev/nvme0n1p1    2048   1103871   1101824  538M EFI System
/dev/nvme0n1p2 1103872   4773887   3670016  1.8G Linux filesystem
/dev/nvme0n1p3 4773888 250069646 245295759  117G Linux filesystem

扩展完成后用df验证,看起来是正常的:

# df -h /
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv  116G  5.3G  106G   5% /

我使用的扩展脚本

这是每次启动后自动执行的扩展逻辑:

lvpath=$(lvdisplay --noheadings -C  -o "lv_path" | sed 's/^ *//g')

growpart -v -u auto /dev/nvme0n1 3
pvresize /dev/nvme0n1p3
lvextend -l +100%FREE $lvpath
resize2fs $lvpath

问题现象

在那两台特定机型上,重启后直接进入initramfs shell,报错信息如下:

Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... [    7.265019] Btrfs loaded, crc32c=crc32c-intel, zoned=yes, fsverity=yes
Scanning for Btrfs filesystems
done.
Begin: Waiting for root file system ... Begin: Running /scripts/local-block ... mdadm: No arrays found in config file or automatically
done.
mdadm: No arrays found in config file or automatically
mdadm: No arrays found in config file or automatically
...(重复多次mdadm无阵列的日志)
mdadm: error opening /dev/md?*: No such file or directory
mdadm: No arrays found in config file or automatically
...
done.

Gave up waiting for root file system device.  Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Missing modules (cat /proc/modules; ls /dev)

ALERT!  /dev/mapper/ubuntu--vg-ubuntu--lv does not exist.  Dropping to a shell!

BusyBox v1.30.1 (Ubuntu 1:1.30.1-7ubuntu3) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)

尝试过的其他方法

我试过不扩展现有分区,而是新增一个分区,创建PV并加入到现有VG中,结果还是一样的,重启后依然掉进initramfs。新增分区后的磁盘状态:

# fdisk -l
Disk /dev/nvme0n1: 119.24 GiB, 128035676160 bytes, 250069680 sectors
Disk model: Vaseky V900/128GB
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: gpt
Disk identifier: F13F5D26-3087-4728-9C50-8D062F54B00B

Device            Start       End   Sectors   Size Type
/dev/nvme0n1p1     2048   1103871   1101824   538M EFI System
/dev/nvme0n1p2  1103872   4773887   3670016   1.8G Linux filesystem
/dev/nvme0n1p3  4773888  16775167  12001280   5.7G Linux filesystem
/dev/nvme0n1p4 16775168 250069646 233294479 111.2G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 116.96 GiB, 125585850368 bytes, 245284864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

临时解决方法(Workaround)

我偶然发现了一个临时解决办法:如果不用+100%FREE,而是用+99%FREE多次执行扩展命令,直到提示逻辑卷大小不再变化,之后重启就不会掉进initramfs了。比如执行:

# lvextend -rl +99%FREE $lvpath
Size of logical volume ubuntu-vg/ubuntu-lv unchanged from 116.96 GiB (29943 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.46.5 (30-Dec-2021)
The filesystem is already 30661632 (4k) blocks long.  Nothing to do!

我怀疑是不是+100%FREE在计算空闲空间的时候出了什么问题?

另外附上我用的Packer配置,供大家参考:

variable "version" {}

source "qemu" "ubuntu" {
boot_command = [
"<esc><esc><esc><esc>e<wait>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del><del>",
"linux /casper/vmlinuz --- autoinstall ds=\"nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\"<enter><wait>",
"initrd /casper/initrd<enter><wait>",
"boot<enter>",
"<enter><f10><wait>"
]
boot_wait        = "3s"
accelerator      = "kvm"
cpus             = "4"
disk_image       = false
disk_size        = "16G"
memory           = 8192
disk_interface   = "virtio"
format           = "raw"
headless         = "true"
http_directory   = "http"
iso_url          = "/images/ubuntu-22.04.2-live-server-amd64.iso"
iso_checksum     = "sha256:5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931"
net_device       = "e1000"
output_directory = "artifacts"
vm_name          = "ubuntu-22-base-image-efi.raw"
qemu_binary      = "kvm"
shutdown_command = "shutdown -h now"
ssh_password     = "..."
ssh_username     = "root"
ssh_wait_timeout = "60m"
vnc_bind_address = "0.0.0.0"
vnc_port_min     = 5960
vnc_port_max     = 5960
machine_type     = "q35"
qemuargs         = [
[ "-cdrom", "/images/ubuntu-22.04.2-live-server-amd64.iso"],
[ "-vga",    "virtio" ],
[ "-serial", "mon:stdio"],
[ "-device", "virtio-scsi-pci" ],
[ "-device", "scsi-hd,drive=drive0,bootindex=0" ],
[ "-device", "scsi-cd,drive=cdrom0,bootindex=1" ],
[ "-drive",  "if=none,file=artifacts/ubuntu-22-base-image-efi.raw,id=drive0,cache=writeback,discard=ignore,format=raw" ],
[ "-drive",  "if=none,file=/images/ubuntu-22.04.2-live-server-amd64.iso,id=cdrom0,media=cdrom" ],
[ "-drive",  "if=pflash,format=raw,readonly=on,file=/usr/share/ovmf/OVMF.fd" ],
]
}

build {
sources = ["source.qemu.ubuntu"]

provisioner "file" {
source          = "./files/"
destination     = "/"
}

provisioner "shell" {
inline = [
"/var/lib/installer/setup.sh"
]
}
}

有没有大佬遇到过类似的问题?或者能帮我分析下到底哪里出问题了?


备注:内容来源于stack exchange,提问作者Jason Separovic

火山引擎 最新活动