Mkinitcpio (简体中文)

From ArchWiki
Revision as of 00:05, 7 November 2011 by Jobinson99 (talk | contribs) (Created page with "Category:Boot process (Chinese) Category:Kernel (Chinese) {{i18n|mkinitcpio}} {{DISPLAYTITLE:mkinitcpio}} fr:mkinitcpio {{Article summary start}} {{Article summary t...")
Jump to navigation Jump to search





mkinitcpio is the next generation of initramfs creation.


mkinitcpio是一个Bash脚本，用于创建一个初始化芯存盘（ramdisk）环境。来自mkinitcpio man page的介绍:

初始化芯存盘实际上是一个非常小的运行环境（早期的用户空间），用于加载一些核心模块，并在处理完一些初始化控制之前创建一些必须的东西，比如加密的根文件系统、在软阵列序列上根文件系统。 mkinicpio 可以方便地使用自定义的钩子扩展，可在运行时自动检测，另还有其他一些其他功能。

传统做法中，核心在启动boot process 中，先于加载根文件系统和通过初始化控制之前，负责所有的硬件检测和初始化任务init。但随着技术的演进，这样的做法将趋于复杂化。

今天，根系统可运行于广泛的硬件上，比如SCSI SATA 闪盘，而这些硬件乃是受控于形形色色的厂家所提供的五花八门的驱动之下。另外，根系统可以加密、压缩，可存放在软阵列序列中，或者一个逻辑卷组上。因此，为了简单的处理这种复杂性，可以把管理权转入一个用户空间：初始化芯存盘

可参考: /dev/brain0 » Blog Archive » Early Userspace in Arch Linux.


  • 支持在运行态中使用 udev 用于硬件检测，从而减少加载无用模块。
  • 不需重构系统镜像，即可使用使用核心命令去配置众多功能





$ git clone git://




# mkinitcpio -p linux



# mkinitcpio -p linux

Users can manually create an image using an alternate configuration file:







Warning: lvm2, mdadm, encrypt 默认是启用的。 如有需要，可详读这节。

Users can modify five variables within the configuration file:

Kernel modules to be loaded before any boot hooks are run.
Additional binaries to be included in the initramfs image.
Additional files to be included in the initramfs image.
Hooks are scripts that execute in the initial ramdisk.
Used to compress the initramfs image.
Command line options to pass to the COMPRESSION program.



MODULES="piix ide_disk reiserfs"


HOOKS="base autodetect ide filesystems"


Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Mkinitcpio (简体中文)#)

Template:Box YELLOW





BINARIES="fsck fsck.ext4"



$ ls -1 /lib/initcpio/install


$ mkinitcpio -H base



HOOKS="base udev autodetect pata scsi sata filesystems"


HOOKS="base udev pata scsi sata filesystems"

For support for encrypted volumes on LVM2 volume groups:



Common hooks
Hook Installation Runtime


由于计算机设备越来越多，因此，启动所需包含的模块越来越多，因此，有时有必要对初始化芯存系统进行压缩。系统支持下列压缩格式 - gzip, bzip2, lzma, xz (also known as lzma2), 和 lzo. 大部分情况下，gzip或者lzop提供的压缩镜像大小和解压速度之间平衡得较好。

COMPRESSION="bzip2"     # kernel 2.6.30后可用
COMPRESSION="lzma"      # kernel 2.6.30后可用
COMPRESSION="lzop"      # kernel 2.6.34后可用
COMPRESSION="xz"        # kernel 2.6.38后可用






Runtime customization





root=/dev/sda1                                                # /dev node
root=LABEL=CorsairF80                                         # label
root=801                                                      # hex-encoded major/minor number

Using RAID




Using net

Required Packages:

net requires the Template:Package Official package from the official repositories.

Kernel Parameters:




Parameter explanation:

               either be determined by RARP/BOOTP/DHCP. What protocol
               is used depends on the <autoconf> parameter. If this
               parameter is not empty, autoconf will be used.
               determine the client address and this parameter is NOT
               empty only replies from the specified server are
               accepted. To use different RARP and NFS server,
               specify your NFS server in the `nfsroot' parameter
               server is used which answered the RARP/BOOTP/DHCP
               server is assumed to be on the local network, unless a
               value has been received by BOOTP/DHCP.
               the netmask is derived from the client IP address assuming
               classful addressing, unless overridden in BOOTP/DHCP reply.
               used in ASCII notation, or the value received by
               first one we receive a reply on is configured. If you
               have only one device, you can safely leave this blank.
               no autoconfiguration.


 ip=  --> Enable the loopback interface.
 ip= --> Enable static eth2 interface.




Parameter explanation:

               is not given, the default address as determined by the
               parameter is for example to allow using different servers
               for RARP and NFS. Usually you can leave this blank.
               replaced by the ASCII-representation of the client's IP
               If the options field is not given, the following defaults
               will be used:
                       port            = as given by server portmap daemon
                       rsize           = 1024
                       wsize           = 1024
                       timeo           = 7
                       retrans         = 3
                       acregmin        = 3
                       acregmax        = 60
                       acdirmin        = 30
                       acdirmax        = 60
                       flags           = hard, nointr, noposix, cto, ac



Using lvm



for example


Using encrypted root


For an encrypted partition on a SATA or SCSI disk:


For an encrypted LVM volume:



Using LUKS volumes



Using a key-file




Using legacy cryptsetup volumes





Using loop-aes volumes

mkinitcpio does not support loop-aes yet.


Extracting the image




You can list the files in the image with:

$ lsinitcpio /boot/initramfs-linux.img

And to extract them all in the current directory:

$ lsinitcpio -x /boot/initramfs-linux.img


$ lsinitcpio -a /boot/initramfs-linux.img


  1. Linux Kernel documentation on initramfs
  2. Linux Kernel documentation on initrd
  3. Wikipedia article on initrd