求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

编译打包和其他
回复
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#1

帖子 fga333 » 2019-07-28 18:00

系统版本ubuntu16.04.本人使用mkinitramfs脚本生成的initrd.img格式为cpio,现在怎么生成zip格式的initrd.img?
发现ubuntu14.04使用mkinitramfs脚本生成的initrd.img格式为zip格式。求助,谢谢!
头像
astolia
论坛版主
帖子: 6444
注册时间: 2008-09-18 13:11

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#2

帖子 astolia » 2019-07-30 14:36

从来就不支持zip格式。gzip/bzip2不是zip
修改 /etc/initramfs-tools/initramfs.conf 中的COMPRESS选项,或者给mkinitramfs加上-c参数来指定
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#3

帖子 fga333 » 2019-08-15 14:19

astolia 写了: 2019-07-30 14:36 从来就不支持zip格式。gzip/bzip2不是zip
修改 /etc/initramfs-tools/initramfs.conf 中的COMPRESS选项,或者给mkinitramfs加上-c参数来指定
您好:
1、/etc/initramfs-tools/initramfs.conf中的COMPRESS选项已经是gzip。
#
# initramfs.conf
# Configuration file for mkinitramfs(8). See initramfs.conf(5).
#
# Note that configuration options from this file can be overridden
# by config files in the /etc/initramfs-tools/conf.d directory.

#
# MODULES: [ most | netboot | dep | list ]
#
# most - Add most filesystem and all harddrive drivers.
#
# dep - Try and guess which modules to load.
#
# netboot - Add the base modules, network modules, but skip block devices.
#
# list - Only include modules from the 'additional modules' list
#

MODULES=most

#
# BUSYBOX: [ y | n | auto ]
#
# Use busybox shell and utilities. If set to n, klibc utilities will be used.
# If set to auto (or unset), busybox will be used if installed and klibc will
# be used otherwise.
#

BUSYBOX=auto

#
# COMPCACHE_SIZE: [ "x K" | "x M" | "x G" | "x %" ]
#
# Amount of RAM to use for RAM-based compressed swap space.
#
# An empty value - compcache isn't used, or added to the initramfs at all.
# An integer and K (e.g. 65536 K) - use a number of kilobytes.
# An integer and M (e.g. 256 M) - use a number of megabytes.
# An integer and G (e.g. 1 G) - use a number of gigabytes.
# An integer and % (e.g. 50 %) - use a percentage of the amount of RAM.
#
# You can optionally install the compcache package to configure this setting
# via debconf and have userspace scripts to load and unload compcache.
#

COMPCACHE_SIZE=""

#
# COMPRESS: [ gzip | bzip2 | lzma | lzop | xz ]
#

COMPRESS=gzip
#
# NFS Section of the config.
#

#
# DEVICE: ...
#
# Specify a specific network interface, like eth0
# Overridden by optional ip= bootarg
#

DEVICE=

#
# NFSROOT: [ auto | HOST:MOUNT ]
#

NFSROOT=auto
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#4

帖子 fga333 » 2019-08-15 14:23

astolia 写了: 2019-07-30 14:36 从来就不支持zip格式。gzip/bzip2不是zip
修改 /etc/initramfs-tools/initramfs.conf 中的COMPRESS选项,或者给mkinitramfs加上-c参数来指定
root@dh:/# cd /boot/
root@dh:/boot# ls
abi-4.15.0-29-generic config-4.15.18.old initrd.img-4.15.0-29-generic memtest86+.elf System.map-4.15.0-29-generic vmlinuz-4.15.0-29-generic
config-4.15.0-29-generic efi initrd.img-4.15.18 memtest86+_multiboot.bin System.map-4.15.18 vmlinuz-4.15.18
config-4.15.18 grub memtest86+.bin retpoline-4.15.0-29-generic System.map-4.15.18.old vmlinuz-4.15.18.old
root@dh:/boot# file initrd.img-4.15.18
initrd.img-4.15.18: ASCII cpio archive (SVR4 with no CRC)
root@dh:/boot#
头像
astolia
论坛版主
帖子: 6444
注册时间: 2008-09-18 13:11

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#5

帖子 astolia » 2019-08-15 18:05

