GPT模式下,通过grub2直接引导CentOS的ISO
关键字: Centos 7, isoscan/filename, nvme, ntfs, grub2, dracut,ntfs-3g 为啥CentOS不支持ISO引导? 作为各种私有云和容器使用最多的系统,CentOS可以很容易的安装在各种服务器及虚拟环境中,但是这都是通过光盘或者USB进行安装,且启动方式均为MBR模式。那么又没有一种不安装,也不使用U盘或CDROM, 直接加载硬盘里的CentOS的ISO镜像,进行LiveCD系统呢? 在经历d多次失败的尝试,在笔记本直接引导ISO的方式肯定是行不通的,即使是最新的CentOS-7-x86_64-LiveKDE-1810.iso也不可能成功,遇到的最主要的问题有以下俩点 a,initramfs中并没有包含nvme的驱动,识别固态硬盘上就存在困难。 b, 缺乏读写ntfs的驱动,将文件保存在ntfs分区肯定没戏,只能通过FAT32/ext2/3/4等分区进行。 特别说明:并不是CentOS本身不支持nvme,而是加载CentOS根分区文件的initram.img缺少nvme的驱动,直接决定了无法加载固态硬盘,无法加载ntfs系统,自然也就无法启动iso,进行后续操作了。 至于解决方法呢,很简单,缺啥补啥,将nvme和ntfs的驱动打进initramfs里。 插播:initrd/initramfs除了手工打包外,还有一些现成的工具可以使用的,如dracut, 如linux-livekit等。CentOS就是通过dracut进行initramfs系统的动态加载。 方向既然明确,后续就对initramfs进行重建,以实现GPT模式下加载引导CentOS ISO的目的。 作为一名历经磨练的工程师,还要啥自行车啊。手工对initramfs进行解包和打包,肯定是第一选择了。 首先,准备CentOS环境,如LiveCD的U盘,或安装在U盘的CentOS系统,之后就可以在CentOS里进行各种折腾了。 1, 解包 CentOS的initramfs与大家理解的还是有点区别的,用7zip或标准的cpio,解开的只有一段Early_CPIO的硬编码,其他与系统相关的重要的文件都无法解开。这明显是不对的,无奈之下,只有去读dracut的代码,之后才找出问题之所在。 首先,initramfs里因附带了early-microcode,直接决定了它只能通过dracut附带的skipcpio解包,当然了,这个功能可以通过开关进行关闭。 正确的解包命令如下: 解包: /usr/lib/dracut/skipcpio ../initramfs-3.10.0-229.el7.x86_64.img | zcat/xcat/cat | cpio -imdv 打包: find . -print0 | cpio --null -R 0:0 -H newc -o --quiet | gzip -9 > /boot/init-new.img 2, 安装nvme驱动 自行车都不要了,安装nvme驱动时,修改配置,全套只能手动了。nvme的驱动文件只有俩个, nvme-core.ko.xz 和 nvme.ko.xz。但这样打包出来的img无一成功。在对各种附带nvme的镜像进行解包和比对,确认驱动安装时,除文件复制外,还会诸多文件会被修改: modules.dep modules.dep.bin modules.alias.bin modules.alias modules.symbols modules.symbols.bin 文件中。 可是手工更新二进制文件,这个挑战也有点太大了,至少个人不具备这个技能。 各种手册和说明,建议的驱动安装方式如下: depmod -a ${kernel_version} -b ${initrdcpio_dir} depmod -m <文件> -b ${initrdcpio_dir} depmod 命令会分析模块相依关系,将模块信息写入对应文件。哎,绕了一大圈。 启动带有nvme的initram系统,如可看到以下信息,说明nvme驱动已正确安装 [liveuser@localhost ~]$ dmesg | grep MSI [ 1.161006] pcieport 0000:00:1c.0: irq 122 for MSI/MSI-X [ 1.161197] pcieport 0000:00:1c.3: irq 123 for MSI/MSI-X [ 1.161410] pcieport 0000:00:1c.4: irq 124 for MSI/MSI-X [ 1.161591] pcieport 0000:00:1d.0: irq 125 for MSI/MSI-X [ 1.171944] xhci_hcd 0000:00:14.0: irq 126 for MSI/MSI-X [ 1.981247] ahci 0000:00:17.0: irq 127 for MSI/MSI-X [ 2.217622] r8169 0000:02:00.0: irq 128 for MSI/MSI-X [ 2.488274] i915 0000:00:02.0: irq 129 for MSI/MSI-X [ 9.130166] rtsx_pci 0000:01:00.0: irq 283 for MSI/MSI-X [ 9.212932] nvme 0000:04:00.0: irq 284 for MSI/MSI-X [ 9.414793] nvme 0000:04:00.0: irq 284 for MSI/MSI-X [ 9.414802] nvme 0000:04:00.0: irq 285 for MSI/MSI-X [ 9.414810] nvme 0000:04:00.0: irq 286 for MSI/MSI-X [ 9.414816] nvme 0000:04:00.0: irq 287 for MSI/MSI-X [ 9.414826] nvme 0000:04:00.0: irq 288 for MSI/MSI-X [ 9.711302] snd_hda_intel 0000:00:1f.3: irq 289 for MSI/MSI-X [ 9.741093] ath10k_pci 0000:03:00.0: irq 290 for MSI/MSI-X [root@localhost boot]# lsmod | grep mmc mmc_block 41535 2 rtsx_pci_sdmmc 23620 0 mmc_core 147317 2 mmc_block,rtsx_pci_sdmmc rtsx_pci 66565 2 rtsx_pci_ms,rtsx_pci_sdmmc
[root@localhost boot]# lsmod | grep nvme nvme 32338 3 nvme_core 58852 5 nvme
3, 安装ntfs-3g 在centos,即便是Live系统,也是可以通过yum进行安装的 yum install -y epel-release* yum install -y ntfs-3g 安装在操作系统是容易的,但如何安装在{initramfs_dir},并没有找出来办法。 况且,ntfs-3g还需要以下程序包的依赖: fusermount ulockmgr_server mount.fuse ntfs-3g 实际上,手动模式到这里,因为k需要客服的困难太多,基本可以放弃了。 采用Dracut进行initramfs的更新 无奈之下, 只有掉头,重新研究dracut,通过它进行initramfs的修改和更新。 在dracut的官方文档里,提供了非常复杂的conf文件,这些东西对仅仅需要更新ramfs的来说,并不是必要的。既然不需要conf文件,在命令下一切就变得易如反掌了。 通过dracut进行驱动安装就很简单, --add-drivers nvme,一条命令就可以搞定。 添加ntfs-3g也并没有想象的复杂,使用 -add dmsquash-live dmsquash-live-ntfs完成。 很多人都会在这里犯错,相信大家在看到以下错误时,也不会过于惊讶: dracut module 'dmsquash-live' cannot be found or installed. 这是因为dmsquash模块只在non-hostonly模块下有效,添加-N参数即可。 -H, --hostonly Host-Only mode: Install only what is needed for booting the local host instead of a generic host. -N, --no-hostonly Disables Host-Only mode 在hostonly模式下,只会安装本机需要的驱动,这样做出来的ramfs会非常小,比通用模块小一半还多。但是因为缺乏通用设备驱动,它也只能在本机运行,无法复制到其他系统运行。默认模式就是Hostonly。 4, ntfs分区的加载 在dracut-033版本,已经支持ntfs分区的识别,但如果想挂载ntfs分区,还需要对dracut脚本进行更新。在有同样问题的Fedora,有热心观众写了ntfsloop模块,进行ntfs分区挂载。这个模块在centos下也时可以用的,只是它总会把ntfs分区挂载在以下路径: /run/initramfs/ntfsloop/${NTFS-UUID}/ntfs 而这与centos要求的路径/run/initramfs/isoscan不符。即使分区挂载成功,也无法运行后续脚本。 当然了,对ntfsloop进行修改,也时可以用的。但本着最小修改的原则,放弃ntfsloop,在dracut自身代码上进行补丁修复 ====================== 文件:/usr/lib/dracut/modules.d/90dmsquash-live/iso-scan.sh ====================== 原代码: mount -t auto -o ro "$dev" "/run/initramfs/isoscan" || continue ======== 新代码 if [ "$(blkid -o value -s TYPE $dev)" = "ntfs" ]; then # Symlinking /usr/bin/ntfs-3g as /sbin/mount.ntfs seems to boot # at the first glance, but ends with lots and lots of squashfs # errors, because systemd attempts to kill the ntfs-3g process?! if [ -x "/usr/bin/ntfs-3g" ]; then ( exec -a @ntfs-3g ntfs-3g -o ro $dev /run/initramfs/isoscan ) | vwarn else die "Failed to mount block device of liveCD image: Missing NTFS support" exit 1 fi else mount -t auto -o ro "$dev" "/run/initramfs/isoscan" || continue fi ================================ 之后,就可以继续研究,使用dracut进行打包了。 研究到这里有几个新发现:centos livecd自带的dracut与yum官方下载的dracut还是有区别的,在livecd里,dracut添加了livenet等多个模块,这些都是dracut-033版本里所没有的。 另外,通过文件复制过来的dracut也许能打包成功,但是不一定能正确运行。也许时权限设定问题,导致有部分东西丢失了。未曾深究。 5, 通过dracut进行打包 先看看dracut的常用命令 dracut --list-modules # list of kernel filesystem modules to be included in the generic initramfs dracut --add " bootchart livenet qemunet ..." 添加各种模块 dracut --add-drivers “ nvme mmc_block” initrafs-with-mymod.img 添加各种驱动 dracut --install 'strace fsck.ext3 ssh' initramfs-dbg.img 添加各种二进制程序 dracut filesystems+="ntfs" 如果以为将上述命令依次敲完,就可以生成一个可以识别nvme和ntfs的img,那就太天真了。每条命令里只新增以给q模块或驱动的方式更是愚昧。因为每条dracut命令都是完整的,都会生成一个全新的img,而这个img与上一个毫无关系,更不会继承上一命令的效果了。只有将所有参数在同一命令执行,生成的img才是我们需要的。 完整的命令如下: # dracut -N --nomdadmconf --nolvmconf --xz \ --add-drivers 'nvme mmc_block' \ --add 'livenet dmsquash-live dmsquash-live-ntfs convertfs pollcdrom qemu qemu-net' \ --no-early-microcode --force \ initrd0.img 说明:a,添加驱动,采用add-drivers命令,在这里添加了nvme和sd卡驱动 b,通过add命令添加了dmsquash-live和其他需用到的模块。 c,模块dmsquash-live-ntfs会完成ntfs-3g及依赖模块的安装,以进行ntfs分区的读写 d,-N, 定义为non-hostonly模式。dmsquash-live-ntfs是不支持hostonly模式的! e, no-early-microcode实际作用未知,但是在NB上证明可有可无的。唯一确认的是,自从添加了它,7zip或cpio解包initramfs时,就会遇到困难了。 有很多种方式对新创建的镜像内容进行检查,包括dracut和lsinitrd dracut --list-modules # list of kernel filesystem modules to be included in the generic initramfs [liveuser@localhost ~]$ lsinitrd initrd-nvme.img > initrd-nvme.txt [liveuser@localhost ~]$ grep nvme initrd-nvme.txt Image: initrd-nvme.img: 29M -rw-r--r-- 1 root root 28444 Nov 9 2018 usr/lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/nvme/host/nvme-core.ko.xz -rw-r--r-- 1 root root 16864 Nov 9 2018 usr/lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/nvme/host/nvme.ko.xz
6, 配置GRUB2, 完成CentOS的ISO引导 此时,革命仍未成功,仍有俩个困难亟待我们解决,a, iso要不要重新打包,包含新创建的initramfs,b,iso文件又如何作为参数传给initramfs。感谢天,感谢地,感谢两年前就完成代码的GRUB2,这俩个问题在它眼里,根本就不是个事。 menuentry 'CentOS-7-x86_64-LiveKDE-1810.iso from ntfs' --class fedora --class gnu-linux --class gnu --class os { insmod iso9660 set root=(hd0,gpt4) set isofile="/images/CentOS-7-x86_64-LiveKDE-1810.iso" search -s root -f ${isofile} loopback loop ${isofile} linux (loop)/isolinux/vmlinuz0 boot=isolinux iso-scan/filename=${isofile} root=live:LABEL="CentOS-7-x86_64-LiveKDE-1810" ro rd.live.image rd.auto=0 rhgb quiet initrd (hd0,gpt4)/images/dracut/initrd0.img } 在CentOS,是通过iso-scan/filename将iso名字作为参数传进initramfs进行加载的。 grub2可以很灵活的设定linux和initrd,并不强制要求他们的位置一致。正是因为这点,我们可以在任何位置加载initrd0.img,只要位置正确,从而避免了对iso进行打包和验证。 CentOS启动的root分区如何设定 对绝大数系统来说,linux都是在真实分区的,因此可以很容易的通过dev或uuid来设定。对于通过iso启动的CentOS来来说,并没有固定的磁盘,也没有真实的uuid,root分区的设定就变得非常困难了,在这里,经过验证的,可以标识它的只有LABEL,也就是光盘的卷标了。虽然在dracut的代码里存在root=live:*.iso的代码,但经测试这段代码与isoboot的场景毫无关系,也就是屁用没有。 在VMware环境下的虚机,可以仿真cdrom,因此通过root=LIVE:/dev/sr0,可以轻松实现root分区挂载。 root分区设置错误,是无法启动的,对任何linux,结果都是一样的,切记这点。 通过grub2加载dracut加持过的initramfs时,总有可能会出现无法正常启动等问题,可以调整grub2的启动参数,进入rd.shell,对运行环境和状态进行分析和诊断 a, 移除rhgb和quiet b, 添加rd.shell rd.udev.info rd.debug. 这样,No root device found时,会自动进入rd.shell,此时可对日志文件/run/initramfs/rdsosreport.txt进行分析。根据分析结果对设备进行检查,通过ls /dev/disks/by-label等命令查看root分区是否已加载。 最常见的启动错误: dracut warning:unable to process initqueue dracut warning: /dev/disk/by-label/Fedora-18-i686-live-Desktop.iso does not exist dracut warning:/dev/mapper/live-rw does not exist Droppint to debug shell
[ 8.444558] localhost dracut-initqueue[656]: + _name='dev-disk-by\x2duuid-E6369F5C369F2D15' [ 8.445792] localhost dracut-initqueue[656]: + '[' -e '/tmp/isoscan-dev-disk-by\x2duuid-E6369F5C369F2D15' ']' [ 8.447135] localhost dracut-initqueue[656]: + mount -t auto -o ro /dev/disk/by-uuid/E6369F5C369F2D15 /run/initramfs/isoscan [ 8.448415] localhost dracut-initqueue[656]: mount: unknown filesystem type 'ntfs' [ 8.449693] localhost dracut-initqueue[656]: + continue [ 8.450956] localhost dracut-initqueue[656]: + rmdir /run/initramfs/isoscan 注:以上错误为ntfs分区的挂载错误,即未打ntfs patch前的报错信息 May 27 14:20:49 localhost dracut-initqueue[683]: + _name='dev-disk-by\x2duuid-E6369F5C369F2D15' May 27 14:20:49 localhost dracut-initqueue[683]: + '[' -e '/tmp/isoscan-dev-disk-by\x2duuid-E6369F5C369F2D15' ']' May 27 14:20:49 localhost dracut-initqueue[683]: ++ blkid -o value -s TYPE /dev/disk/by-uuid/E6369F5C369F2D15 May 27 14:20:49 localhost dracut-initqueue[683]: + '[' ntfs = ntfs ']' May 27 14:20:49 localhost dracut-initqueue[683]: + '[' -x /usr/bin/ntfs-3g ']' May 27 14:20:49 localhost dracut-initqueue[683]: + vwarn May 27 14:20:49 localhost dracut-initqueue[683]: + read line May 27 14:20:49 localhost dracut-initqueue[683]: + exec -a @ntfs-3g ntfs-3g -o ro /dev/disk/by-uuid/E6369F5C369F2D15 /run/initramfs/isoscan May 27 14:20:49 localhost dracut-initqueue[683]: + '[' -n '' ']' May 27 14:20:49 localhost ntfs-3g[2406]: Version 2017.3.23 integrated FUSE 28 May 27 14:20:49 localhost dracut-initqueue[683]: + '[' -f /run/initramfs/isoscan//images/CentOS-7-x86_64-LiveKDE-1810.iso ']' May 27 14:20:49 localhost dracut-initqueue[683]: + losetup -f /run/initramfs/isoscan//images/CentOS-7-x86_64-LiveKDE-1810.iso May 27 14:20:49 localhost ntfs-3g[2406]: Requested device /dev/disk/by-uuid/E6369F5C369F2D15 canonicalized as /dev/nvme0n1p4 May 27 14:20:49 localhost ntfs-3g[2406]: Mounted /dev/nvme0n1p4 (Read-Only, label "Data", NTFS 3.1) May 27 14:20:49 localhost ntfs-3g[2406]: Cmdline options: ro May 27 14:20:49 localhost ntfs-3g[2406]: Mount options: ro,allow_other,nonempty,relatime,fsname=/dev/nvme0n1p4,blkdev,blksize=4096 May 27 14:20:49 localhost ntfs-3g[2406]: Ownership and permissions disabled, configuration type 7 注:以上为正确挂载ntfs分区的完整记录。 在这里,将iso分别存放在ext4和ntfs分区下测试,均成功引导iso,进入live系统。在加载存放在ext4分区下的文件时,记得在grub2下instmod ext2,加载ext2驱动。 在grub2对iso进行loopback时,有一个隐含的小约定。即是否设置loopback为grub2的root。 1, 如通过set root (loop),将iso文件设置为root,那么后续文件都以iso为根目录进行查找的,这种模式下是无法加载我们自定义的initrd0.img的。那么后续的linux/initrd都无需再添加loop或其他分区路径,如(loop)或(hd0, gpt4)等。 2,如不设定loop为root,那么linux和initrd的位置和路径就可以自由设定了,如(loop),如(hd0,gpt4)等,这种方式可以简化代码,也具备更大的灵活性。 在grub2的启动代码里,添加以下代码: rd.live.ram rd.live.overlay=/dev/nvme0n1p4:/images/dracut/centos-overlay.img rd.live.overlay.size=512 rd.live.overlay.thin 即使在LiveCD模式,也会创建一个overlay.img,将系统状态保存下来,避免每次启动都做重复工作。但在实际验证中,发现还有问题需要处理,1), overlay处理代码不支持ntfs,需要额外的补丁; 2), 在overlay和iso保存在同一分区时,加载overlay时,分区已经挂载完成,且以ro的方式。此时也需要更多的代码处理重复挂载,且要重新挂载为rw格式,状态保存时需要。 Jun 05 10:33:01 localhost dracut-initqueue[651]: + '[' -z /dev/nvme0n1p4:/images/dracut/centos-ovly.img ']' Jun 05 10:33:01 localhost dracut-initqueue[651]: + echo /dev/nvme0n1p4:/images/dracut/centos-ovly.img Jun 05 10:33:01 localhost dracut-initqueue[651]: + grep -q : Jun 05 10:33:01 localhost dracut-initqueue[651]: ++ echo /dev/nvme0n1p4:/images/dracut/centos-ovly.img Jun 05 10:33:01 localhost dracut-initqueue[651]: ++ sed -e 's/^.*://' Jun 05 10:33:01 localhost dracut-initqueue[651]: + pathspec=/images/dracut/centos-ovly.img Jun 05 10:33:01 localhost dracut-initqueue[651]: + '[' -z /images/dracut/centos-ovly.img -o /images/dracut/centos-ovly.img = auto ']' Jun 05 10:33:01 localhost dracut-initqueue[651]: ++ echo /dev/nvme0n1p4:/images/dracut/centos-ovly.img Jun 05 10:33:01 localhost dracut-initqueue[651]: ++ sed -e 's/:.*$//' Jun 05 10:33:01 localhost dracut-initqueue[651]: + devspec=/dev/nvme0n1p4 Jun 05 10:33:01 localhost dracut-initqueue[651]: + setup= Jun 05 10:33:01 localhost dracut-initqueue[651]: + '[' -n /dev/nvme0n1p4 -a -n /images/dracut/centos-ovly.img -a -n /dev/nvme0n1p4:/images/dracut/centos-ovly.img ']' Jun 05 10:33:01 localhost dracut-initqueue[651]: + mkdir -m 0755 /run/initramfs/overlayfs Jun 05 10:33:01 localhost dracut-initqueue[651]: + mount -n -t auto /dev/nvme0n1p4 /run/initramfs/overlayfs Jun 05 10:33:02 localhost dracut-initqueue[651]: mount: unknown filesystem type 'ntfs' Jun 05 10:33:02 localhost dracut-initqueue[651]: + : Jun 05 10:33:02 localhost dracut-initqueue[651]: + '[' -f /run/initramfs/overlayfs/images/dracut/centos-ovly.img -a -w /run/initramfs/overlayfs/images/dracut/centos-ovly.img ']' Jun 05 10:33:02 localhost dracut-initqueue[651]: + umount -l /run/initramfs/overlayfs Jun 05 10:33:02 localhost dracut-initqueue[651]: umount: /run/initramfs/overlayfs: not mounted Jun 05 10:33:02 localhost dracut-initqueue[651]: + : Jun 05 10:33:02 localhost dracut-initqueue[651]: + '[' -z '' -o -n '' ']' Jun 05 10:33:02 localhost dracut-initqueue[651]: + '[' -n '' ']' Jun 05 10:33:02 localhost dracut-initqueue[651]: + '[' -n /dev/nvme0n1p4 -a -n /images/dracut/centos-ovly.img ']' Jun 05 10:33:02 localhost dracut-initqueue[651]: + warn 'Unable to find persistent overlay; using temporary' Jun 05 10:33:02 localhost dracut-initqueue[651]: + echo 'Warning: Unable to find persistent overlay; using temporary' Jun 05 10:33:02 localhost dracut-initqueue[651]: Warning: Unable to find persistent overlay; using temporary Jun 05 10:33:02 localhost dracut-initqueue[651]: + sleep 5 Jun 05 10:33:07 localhost dracut-initqueue[651]: + dd if=/dev/null of=/overlay bs=1024 count=1 seek=524288 Jun 05 10:33:07 localhost dracut-initqueue[651]: + '[' -n '' -a -n '' ']' Jun 05 10:33:07 localhost dracut-initqueue[651]: + losetup /dev/loop5 /overlay Jun 05 10:33:07 localhost dracut-initqueue[651]: ++ blockdev --getsz /dev/loop4 Jun 05 10:33:07 localhost dracut-initqueue[651]: + sz=16777216 Jun 05 10:33:07 localhost dracut-initqueue[651]: + '[' -n '' ']' Jun 05 10:33:07 localhost dracut-initqueue[651]: + base=/dev/loop4 Jun 05 10:33:07 localhost dracut-initqueue[651]: + over=/dev/loop5 Jun 05 10:33:07 localhost dracut-initqueue[651]: + '[' -n yes ']' Jun 05 10:33:07 localhost dracut-initqueue[651]: + modprobe dm_thin_pool Jun 05 10:33:07 localhost dracut-initqueue[651]: + mkdir /run/initramfs/thin-overlay Jun 05 10:33:07 localhost dracut-initqueue[651]: + thin_data_sz=1048576 Jun 05 10:33:07 localhost dracut-initqueue[651]: + thin_meta_sz=104857 Jun 05 10:33:07 localhost dracut-initqueue[651]: + dd if=/dev/null of=/run/initramfs/thin-overlay/meta bs=1b count=1 seek=104857 Jun 05 10:33:07 localhost dracut-initqueue[651]: + dd if=/dev/null of=/run/initramfs/thin-overlay/data bs=1b count=1 seek=1048576 Jun 05 10:33:07 localhost dracut-initqueue[651]: ++ losetup --show -f /run/initramfs/thin-overlay/meta 因未在overlay部分打ntfs补丁,在分区挂载失败后,采用了临时的overlay方案。如果把overlay保存在ext4等分区,估计不做代码更新也能成功。 总结 GPT模式下,通过grub2直接引导CentOS的ISO的完整步骤 1, 通过U盘,引导CentOS的liveCD或新安装系统 2, 为live系统配置网络,完成ntfs-3g的安装 3, 更新/usr/lib/dracut/modules.d/90dmsquash-live/iso-scan.sh, 打ntfs挂载patch 4, 通过dracut,打包需要的initramfs 5, 准备iso和initram镜像,配置grub2,完成iso启动。 以安全著称的Qubes已经基本上停止开发,但它也是以dracut封装的xen内核,存在与CentOS一样的问题,没有ntfs-3g, 不能自动loopback iso文件,解决的方案也很简单,用dracut重新打包initrd, 但因其以Xen为kernel,在这里就不再折腾了。 补充及探索 1, 在现有模式里,iso-scan会遍历所有分区,搜索到指定位置的特定文件即终止。后果就是,如果在不同分区存放同名文件, 那么只有前面的分区会被搜到,即使此文件是错误文件。如果想仅搜索指定分区,那修改的dracut代码就太多,也没必要了。 2, 在dracut里,有一大段代码在进行img文件分析和加载。但这段代码只适用于网络启动,支持协议 http, https, ftp, torrent, tftp。从本地磁盘的img启动,单纯依靠这段代码是无法实现的。 当然了,如果对dracut代码进行调整,也可以实现从本地的img启动。这样,即使在物理机环境下,也无独立的分区需求,直接读写本地镜像,也可完成CentOS的运行。这倒是一个好思路,如果有时间,可以继续进行类似的研究。 新增nvme和ntfs-3g的CentOS initrd0.img, 感兴趣的童鞋可直接下载试用 链接: https://pan.baidu.com/s/1dOKzjZsJnOxkhIGUypuxnA 提取码: f8vn Reference: Dracut official documents https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html Dracut的各种模块组合和使用说明 https://wiki.gentoo.org/wiki/Dracut#List_of_modules Dracut中文介绍 https://www.cnblogs.com/doscho/p/6269279.html 制作initrd: update-initramfs脚本分析 https://blog.51cto.com/woshiyu001/2088322 linux initrd的解压与压缩 https://blog.csdn.net/longgeQ1993/article/details/73196325 手工打造自己的Fedora LiveCD https://fedora-tw.org/t/fedora-livecd/378 Howto config NVMe over fabrics https://community.mellanox.com/s/article/howto-configure-nvme-over-fabrics