ramfs, rootfs and initramfs
October 17, 2005
2005ǯ1017
Rob Landley <rob@landley.net>
=============================

ܸȻ <yosshydebian.or.jp>


ʸ­餺ʬʸ {} ­뤫
        ޤ


What is ramfs?
ramfs Ȥϲ
--------------


Ramfs is a very simple filesystem that exports Linux's disk caching
mechanisms (the page cache and dentry cache) as a dynamically resizable
ram-based filesystem.

ramfs  Linux Υǥå嵡(ڡå dentry 
åˤưŪ˥Ѳ RAM ١Υե륷ƥȤ
ɽ˽Ф˥ץʥե륷ƥǤ

Normally all files are cached in memory by Linux.  Pages of data read from
backing store (usually the block device the filesystem is mounted on) are kept
around in case it's needed again, but marked as clean (freeable) in case the
Virtual Memory system needs the memory for something else.  Similarly, data
written to files is marked clean as soon as it has been written to backing
store, but kept around for caching purposes until the VM reallocates the
memory.  A similar mechanism (the dentry cache) greatly speeds up access to
directories.

̾ƤΥե Linux ˤäƥ˥å夵ޤ
(̾ϤΥե륷ƥबޥȤ줿֥åǥХ) 
ɤ߹ޤ줿ǡΥڡϡ줬ɬפȤ
{ڡåȤ}ݻƤꡢۥꥷƥब¾ǥ
ɬפȽǤ{ѤǤ褦} clean (ǽ)ȥޡ
ޤƱͤˡե˽񤭹ޤ줿ǡϡ󼡵֤˽񤭹
줿餹 clean ȥޡޤۥ굡Ƴ
Ƥʤ¤ꥭåŪݻޤƱͤε(dentry å)
ϥǥ쥯ȥꥢŪ˹®ޤ

With ramfs, there is no backing store.  Files written into ramfs allocate
dentries and page cache as usual, but there's nowhere to write them to.
This means the pages are never marked clean, so they can't be freed by the
VM when it's looking to recycle memory.

ramfs Ǥϡ󼡵֤ޤramfs ˽񤭹ޤ줿ե 
{Υե륷ƥ}Ʊ褦 dentry ڡåѤ
ޤ餬񤭹ޤϤɤˤ⤢ޤ󡣤ϡΥڡ
Ϸ褷 clean ȥޡʤ椨ۥ굡{
ǽ}Ѥ뤿õݤˤ⡢ΥڡǤ


The amount of code required to implement ramfs is tiny, because all the
work is done by the existing Linux caching infrastructure.  Basically,
you're mounting the disk cache as a filesystem.  Because of this, ramfs is not
an optional component removable via menuconfig, since there would be negligible
space savings.

{ramfs Ǥ}٤ƤκȤ¸ Linux åˤäƹԤ
뤿ᡢramfs ٤ɬפʥ̤Ϥ鷺ǤŪˡ
{ramfs }ǥåե륷ƥȤƥޥȤޤ
Τᡢramfs  menuconfig {Linux ͥ빽ۻ}Ǻǽʥ
ץǤǤϤޤ󤷡ʤȤƤǤ륵Ϥ鷺
Ǥ礦

ramfs and ramdisk:
ramfs  RAM ǥ
------------------

The older "ram disk" mechanism created a synthetic block device out of
an area of ram and used it as backing store for a filesystem.  This block
device was of fixed size, so the filesystem mounted on it was of fixed
size.  Using a ram disk also required unnecessarily copying memory from the
fake block device into the page cache (and copying changes back out), as well
as creating and destroying dentries.  Plus it needed a filesystem driver
(such as ext2) to format and interpret this data.

ŤRAM ǥ׵ RAM ΰѤ˵֥åǥХ
ꡢե륷ƥ󼡵֤ȤƻѤƤޤΥ
åǥХϸꥵʤΤǡξ˥ޥȤ줿ե륷
ꥵǤRAM ǥѤϤޤ֥åǥ
ڡå(ȥڡι򵿻֥åǥХ)
ɬפʥꥳԡɬפǡޤ dentry ǤƱͤǤ
äơRAM ǥϤΥǡեޥåȤƲ᤹٤(ext2 
褦)ե륷ƥɥ饤ФɬפǤ

Compared to ramfs, this wastes memory (and memory bus bandwidth), creates
unnecessary work for the CPU, and pollutes the CPU caches.  (There are tricks
to avoid this copying by playing with the page tables, but they're unpleasantly
complicated and turn out to be about as expensive as the copying anyway.)
More to the point, all the work ramfs is doing has to happen _anyway_,
since all file access goes through the page and dentry caches.  The ram
disk is simply unnecessary, ramfs is internally much simpler.

ramfs ӤơRAM ǥϥ(ȥΥХХ)̵̤
;פ CPU ٤CPU åޤ(ڡơ֥
äƤΥԡ򤹤ȥåޤϴ򤷤
ȤʣǡԡΤƱͤ˥ȤʬäƤޤ)
դäСƤΥեϥڡ dentry å̤ƥ
Τǡramfs ưϡ֤ɤʾǤ׵ΤʤΤǤRAM 
ǥñפǤꡢramfs ŪˤäȥץǤ

Another reason ramdisks are semi-obsolete is that the introduction of
loopback devices offered a more flexible and convenient way to create
synthetic block devices, now from files instead of from chunks of memory.
See losetup (8) for details.

RAM ǥʪȤʤĤĤ̤ͳϡloopback ǥХƳ
β (chunks) ǤϤʤե뤫鵿֥åǥХ
뤿ΤǲŬʼʤ󶡤ƤǤܺ٤ 
losetup (8) 򻲾ȤƲ

ramfs and tmpfs:
ramfs  tmpfs:
----------------

One downside of ramfs is you can keep writing data into it until you fill
up all memory, and the VM can't free it because the VM thinks that files
should get written to backing store (rather than swap space), but ramfs hasn't
got any backing store.  Because of this, only root (or a trusted user) should
be allowed write access to a ramfs mount.

ramfs Υޥʥ̤ϡramfs ˽񤭹ǡƤΥ
Ǥޤ VM ΥǤʤǤʤʤ顢VM Ͻ
ޤ줿ե(åץڡǤϤʤ)󼡵֤˽񤭹⤦
ޤramfs ˤ󼡵֤ʤǤΤᡢroot (ޤ
ѤǤ1桼) Τ ramfs ޥȤФ񤭹ߥĤ
٤Ǥ

A ramfs derivative called tmpfs was created to add size limits, and the ability
to write the data to swap space.  Normal users can be allowed write access to
tmpfs mounts.  See Documentation/filesystems/tmpfs.txt for more information.

tmpfs ȸƤФ ramfs ʪϡ{ե륷ƥ}¤
٤ȥǡ򥹥åץڡ˽ϲǽˤ٤˺ޤ
桼 tmpfs ޥȤؤν񤭹ߥĤǤޤʾ
 Documentation/filesystems/tmpfs.txt 򻲾ȤƲ

What is rootfs?
rootfs Ȥϲ
---------------

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is
always present in 2.6 systems.  You can't unmount rootfs for approximately the
same reason you can't kill the init process; rather than having special code
to check for and handle an empty list, it's smaller and simpler for the kernel
to just make sure certain lists can't become empty.

rootfs  ramfs (ޤͭʤ tmpfs) ̤¸ߤǤꡢͥ 
2.6 ΥƥǤϾ¸ߤƤޤinit ץ kill Ǥʤ
ȤۤƱͤͳǡrootfs ϥޥȤǤޤ󡣤ĤޤꥹȤ
åư٤̤ʥɤĤꡢñˤΥꥹȤˤ
ʤݾڤͥˤȤäƾޤꥷץʰ٤Ǥ

Most systems just mount another filesystem over rootfs and ignore it.  The
amount of space an empty instance of ramfs takes up is tiny.

ۤȤɤΥƥ rootfs ξ̤Υե륷ƥޥȤ
rootfs ̵뤷ޤ ramfs Υ̤Ϥ鷺Ǥ

What is initramfs?
initramfs Ȥϲ
------------------

All 2.6 Linux kernels contain a gzipped "cpio" format archive, which is
extracted into rootfs when the kernel boots up.  After extracting, the kernel
checks to see if rootfs contains a file "init", and if so it executes it as PID
1.  If found, this init process is responsible for bringing the system the
rest of the way up, including locating and mounting the real root device (if
any).  If rootfs does not contain an init program after the embedded cpio
archive is extracted into it, the kernel will fall through to the older code
to locate and mount a root partition, then exec some variant of /sbin/init
out of that.

Ƥ 2.6  Linux ͥ gzip ̤줿cpioץեޥåȤΥ
֤ޤǤꡢϥͥ뤬ưݤ rootfs Ÿޤ
Ÿ塢ͥ rootfs initץեޤǤ뤫ɤǧ
 PID 1 ȤƼ¹Ԥޤξ硢 init ץϥ
ƥ൯ưλĤʬǤˤ(⤷)ʪΥ롼ȥǥ
ȥޥȤޤޤޤޤ줿 cpio ֤Ÿ塢
rootfs  init ץޤǤʤäϡͥϥ롼ȥѡ
ƥꤷƥޥȤŤɤΩꡢrootfs γ 
/sbin/init ¹Ԥޤ

ͥ뤬ưͣ줫ĺǽΥ桼ץλ
        ץ ID (PID)  1 ˤʤޤ

All this differs from the old initrd in several ways:

ϸŤ initrd ȤϴĤʬǰۤʤޤ

  - The old initrd was always a separate file, while the initramfs archive is
    linked into the linux kernel image.  (The directory linux-*/usr is devoted
    to generating this archive during the build.)

  - Ť initrd ϾñȤΥեǤinitramfs ֤ 
    Linux ͥ륤᡼˥󥯤ޤ(linux-*/usr ǥ쥯ȥ
    ϥͥ빽ˤΥ֤٤ʪǤ)

  - The old initrd file was a gzipped filesystem image (in some file format,
    such as ext2, that needed a driver built into the kernel), while the new
    initramfs archive is a gzipped cpio archive (like tar only simpler,
    see cpio(1) and Documentation/early-userspace/buffer-format.txt).  The
    kernel's cpio extraction code is not only extremely small, it's also
    __init data that can be discarded during the boot process.

  - Ť initrd ե gzip ̤줿ե륷ƥ।᡼
    (ext2 Τ褦ʤĤΥեեޥåȤǡͥ˥ɥ饤
    Ȥ߹Ǥɬפ)Ǥ initramfs ֤ 
    gzip ̤줿 cpio (tar Τ褦ʤΤñˤꥷץ롢
    ܺ٤ cpio(1) ޥ˥奢
    Documentation/early-userspace/buffer-format.txt )Ǥ
     cpio ŸɤϤ˾ǤϤʤưץ
    ֤˴ǽ __init ǡǤ⤢ޤ

  - The program run by the old initrd (which was called /initrd, not /init) did
    some setup and then returned to the kernel, while the init program from
    initramfs is not expected to return to the kernel.  (If /init needs to hand
    off control it can overmount / with a new root device and exec another init
    program.  See the switch_root utility, below.)

  - Ť initrd ˤäƼ¹Ԥץ(/init ǤϤʤ /initrd 
    ƤФ)ϴĤΥåȥåפԤäƤθ奫ͥޤ
    initramfs  init ץϥͥ뤳ȤȤƤޤ
    (⤷ /init ɬפС/ 򿷤롼ȥǥ
    Ǿ񤭥ޥȤ̤ init ưǤޤҤ 
    switch_root 桼ƥƥ򻲾Ȳ)

  - When switching another root device, initrd would pivot_root and then
    umount the ramdisk.  But initramfs is rootfs: you can neither pivot_root
    rootfs, nor unmount it.  Instead delete everything out of rootfs to
    free up the space (find -xdev / -exec rm '{}' ';'), overmount rootfs
    with the new root (cd /newmount; mount --move . /; chroot .), attach
    stdin/stdout/stderr to the new /dev/console, and exec the new init.

  - ̤ root ǥХؤݡinitrd Ǥ pivot_root 
     RAM ǥ򥢥ޥȤƤޤinitramfs  
    rootfs Ǥrootfs  pivot_root Ǥޤ󤷡ޥȤ
    ǤޤˡΥ֤뤿 rootfs 
    Ƥõ(find -xdev / -exec rm '{}' ';')롼ȥǥХ
    夫ޥȤޤ(cd /newmount; mount --move . /; chroot .)ɸ
    /ɸ/ɸ२顼Ϥ򿷤 /dev/console ˥åơ
     init ¹Ԥޤ

롼ȥե륷ƥ촹륷ƥॳ롢ޤϤΥޥ

    Since this is a remarkably persnickity process (and involves deleting
    commands before you can run them), the klibc package introduced a helper
    program (utils/run_init.c) to do all this for you.  Most other packages
    (such as busybox) have named this command "switch_root".

    ˹η㤷(⤽¹Ԥ˥ޥ
    ξõȼ)ǤΤǡklibc ΥѥåϤʤΰ٤ˤ
    ƤԤإѡץ(utils/run_init.c)Ƴޤ
    (busybox Τ褦)¾ΤۤȤɤΥѥåϤΥޥɤ 
    switch_rootפ̾դƤޤ

Populating initramfs:
initramfs դƤߤ:
---------------------

The 2.6 kernel build process always creates a gzipped cpio format initramfs
archive and links it into the resulting kernel binary.  By default, this
archive is empty (consuming 134 bytes on x86).

2.6 ͥι۲Ͼ gzip 줿 cpio եޥåȤ initramfs 
֤ۤ줿ͥХʥ˥󥯤ޤ
Υ֤϶Ǥ(x86 Ǥ 134 ХȾ񤷤ޤ)

The config option CONFIG_INITRAMFS_SOURCE (for some reason buried under
devices->block devices in menuconfig, and living in usr/Kconfig) can be used
to specify a source for the initramfs archive, which will automatically be
incorporated into the resulting binary.  This option can point to an existing
gzipped cpio archive, a directory containing files to be archived, or a text
file specification such as the following example:

ꥪץ CONFIG_INITRAMFS_SOURCE(Ĥͳǡmenuconfig 
 devices->block ǥХɽ졢usr/Kconfig ޤ) 
 initramfs ָꤹ٤˻ѤǤޤΥץ
¸ gzip ̤줿 cpio ֤֤ե
ǥ쥯ȥ꤫Τ褦ʻͤΥƥȥեꤹǤޤ

  dir /dev 755 0 0
  nod /dev/console 644 0 0 c 5 1
  nod /dev/loop0 644 0 0 b 7 0
  dir /bin 755 1000 1000
  slink /bin/sh busybox 777 0 0
  file /bin/busybox initramfs/busybox 755 0 0
  dir /proc 755 0 0
  dir /sys 755 0 0
  dir /mnt 755 0 0
  file /init initramfs/init.sh 755 0 0

Run "usr/gen_init_cpio" (after the kernel build) to get a usage message
documenting the above file format.

嵭ΥեեޥåȤ usage å뤿ˡ
(ͥ빽۸)usr/gen_init_cpioפ¹ԤƲ

One advantage of the configuration file is that root access is not required to
set permissions or create device nodes in the new archive.  (Note that those
two example "file" entries expect to find files named "init.sh" and "busybox" in
a directory called "initramfs", under the linux-2.6.* directory.  See
Documentation/early-userspace/README for more details.)

ե1Ĥϡ֤˥ѡߥå
ǥХΡɤݤ root ɬפʤȤǤ
(2Ĥ file ȥǤϡlinux-2.6.* ǥ쥯ȥ겼 
initramfs Ȥǥ쥯ȥ init.sh  busybox Ȥե뤬
ꤷƤޤܺ٤ Documentation/early-userspace/README 
ȤƲ)

The kernel does not depend on external cpio tools.  If you specify a
directory instead of a configuration file, the kernel's build infrastructure
creates a configuration file from that directory (usr/Makefile calls
scripts/gen_initramfs_list.sh), and proceeds to package up that directory
using the config file (by feeding it to usr/gen_init_cpio, which is created
from usr/gen_init_cpio.c).  The kernel's build-time cpio creation code is
entirely self-contained, and the kernel's boot-time extractor is also
(obviously) self-contained.

ͥϳ cpio ġ˰¸Ƥޤ󡣤⤷եǤϤ
ǥ쥯ȥꤷϡͥι۴פϤΥǥ쥯ȥ꤫
ե(usr/Makefile  scripts/gen_initramfs_list.sh 
¹Ԥޤ)եѤƥǥ쥯ȥΥѥå
ޤ(եusr/gen_init_cpio.c 줿 
usr/gen_init_cpio ˿碌ޤ)ͥιۻ cpio ɤ
˥ͥ륽˴ޤޤƤꡢͥεư cpio Ÿ
ޤ(Ǥ)ͥ˴ޤޤƤޤ

The one thing you might need external cpio utilities installed for is creating
or extracting your own preprepared cpio files to feed to the kernel build
(instead of a config file or directory).

Υ󥹥ȡѤ cpio 桼ƥƥɬפˤʤ1ĤΥϡ
ͥ빽ۤ˿碌٤(եǥ쥯ȥǤϤʤ)ʤ
Ȥ cpio եޤŸǤ

The following command line can extract a cpio image (either by the above script
or by the kernel build) back into its component files:

ʲΥޥɥ饤(嵭ΥץȤޤϥͥ빽ۤΤɤ餫
줿) cpio ᡼򤽤ιե뷲Ÿޤ

  cpio -i -d -H newc -F initramfs_data.cpio --no-absolute-filenames

The following shell script can create a prebuilt cpio archive you can
use in place of the above config file:

ʲΥ륹ץȤǡۺѤߤ cpio ֤Ǥޤ
ΥץȤϡ嵭ե˻Ȥޤ

ǤϡեפѤȤޤϻꤵ줿ǥ
        쥯ȥ겼 cpio + gzip ֤륹ץȤˤ
        ޤ

  #!/bin/sh

  # Copyright 2006 Rob Landley <rob@landley.net> and TimeSys Corporation.
  # Licensed under GPL version 2

  if [ $# -ne 2 ]
  then
    echo "usage: mkinitramfs directory imagename.cpio.gz"
    exit 1
  fi

  if [ -d "$1" ]
  then
    echo "creating $2 from $1"
    (cd "$1"; find . | cpio -o -H newc | gzip) > "$2"
  else
    echo "First argument must be a directory"
    exit 1
  fi

Note: The cpio man page contains some bad advice that will break your initramfs
archive if you follow it.  It says "A typical way to generate the list
of filenames is with the find command; you should give find the -depth option
to minimize problems with permissions on directories that are unwritable or not
searchable."  Don't do this when creating initramfs.cpio.gz images, it won't
work.  The Linux kernel cpio extractor won't create files in a directory that
doesn't exist, so the directory entries must go before the files that go in
those directories.  The above script gets them in the right order.

cpio ޥ˥奢ڡϡ̤˹ԤȤʤ initramfs 
֤ƤޤĤΰɥХޤǤޤ۩֥ե
̾ΰŵŪˡ find ޥɤѤǡ񤭹Բ
ޤϥԲĤʥǥ쥯ȥΥѡߥåˤǾ
٤ find ޥɤ -depth ץͿ٤Ǥ
initramfs.cpio.gz ᡼ݤϤ̤ˤʤǲ
ưޤLinux ͥ cpio Ÿ롼ϡǥ쥯ȥ
¸ߤʤˤϤΥեޤΤǡǥ쥯ȥ
Υե뷲ΥȥˤΥǥ쥯ȥΥȥ꤬ʤȤ
󡣾嵭ΥץȤϰޤ


External initramfs images:
 initramfs ᡼
--------------------------

If the kernel has initrd support enabled, an external cpio.gz archive can also
be passed into a 2.6 kernel in place of an initrd.  In this case, the kernel
will autodetect the type (initramfs, not initrd) and extract the external cpio
archive into rootfs before trying to run /init.

ͥ initrd ݡȤͭˤ硢initrd ˳ 
cpio.gz ֤ 2.6 ͥϤǤޤξ硢
ϼưŪˤΥ(initd ǤϤʤ initramfs)Τ/init μ¹
˳ cpio ֤ rootfs Ÿޤ

This has the memory efficiency advantages of initramfs (no ramdisk block
device) but the separate packaging of initrd (which is nice if you have
non-GPL code you'd like to run from initramfs, without conflating it with
the GPL licensed Linux kernel binary).

ϡ(RAM ǥΥ֥åǥХΤʤ)initramfs ΥΨ
ΥåȤ¾ˡinitrd ʬΥѥå󥰤ȤåȤ
ޤ( GPL Υɤ initramfs ¹ԤˡLinux 
Хʥ GPL 饤󥹤ȾͤʤΤɤ)

It can also be used to supplement the kernel's built-in initamfs image.  The
files in the external archive will overwrite any conflicting files in
the built-in initramfs archive.  Some distributors also prefer to customize
a single kernel image with task-specific initramfs images, without recompiling.

ϥͥȤ߹ޤ줿 initramfs ᡼­٤ˤѤ
ޤΥե뷲ϡͥȤ߹ޤ줿 
initramfs ζ礹ե뷲񤭤ޤĤΥǥ
ȥӥ塼⡢ꥳѥ뤻ñΥͥ륤᡼̤ 
initramfs ᡼ǥޥˡ򹥤ߤޤ

Contents of initramfs:
initramfs :
----------------------

An initramfs archive is a complete self-contained root filesystem for Linux.
If you don't already understand what shared libraries, devices, and paths
you need to get a minimal root filesystem up and running, here are some
references:

initramfs ֤ϴʼʴ뷿 Linux ѥ롼ȥե륷
Ǥ¤Υ롼ȥե륷ƥƵư٤ɬפʶͭ饤
֥ꡢǥХѥˤĤƤޤ򤷤ƤʤΤǤС˴
λʸ񤬤ޤ

http://www.tldp.org/HOWTO/Bootdisk-HOWTO/
http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html
http://www.linuxfromscratch.org/lfs/view/stable/

The "klibc" package (http://www.kernel.org/pub/linux/libs/klibc) is
designed to be a tiny C library to statically link early userspace
code against, along with some related utilities.  It is BSD licensed.

klibc ѥå(http://www.kernel.org/pub/linux/libs/klibc)ϡư
ʳΥ桼֤ΥɤФŪ󥯤褦˥ǥ󤵤줿
 C 饤֥ȴϢ桼ƥƥǤ BSD 饤󥹤ǥ饤󥹤Ƥޤ

I use uClibc (http://www.uclibc.org) and busybox (http://www.busybox.net)
myself.  These are LGPL and GPL, respectively.  (A self-contained initramfs
package is planned for the busybox 1.3 release.)

伫Ȥ uClibc (http://www.uclibc.org)  busybox
(http://www.busybox.net) ѤƤޤϤ줾 LPGL  
GPL ǥ饤󥹤Ƥޤ(ʴ뷿 initramfs ѥå 
busybox 1.3 ꡼Ƿײ褵Ƥޤ)

In theory you could use glibc, but that's not well suited for small embedded
uses like this.  (A "hello world" program statically linked against glibc is
over 400k.  With uClibc it's 7k.  Also note that glibc dlopens libnss to do
name lookups, even when otherwise statically linked.)

Ūˤ glibc ѤƤɤΤǤglibc ϤΤ褦ʾϤ
Ȥ߹ѤˤϤޤƤޤ(glibc Ū󥯤줿Hello
worldץץ{Υ} 400kB ĶƤޤuClibc  7kB 
ޤglibc ϥƥå󥯤ȤƤ⡢ͥåȥ̾β
򤹤٤ libnss  dlopen ޤ)

dlopenĥץ൯ư˶ͭ饤֥ɲäưŪ󥯤
        ƥॳ롣ǤŪ󥯤ϤΥХʥ꤬ libnss 
        ưŪ󥯤뤷Ƥޤ

A good first step is to get initramfs to run a statically linked "hello world"
program as init, and test it under an emulator like qemu (www.qemu.org) or
User Mode Linux, like so:

ɤǽΰϡŪ󥯤줿hello worldץץ init 
Ƽ¹Ԥ initramfs äơqemu (www.qemu.org) User Mode Linux 
Τ褦ʥߥ졼ǥƥȤǤΤ褦ˡ

  cat > hello.c << EOF
  #include <stdio.h>
  #include <unistd.h>

  int main(int argc, char *argv[])
  {
    printf("Hello world!\n");
    sleep(999999999);
  }
  EOF
  gcc -static hello2.c -o init
  echo init | cpio -o -H newc | gzip > test.cpio.gz
  # Testing external initramfs using the initrd loading mechanism.
  qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero

When debugging a normal root filesystem, it's nice to be able to boot with
"init=/bin/sh".  The initramfs equivalent is "rdinit=/bin/sh", and it's
just as useful.

̾Υ롼ȥե륷ƥǥХåݡinit=/bin/shעǵư
ǤɤȤǤinitramfs ѥ᡼
rdinit=/bin/shעǡǤ

init=סrdinit=׶ Linux Υͥ륳ޥɥ饤󥪥ץ
        ǡ֡ȥ qemu/UML μ¹Ի˻ꤷޤ

Why cpio rather than tar?
 tar Ǥʤ cpio ʤΤ
-------------------------

This decision was made back in December, 2001.  The discussion started here:

ηǤ 2001ǯ12̤ޤϤϤޤޤ

  http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1538.html

And spawned a second thread (specifically on tar vs cpio), starting here:

(tar  cpio ò) 2ܤεǳޤ

  http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1587.html

The quick and dirty summary version (which is no substitute for reading
the above threads) is:

ʰפǹӤ (2ĤεΤɤˤϤʤޤ) ϡ

1) cpio is a standard.  It's decades old (from the AT&T days), and already
   widely used on Linux (inside RPM, Red Hat's device driver disks).  Here's
   a Linux Journal article about it from 1996:

1) cpio 1ĤɸǤǯʪ(AT&T 夫)Ǥꡢ Linux 
   ǹѤƤޤ (RPM  Red Hat ΥǥХɥ饤Хǥ
   ) 1996 ǯ cpio ˴ؤ Linux Journal ޤ

      http://www.linuxjournal.com/article/1213

   It's not as popular as tar because the traditional cpio command line tools
   require _truly_hideous_ command line arguments.  But that says nothing
   either way about the archive format, and there are alternative tools,
   such as:

   Ū cpio ޥɥ饤ġ뤬ּ¤˹󤤡װɬפȤ
   ١cpio  tar ͵ޤ󡣤ΤȤϥ֤
   եޥåȤͥȤϴطޤ󡣲Τ褦إġ뤬
   ޤ

     http://freshmeat.net/projects/afio/

2) The cpio archive format chosen by the kernel is simpler and cleaner (and
   thus easier to create and parse) than any of the (literally dozens of)
   various tar archive formats.  The complete initramfs archive format is
   explained in buffer-format.txt, created in usr/gen_init_cpio.c, and
   extracted in init/initramfs.c.  All three together come to less than 26k
   total of human-readable text.

2) ͥ뤬򤷤 cpio ֥եޥåȤϡ(ʸɤ겿
   ⤢) tar Υ֥եޥåȤΤɤñ㤫Ĥ
   줤(äɤñ)Ǥ initramfs ֥ե
   ޥåȤ buffer-format.txt ˵Ҥ졢usr/gen_init_cpio.c 
   졢init/initramfs.c Ÿޤ飳Ĥ碌Ƥ⡢
   ɤΥƥȥեޥå 26kB ̤ˤʤޤ

3) The GNU project standardizing on tar is approximately as relevant as
   Windows standardizing on zip.  Linux is not part of either, and is free
   to make its own technical decisions.

3) tar  GNU ץɸಽϡ zip  Windows ɸಽ
   ƤޤLinux ϤΤɤǤ⤢ޤ󤷡ȼεŪ
   򤹤ϼͳǤ

4) Since this is a kernel internal format, it could easily have been
   something brand new.  The kernel provides its own tools to create and
   extract this format anyway.  Using an existing standard was preferable,
   but not essential.

4) ϥͥեޥåȤǤ뤿ᡢñ˲ʪ
   ǤޤʤȤ⥫ͥϤΥեޥåȤŸ
   ȼΥġ󶡤Ƥޤ¸ɸλѤ˾ޤϤ
   ޤԲķǤϤޤ

