为 vmlinuz 和 initrd 设置自定义名称,以便多个发行版可以共享启动目录

为 vmlinuz 和 initrd 设置自定义名称,以便多个发行版可以共享启动目录

我在上设置了三重启动系统btrfs,并且有 arch、xenial 和 bionic,如下所示:

  • 加密btrfs容器
  • 每一个都有btrfs subvol自己的根源
  • /boot三者之间未加密共享

我已经使用这个设置用于 arch 和 xenial 一年多了,效果非常好。现在我添加了 bionic,我对内核和 initrd 的命名有点担心。例如:

$ ls /boot
initramfs-linux.img           # arch; no problems here
initrd.img-4.13.0-39-generic  # xenial
initrd.img-4.15.0-20-generic  # bionic
vmlinuz-linux                 # arch
vmlinuz-4.13.0-39-generic     # xenial
vmlinuz-4.15.0-20-generic     # bionic

也许仿生名称永远不会与 xenial 冲突,但也许会。

我想知道是否有一个钩子或配置文件可以设置这些文件的默认名称,而无需我自己编译。基本上,某种方式可以像或被CONFIG_LOCALVERSION传递一样EXTRAVERSION?或者一个可以拦截默认文件名并附加其他内容的钩子?

我维护自己的引导程序(rEFInd现在),我并不担心那方面(grub例如,有些人可能预见到对我所问内容的同步的担忧)。


另外,我愿意接受其他解决方案。我认为一般情况是“如何让多个发行版启动文件共存于一个分区?”我提到这一点是因为我刚刚偶然发现这个帖子,即设置子目录,而不是更改名称。使用路径来分隔这些目录也很好。也许在initramfs 工具,但目前我还不清楚。


我无法发表评论来充分回答主要问题,因此我添加以下评论来解决迄今为止的主要问题:

您无法更改 Ubuntu 内核的名称,因为很多程序都引用原始名称。

接下来使用来locate显示文件系统中内核版本字符串被使用了多少次。

我正在使用以下refind.conf条目启动 Ubuntu xenial 进行编写:

$ cat /boot/efi/EFI/refind/refind.conf
menuentry "xenial" {
    icon        /EFI/refind/icons/os_ubuntu.png
    volume      4bdcd743-9d09-2f41-9379-e5491e79ae9d
    loader      /vmlinuz-foo
    initrd      /initrd-foo
    options     "root=UUID=xxxx rootflags=compress=lzo,discard,ssd,subvol=xenial nomodeset $vt_handoff add_efi_memmap ro"
}

为了做到这一点,我做了:

$ cd /boot
$ sudo mv initrd.img-4.13.0-39-generic initrd-foo
$ sudo mv vmlinuz-4.13.0-39-generic vmlinuz-foo

文件名本身并不重要,因为内核版本是在内核中

$ uname -a
Linux roboxenial 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

所以...我可以从任何我想要的文件名运行。问题仍然存在,是否有办法在安装/升级期间以某种方式更改每个内核名称(如钩子)。这可能是一个约定(例如initrd-xenial),后缀(initrd.img-4.13.0-39-generic_xenial)或其他。

答案1

您无法更改 Ubuntu 内核的名称,因为许多程序都引用了原始名称。以我当前的内核为例4.14.34

