← 返回命令列表

Linux command

mkinitramfs 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Generate initramfs for the current kernel

sudo mkinitramfs -o [/boot/initrd.img]

Generate initramfs for a specific kernel version

sudo mkinitramfs -o [/boot/initrd.img-5.10.0] [5.10.0-generic]

Generate with verbose output

sudo mkinitramfs -v -o [/boot/initrd.img]

Keep the temporary working directory for inspection

sudo mkinitramfs -k -o [/boot/initrd.img]

Use a specific configuration directory

sudo mkinitramfs -d [/etc/initramfs-tools] -o [/boot/initrd.img]

说明

mkinitramfs creates an initial ramdisk image (initramfs) for Linux. The initramfs contains essential drivers and scripts needed to mount the root filesystem during boot, including storage drivers, filesystem modules, and early userspace tools. This tool is Debian/Ubuntu specific and is typically invoked indirectly via update-initramfs. Other distributions use different tools (mkinitcpio on Arch, dracut on Fedora/RHEL).

参数

-o _FILE_
Output file (required). The generated initramfs image path.
-d _CONFDIR_
Use an alternate configuration directory (default: /etc/initramfs-tools).
-k
Keep the temporary directory used during generation for debugging.
-v
Verbose output showing files being added.
-c _COMPRESS_
Override the compression method (gzip, lz4, lzma, lzop, xz, zstd).

FAQ

What is the mkinitramfs command used for?

mkinitramfs creates an initial ramdisk image (initramfs) for Linux. The initramfs contains essential drivers and scripts needed to mount the root filesystem during boot, including storage drivers, filesystem modules, and early userspace tools. This tool is Debian/Ubuntu specific and is typically invoked indirectly via update-initramfs. Other distributions use different tools (mkinitcpio on Arch, dracut on Fedora/RHEL).

How do I run a basic mkinitramfs example?

Run `sudo mkinitramfs -o [/boot/initrd.img]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o _FILE_ do in mkinitramfs?

Output file (required). The generated initramfs image path.