5) Al Viro made the decision (quote: "tar is ugly as hell and not going to be
   supported on the kernel side"):

5) Al Viro 򲼤ޤ (ѡtar ϻƥͥ¦
   ݡȤʤ)

      http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1540.html

   explained his reasoning:

   {}ͳϤƤޤ

      http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1550.html
      http://www.uwsg.iu.edu/hypermail/linux/kernel/0112.2/1638.html

   and, most importantly, designed and implemented the initramfs code.

   ޤʻϡinitramfs ɤ߷ס줿Ǥ

Future directions:

------------------

Today (2.6.16), initramfs is always compiled in, but not always used.  The
kernel falls back to legacy boot code that is reached only if initramfs does
not contain an /init program.  The fallback is legacy code, there to ensure a
smooth transition and allowing early boot functionality to gradually move to
"early userspace" (I.E. initramfs).

(2.6.16)initramfs ϾȤ߹ޤƤޤ˻ȤƤ
ǤϤޤinitramfs  /init ץޤǤʤä
ΤߡͥϸŤưɤ˼¹ԤޤغϸŤ
ɤα߳ʰܹԤݾڤ뤿ᡢĤޤ굯ưǽ(early boot
functionality) ֵư桼ڡ(¨ initramfs)˽˰
ԤǤ褦ˤ뤿ˤޤ

