120 lines · plain
1=======================2initramfs buffer format3=======================4 5Al Viro, H. Peter Anvin6 7Last revision: 2002-01-138 9Starting with kernel 2.5.x, the old "initial ramdisk" protocol is10getting {replaced/complemented} with the new "initial ramfs"11(initramfs) protocol. The initramfs contents is passed using the same12memory buffer protocol used by the initrd protocol, but the contents13is different. The initramfs buffer contains an archive which is14expanded into a ramfs filesystem; this document details the format of15the initramfs buffer format.16 17The initramfs buffer format is based around the "newc" or "crc" CPIO18formats, and can be created with the cpio(1) utility. The cpio19archive can be compressed using gzip(1). One valid version of an20initramfs buffer is thus a single .cpio.gz file.21 22The full format of the initramfs buffer is defined by the following23grammar, where::24 25 * is used to indicate "0 or more occurrences of"26 (|) indicates alternatives27 + indicates concatenation28 GZIP() indicates the gzip(1) of the operand29 ALGN(n) means padding with null bytes to an n-byte boundary30 31 initramfs := ("\0" | cpio_archive | cpio_gzip_archive)*32 33 cpio_gzip_archive := GZIP(cpio_archive)34 35 cpio_archive := cpio_file* + (<nothing> | cpio_trailer)36 37 cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data38 39 cpio_trailer := ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4)40 41 42In human terms, the initramfs buffer contains a collection of43compressed and/or uncompressed cpio archives (in the "newc" or "crc"44formats); arbitrary amounts zero bytes (for padding) can be added45between members.46 47The cpio "TRAILER!!!" entry (cpio end-of-archive) is optional, but is48not ignored; see "handling of hard links" below.49 50The structure of the cpio_header is as follows (all fields contain51hexadecimal ASCII numbers fully padded with '0' on the left to the52full width of the field, for example, the integer 4780 is represented53by the ASCII string "000012ac"):54 55============= ================== ==============================================56Field name Field size Meaning57============= ================== ==============================================58c_magic 6 bytes The string "070701" or "070702"59c_ino 8 bytes File inode number60c_mode 8 bytes File mode and permissions61c_uid 8 bytes File uid62c_gid 8 bytes File gid63c_nlink 8 bytes Number of links64c_mtime 8 bytes Modification time65c_filesize 8 bytes Size of data field66c_maj 8 bytes Major part of file device number67c_min 8 bytes Minor part of file device number68c_rmaj 8 bytes Major part of device node reference69c_rmin 8 bytes Minor part of device node reference70c_namesize 8 bytes Length of filename, including final \071c_chksum 8 bytes Checksum of data field if c_magic is 070702;72 otherwise zero73============= ================== ==============================================74 75The c_mode field matches the contents of st_mode returned by stat(2)76on Linux, and encodes the file type and file permissions.77 78The c_filesize should be zero for any file which is not a regular file79or symlink.80 81The c_chksum field contains a simple 32-bit unsigned sum of all the82bytes in the data field. cpio(1) refers to this as "crc", which is83clearly incorrect (a cyclic redundancy check is a different and84significantly stronger integrity check), however, this is the85algorithm used.86 87If the filename is "TRAILER!!!" this is actually an end-of-archive88marker; the c_filesize for an end-of-archive marker must be zero.89 90 91Handling of hard links92======================93 94When a nondirectory with c_nlink > 1 is seen, the (c_maj,c_min,c_ino)95tuple is looked up in a tuple buffer. If not found, it is entered in96the tuple buffer and the entry is created as usual; if found, a hard97link rather than a second copy of the file is created. It is not98necessary (but permitted) to include a second copy of the file99contents; if the file contents is not included, the c_filesize field100should be set to zero to indicate no data section follows. If data is101present, the previous instance of the file is overwritten; this allows102the data-carrying instance of a file to occur anywhere in the sequence103(GNU cpio is reported to attach the data to the last instance of a104file only.)105 106c_filesize must not be zero for a symlink.107 108When a "TRAILER!!!" end-of-archive marker is seen, the tuple buffer is109reset. This permits archives which are generated independently to be110concatenated.111 112To combine file data from different sources (without having to113regenerate the (c_maj,c_min,c_ino) fields), therefore, either one of114the following techniques can be used:115 116a) Separate the different file data sources with a "TRAILER!!!"117 end-of-archive marker, or118 119b) Make sure c_nlink == 1 for all nondirectory entries.120