出现这个现象的原因是,你系统上生成的initrd.img不是一个单一格式的文件,而是在压缩包之前附加了多个cpio包
你可以用cpio -t < /boot/initrd.img-4.15.18或cpio -i < /boot/initrd.img-4.15.18,来查看/解压出第一个cpio包的内容,应该是cpu的微码
如果你非要生成纯gzip的包,删除/usr/share/initramfs-tools/hooks/下面intel-microcode和amd64-microcode两个文件,不让它们往initrd.img前添加微码和更新微码的代码应该就可以了
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#6

帖子 fga333 » 2019-08-21 17:58

astolia 写了: 2019-08-15 18:05 出现这个现象的原因是,你系统上生成的initrd.img不是一个单一格式的文件,而是在压缩包之前附加了多个cpio包
你可以用cpio -t < /boot/initrd.img-4.15.18或cpio -i < /boot/initrd.img-4.15.18,来查看/解压出第一个cpio包的内容,应该是cpu的微码
如果你非要生成纯gzip的包,删除/usr/share/initramfs-tools/hooks/下面intel-microcode和amd64-microcode两个文件,不让它们往initrd.img前添加微码和更新微码的代码应该就可以了

root@dh:~/cxx#
root@dh:~/cxx# cpio -ivmd < /boot/initrd.img-4.15.18
.
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/AuthenticAMD.bin
56 blocks
root@dh:~/cxx# du -sh ./*
40K ./kernel
root@dh:~/cxx# ls /boot/initrd.img-4.15.18 -l
-rw-r--r-- 1 root root 454219559 8月 21 17:28 /boot/initrd.img-4.15.18
root@dh:~/cxx# file /boot/initrd.img-4.15.18
/boot/initrd.img-4.15.18: ASCII cpio archive (SVR4 with no CRC)
root@dh:~/cxx#
root@dh:~/cxx#

删掉intel-microcode和amd64-microcode两个文件以后,还是老样子,解压不全
头像
astolia
论坛版主
帖子: 6444
注册时间: 2008-09-18 13:11

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#7

帖子 astolia » 2019-08-22 14:51

fga333 写了: 2019-08-21 17:58 删掉intel-microcode和amd64-microcode两个文件以后,还是老样子,解压不全
你的文件里有AuthenticAMD.bin,就是amd64-microcode带进来的。说明你删了文件之后没有重建initrd。
如果你是用update-initramfs来生成的,要加-c参数
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#8

帖子 fga333 » 2019-08-22 17:10

astolia 写了: 2019-08-22 14:51
fga333 写了: 2019-08-21 17:58 删掉intel-microcode和amd64-microcode两个文件以后,还是老样子,解压不全
你的文件里有AuthenticAMD.bin,就是amd64-microcode带进来的。说明你删了文件之后没有重建initrd。
如果你是用update-initramfs来生成的,要加-c参数
我是将文件删除以后,编译内核make modules_install && make install自动重新生成initrd。请问这这样生成的initrd有什么区别吗,正确的做法应该怎么做? :Sad
fga333
帖子: 17
注册时间: 2019-07-28 14:27
系统: ubuntu16

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#9

帖子 fga333 » 2019-08-24 18:28

astolia 写了: 2019-08-22 14:51
fga333 写了: 2019-08-21 17:58 删掉intel-microcode和amd64-microcode两个文件以后,还是老样子,解压不全
你的文件里有AuthenticAMD.bin,就是amd64-microcode带进来的。说明你删了文件之后没有重建initrd。
如果你是用update-initramfs来生成的,要加-c参数
按照你的方法问题解决了,现在已经变成gzip格式

root@dh:/boot# file initrd.img-4.15.18
initrd.img-4.15.18: gzip compressed data, last modified: Sat Aug 24 06:26:25 2019, from Unix
root@dh:/boot#

非常感谢 :Haha

顺便再问一句:
编译内核自动生成的initrd.img-4.15.18非常大,将近几百兆,导致开机时加载非常慢,影响了开机速度。
这个initrd.img大小可以用什么办法控制吗?
头像
astolia
论坛版主
帖子: 6444
注册时间: 2008-09-18 13:11

Re: 求助:ubuntu16.04如何使用mkinitramfs生成zip格式的initrd.img

#10

帖子 astolia » 2019-08-27 1:32

gzip本来压缩率就不怎么样,换xz会好很多。另外你不修改内核配置的话,默认是照抄当前运行内核的配置,一般发行版为了兼容尽可能多的硬件,各种杂七杂八的驱动模块包含了一堆进去。你针对特定机器编译的话,不需要的驱动完全可以去掉。
回复