The move to early userspace is necessary because finding and mounting the real
root device is complex.  Root partitions can span multiple devices (raid or
separate journal).  They can be out on the network (requiring dhcp, setting a
specific mac address, logging into a server, etc).  They can live on removable
media, with dynamically allocated major/minor numbers and persistent naming
issues requiring a full udev implementation to sort out.  They can be
compressed, encrypted, copy-on-write, loopback mounted, strangely partitioned,
and so on.


ư桼ڡؤΰܹԤɬפʤΤϡ¥롼ȥǥХθФȥ
ȤʣʤǤ롼ȥѡƥʣΥǥХʬ
ޤ(RAID ޤʬΥ㡼ʥ)롼ȥѡƥϥͥå
ۤˤʤޤ(DHCP MAC ɥ쥹ꡢФ
Υ)ɬפʾ礬ޤ)롼ȥѡƥ
ࡼХ֥ǥˤϡưŪ˥ǥХΥ᥸㡼ޥʡ
ֹ椬դƤꡢ̾ΤȤ뤿ˤϡ udev ˤä
褷ʤФʤޤ󡣥롼ȥѡƥϰ̡Ź沽
copy-on-write롼ץХåޥȡüʬ䡢¾줳줵
ޤ

This kind of complexity (which inevitably includes policy) is rightly handled
in userspace.  Both klibc and busybox/uClibc are working on simple initramfs
packages to drop into a kernel build.

μʣ(ɬŪ˥ݥꥷޤ)ϥ桼ڡǰΤŬڤ
klibc  busybox/uClibc Ϥɤ⡢ñ initramfs ѥå
ͥӥɤ˴ޤѤǤޤ

The klibc package has now been accepted into Andrew Morton's 2.6.17-mm tree.
The kernel's current early boot code (partition detection, etc) will probably
be migrated into a default initramfs, automatically created and used by the
kernel build.

klibc ѥåϸߡAndrew Morton  2.6.17-mm ĥ꡼˴ޤޤƤ
ޤͥθߤư(ѡƥ󸡽)¿ʬ
ͥ빽ۻ˼ưŪ˺ǥեȤ initramfs ˰ܿǤ

