2 raid software-raid mdadm grub2
我有一个mdadm
管理的 RAID1,上面有一个 EXT4 分区(操作系统文件和 GRUB 文件都在/boot/grub
.
小智 6
最低要求grub.cfg
如下:
set timeout=1
set root='mduuid/ce16c757e4752e4fa9a2fd4935df1aef'
menuentry 'Arch Linux' {
linux /boot/vmlinuz-linux root=UUID=05dddf23-1d9f-417e-b3f8-2281a328dc0b rw
initrd /boot/initramfs-linux.img
}
Run Code Online (Sandbox Code Playgroud)
是的,与由 生成的长垃圾流有很大不同grub-mkconfig
,正如您所见,此设置似乎不需要任何模块。
我的特殊设置是 MBR 格式磁盘上的单个分区,我在该磁盘上组装了一个 RAID1 阵列和该阵列上的 EXT4 分区。
该root
变量设置为RAID 阵列mduuid/xxx
的UUID,您可以通过mdadm --examine /dev/sdX
在作为 RAID 阵列一部分的磁盘或分区上运行来获取该UUID。这不是 RAID 上的 EXT4 文件系统的 UUID,不要使用报告的 UUID,lsblk
因为它只会为您提供无法在那里工作的分区的 UUID。
您还可以将root
变量设置为md/...
创建时指定的 RAID 阵列标签 ( mdadm ... -N "some label" ...
)。有关指定根设备的其他方法,请查看文档。
内核参数行上的 UUID是位于 RAID 阵列顶部的文件系统的 UUID - 这可以通过运行获得lsblk -o NAME,UUID
:
NAME UUID
loop0
??loop0p2 ce16c757-e475-2e4f-a9a2-fd4935df1aef
??md127 05dddf23-1d9f-417e-b3f8-2281a328dc0b
loop1
??loop1p2 ce16c757-e475-2e4f-a9a2-fd4935df1aef
??md127 05dddf23-1d9f-417e-b3f8-2281a328dc0b
Run Code Online (Sandbox Code Playgroud)
它是与mdXXX
设备节点对应的节点 -05dddf23-1d9f-417e-b3f8-2281a328dc0b
就我而言。不要使用底层分区的 UUID -loopXp2
在这个例子中。
作为奖励,这里有一些可怕的shell脚本有点儿工作,如果你想在一个QEMU / KVM虚拟机使用GRUB进行试验。
要创建一些原始磁盘,它们必须是“原始”才能安装在主机上,您不能使用 qcow2 或 vmdk :
qemu-img create -f raw driveX.img XXXG # name and size
Run Code Online (Sandbox Code Playgroud)
要使用两个磁盘、一个 ISO(在本例中是 Archlinux,但它可以是任何东西)和基本网络访问权限来启动 VM:
/path/to/qemu-system-x86_64 -m 512 -cpu host -smp 2,cores=2,sockets=1 -machine q35,accel=kvm -balloon none -device ahci,id=ahci -drive if=none,file=drive1.img,format=raw,cache=none,aio=native,id=hdd1 -device ide-hd,bus=ahci.0,drive=hdd1 -drive if=none,file=drive2.img,format=raw,cache=none,aio=native,id=hdd2 -device ide-hd,bus=ahci.1,drive=hdd2 -drive if=none,file=arch.iso,format=raw,cache=none,aio=native,id=iso,snapshot=on -device ide-cd,bus=ahci.2,drive=iso -device pci-ohci,id=ohci -device usb-kbd,bus=ohci.0 -device usb-mouse,bus=ohci.0 -netdev user,id=net0 -device e1000-82545em,autonegotiation=on,netdev=net0 -realtime mlock=on
Run Code Online (Sandbox Code Playgroud)
在主机上挂载 VM 分区的脚本,请确保在运行之前停止 QEMU 以避免损坏分区:
losetup -P -f drive1.img # create loopback device nodes for the virtual disks
losetup -P -f drive2.img
mdadm --assemble /dev/md/root /dev/loop0p1 /dev/loop1p1 # assemble the RAID
# some distributions will auto-detect and assemble them so it sometimes fails
# running this script a second time usually succeeds in mounting it anyway
# if it failed the first time - I don't have time to fix the real issue
mount "/dev/md/root" rootfs # mount the root FS of the VM in this directory
Run Code Online (Sandbox Code Playgroud)
卸载脚本,在启动 VM 备份之前运行这个(多次只是为了安全):
umount rootfs # umount the FS
mdadm --stop /dev/md127 # sometimes the array appears under these names
mdadm --stop /dev/md126 # so we stop them as well just to be safe
mdadm --stop /dev/md/root # the correct name
losetup -D # detach all loop device nodes
Run Code Online (Sandbox Code Playgroud)