18c2ecf20Sopenharmony_ci======================= 28c2ecf20Sopenharmony_ciinitramfs buffer format 38c2ecf20Sopenharmony_ci======================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciAl Viro, H. Peter Anvin 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciLast revision: 2002-01-13 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciStarting with kernel 2.5.x, the old "initial ramdisk" protocol is 108c2ecf20Sopenharmony_cigetting {replaced/complemented} with the new "initial ramfs" 118c2ecf20Sopenharmony_ci(initramfs) protocol. The initramfs contents is passed using the same 128c2ecf20Sopenharmony_cimemory buffer protocol used by the initrd protocol, but the contents 138c2ecf20Sopenharmony_ciis different. The initramfs buffer contains an archive which is 148c2ecf20Sopenharmony_ciexpanded into a ramfs filesystem; this document details the format of 158c2ecf20Sopenharmony_cithe initramfs buffer format. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciThe initramfs buffer format is based around the "newc" or "crc" CPIO 188c2ecf20Sopenharmony_ciformats, and can be created with the cpio(1) utility. The cpio 198c2ecf20Sopenharmony_ciarchive can be compressed using gzip(1). One valid version of an 208c2ecf20Sopenharmony_ciinitramfs buffer is thus a single .cpio.gz file. 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciThe full format of the initramfs buffer is defined by the following 238c2ecf20Sopenharmony_cigrammar, where:: 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci * is used to indicate "0 or more occurrences of" 268c2ecf20Sopenharmony_ci (|) indicates alternatives 278c2ecf20Sopenharmony_ci + indicates concatenation 288c2ecf20Sopenharmony_ci GZIP() indicates the gzip(1) of the operand 298c2ecf20Sopenharmony_ci ALGN(n) means padding with null bytes to an n-byte boundary 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci initramfs := ("\0" | cpio_archive | cpio_gzip_archive)* 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci cpio_gzip_archive := GZIP(cpio_archive) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci cpio_archive := cpio_file* + (<nothing> | cpio_trailer) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci cpio_trailer := ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciIn human terms, the initramfs buffer contains a collection of 438c2ecf20Sopenharmony_cicompressed and/or uncompressed cpio archives (in the "newc" or "crc" 448c2ecf20Sopenharmony_ciformats); arbitrary amounts zero bytes (for padding) can be added 458c2ecf20Sopenharmony_cibetween members. 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciThe cpio "TRAILER!!!" entry (cpio end-of-archive) is optional, but is 488c2ecf20Sopenharmony_cinot ignored; see "handling of hard links" below. 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciThe structure of the cpio_header is as follows (all fields contain 518c2ecf20Sopenharmony_cihexadecimal ASCII numbers fully padded with '0' on the left to the 528c2ecf20Sopenharmony_cifull width of the field, for example, the integer 4780 is represented 538c2ecf20Sopenharmony_ciby the ASCII string "000012ac"): 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci============= ================== ============================================== 568c2ecf20Sopenharmony_ciField name Field size Meaning 578c2ecf20Sopenharmony_ci============= ================== ============================================== 588c2ecf20Sopenharmony_cic_magic 6 bytes The string "070701" or "070702" 598c2ecf20Sopenharmony_cic_ino 8 bytes File inode number 608c2ecf20Sopenharmony_cic_mode 8 bytes File mode and permissions 618c2ecf20Sopenharmony_cic_uid 8 bytes File uid 628c2ecf20Sopenharmony_cic_gid 8 bytes File gid 638c2ecf20Sopenharmony_cic_nlink 8 bytes Number of links 648c2ecf20Sopenharmony_cic_mtime 8 bytes Modification time 658c2ecf20Sopenharmony_cic_filesize 8 bytes Size of data field 668c2ecf20Sopenharmony_cic_maj 8 bytes Major part of file device number 678c2ecf20Sopenharmony_cic_min 8 bytes Minor part of file device number 688c2ecf20Sopenharmony_cic_rmaj 8 bytes Major part of device node reference 698c2ecf20Sopenharmony_cic_rmin 8 bytes Minor part of device node reference 708c2ecf20Sopenharmony_cic_namesize 8 bytes Length of filename, including final \0 718c2ecf20Sopenharmony_cic_chksum 8 bytes Checksum of data field if c_magic is 070702; 728c2ecf20Sopenharmony_ci otherwise zero 738c2ecf20Sopenharmony_ci============= ================== ============================================== 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciThe c_mode field matches the contents of st_mode returned by stat(2) 768c2ecf20Sopenharmony_cion Linux, and encodes the file type and file permissions. 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciThe c_filesize should be zero for any file which is not a regular file 798c2ecf20Sopenharmony_cior symlink. 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciThe c_chksum field contains a simple 32-bit unsigned sum of all the 828c2ecf20Sopenharmony_cibytes in the data field. cpio(1) refers to this as "crc", which is 838c2ecf20Sopenharmony_ciclearly incorrect (a cyclic redundancy check is a different and 848c2ecf20Sopenharmony_cisignificantly stronger integrity check), however, this is the 858c2ecf20Sopenharmony_cialgorithm used. 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciIf the filename is "TRAILER!!!" this is actually an end-of-archive 888c2ecf20Sopenharmony_cimarker; the c_filesize for an end-of-archive marker must be zero. 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ciHandling of hard links 928c2ecf20Sopenharmony_ci====================== 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciWhen a nondirectory with c_nlink > 1 is seen, the (c_maj,c_min,c_ino) 958c2ecf20Sopenharmony_cituple is looked up in a tuple buffer. If not found, it is entered in 968c2ecf20Sopenharmony_cithe tuple buffer and the entry is created as usual; if found, a hard 978c2ecf20Sopenharmony_cilink rather than a second copy of the file is created. It is not 988c2ecf20Sopenharmony_cinecessary (but permitted) to include a second copy of the file 998c2ecf20Sopenharmony_cicontents; if the file contents is not included, the c_filesize field 1008c2ecf20Sopenharmony_cishould be set to zero to indicate no data section follows. If data is 1018c2ecf20Sopenharmony_cipresent, the previous instance of the file is overwritten; this allows 1028c2ecf20Sopenharmony_cithe data-carrying instance of a file to occur anywhere in the sequence 1038c2ecf20Sopenharmony_ci(GNU cpio is reported to attach the data to the last instance of a 1048c2ecf20Sopenharmony_cifile only.) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cic_filesize must not be zero for a symlink. 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciWhen a "TRAILER!!!" end-of-archive marker is seen, the tuple buffer is 1098c2ecf20Sopenharmony_cireset. This permits archives which are generated independently to be 1108c2ecf20Sopenharmony_ciconcatenated. 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciTo combine file data from different sources (without having to 1138c2ecf20Sopenharmony_ciregenerate the (c_maj,c_min,c_ino) fields), therefore, either one of 1148c2ecf20Sopenharmony_cithe following techniques can be used: 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cia) Separate the different file data sources with a "TRAILER!!!" 1178c2ecf20Sopenharmony_ci end-of-archive marker, or 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cib) Make sure c_nlink == 1 for all nondirectory entries. 120