$ locate 4.14.34 | wc -l
70192
$ ll /boot/*4.14.34*
-rw-r--r-- 1 root root  1496011 Apr 12 05:53 /boot/abi-4.14.34-041434-generic
-rw-r--r-- 1 root root   213406 Apr 12 05:53 /boot/config-4.14.34-041434-generic
-rw-r--r-- 1 root root 58514444 Apr 28 13:36 /boot/initrd.img-4.14.34-041434-generic
-rw-r--r-- 1 root root        0 Apr 12 05:53 /boot/retpoline-4.14.34-041434-generic
-rw------- 1 root root  3952348 Apr 12 05:53 /boot/System.map-4.14.34-041434-generic
-rw------- 1 root root  8607504 Apr 30 03:52 /boot/vmlinuz-4.14.34-041434-generic

有 70,192 个文件链接到内核版本4.14.34,但其中只有五个位于/boot您希望重命名的位置。

正如评论中提到的,ArchLinux 使用与 Ubuntu 相同的内核名称的危险性很小,因为它们有自己独特的编号系统:如何将 Linux 内核映射到 Ubuntu 内核?

笔记:运行此程序时,我安装了两个 Ubuntu 16.04 分区,因此4.14.34单个 16.04 安装的文件数为 35,096。还请注意,其中包含了标头,我认为这些标头是可选的,但我总是“以防万一”安装它们。

大型列表

以下是列表的开头locate。如果vmlinuz重命名,模块文件可能将无法找到:

$ locate 4.14.34 | head -n1000
/boot/System.map-4.14.34-041434-generic
/boot/abi-4.14.34-041434-generic
/boot/config-4.14.34-041434-generic
/boot/initrd.img-4.14.34-041434-generic
/boot/retpoline-4.14.34-041434-generic
/lib/modprobe.d/blacklist_linux_4.14.34-041434-generic.conf
/lib/modules/4.14.34-041434-generic
/lib/modules/4.14.34-041434-generic/build
/lib/modules/4.14.34-041434-generic/initrd
/lib/modules/4.14.34-041434-generic/kernel
/lib/modules/4.14.34-041434-generic/modules.alias
/lib/modules/4.14.34-041434-generic/modules.alias.bin
/lib/modules/4.14.34-041434-generic/modules.builtin
/lib/modules/4.14.34-041434-generic/modules.builtin.bin
/lib/modules/4.14.34-041434-generic/modules.dep
/lib/modules/4.14.34-041434-generic/modules.dep.bin
/lib/modules/4.14.34-041434-generic/modules.devname
/lib/modules/4.14.34-041434-generic/modules.order
/lib/modules/4.14.34-041434-generic/modules.softdep
/lib/modules/4.14.34-041434-generic/modules.symbols
/lib/modules/4.14.34-041434-generic/modules.symbols.bin
/lib/modules/4.14.34-041434-generic/vdso
/lib/modules/4.14.34-041434-generic/kernel/arch
/lib/modules/4.14.34-041434-generic/kernel/block
/lib/modules/4.14.34-041434-generic/kernel/crypto
/lib/modules/4.14.34-041434-generic/kernel/drivers
/lib/modules/4.14.34-041434-generic/kernel/fs
/lib/modules/4.14.34-041434-generic/kernel/kernel
/lib/modules/4.14.34-041434-generic/kernel/lib
/lib/modules/4.14.34-041434-generic/kernel/mm
/lib/modules/4.14.34-041434-generic/kernel/net
/lib/modules/4.14.34-041434-generic/kernel/sound
/lib/modules/4.14.34-041434-generic/kernel/virt
/lib/modules/4.14.34-041434-generic/kernel/arch/x86
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/events
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kvm
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/oprofile
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/platform
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/aes-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/aesni-intel.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/blowfish-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/camellia-aesni-avx-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/camellia-aesni-avx2.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/camellia-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/cast5-avx-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/cast6-avx-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/chacha20-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/crc32-pclmul.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/crct10dif-pclmul.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/des3_ede-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/ghash-clmulni-intel.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/glue_helper.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/poly1305-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/salsa20-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/serpent-avx-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/serpent-avx2.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/serpent-sse2-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha1-mb
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha1-ssse3.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha256-mb
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha256-ssse3.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha512-mb
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha512-ssse3.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/twofish-avx-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/twofish-x86_64-3way.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/twofish-x86_64.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha1-mb/sha1-mb.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha256-mb/sha256-mb.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/crypto/sha512-mb/sha512-mb.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/events/intel
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/events/intel/intel-cstate.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/events/intel/intel-rapl-perf.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel/cpu
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel/cpuid.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel/msr.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel/cpu/mcheck
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kernel/cpu/mcheck/mce-inject.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kvm/kvm-amd.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kvm/kvm-intel.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/kvm/kvm.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/oprofile/oprofile.ko
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/platform/atom
/lib/modules/4.14.34-041434-generic/kernel/arch/x86/platform/atom/punit_atom_debug.ko
/lib/modules/4.14.34-041434-generic/kernel/block/bfq.ko
/lib/modules/4.14.34-041434-generic/kernel/block/kyber-iosched.ko
/lib/modules/4.14.34-041434-generic/kernel/block/mq-deadline.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/842.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/ablk_helper.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/aes_ti.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/af_alg.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/algif_aead.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/algif_hash.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/algif_rng.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/algif_skcipher.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/ansi_cprng.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/anubis.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/arc4.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/asymmetric_keys
/lib/modules/4.14.34-041434-generic/kernel/crypto/async_tx
/lib/modules/4.14.34-041434-generic/kernel/crypto/authenc.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/authencesn.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/blowfish_common.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/blowfish_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/camellia_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/cast5_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/cast6_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/cast_common.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/ccm.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/chacha20_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/chacha20poly1305.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/cmac.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/crc32_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/cryptd.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/crypto_engine.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/crypto_simd.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/crypto_user.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/deflate.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/des_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/ecdh_generic.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/echainiv.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/fcrypt.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/keywrap.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/khazad.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/lrw.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/lz4.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/lz4hc.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/mcryptd.ko
/lib/modules/4.14.34-041434-generic/kernel/crypto/md4.ko

相关内容