URL
https://opencores.org/ocsvn/or1k_old/or1k_old/trunk
Subversion Repositories or1k_old
[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [Documentation/] [initrd.txt] - Rev 1782
Compare with Previous | Blame | View Log
Using the initial RAM disk (initrd)===================================Written 1996 by Werner Almesberger <almesber@lrc.epfl.ch> andHans Lermen <lermen@elserv.ffm.fgan.de>initrd adds the capability to load a RAM disk by the boot loader. ThisRAM disk can then be mounted as the root file system and programs can berun from it. Afterwards, a new root file system can be mounted from adifferent device. The previous root (from initrd) is then either movedto the directory /initrd or it is unmounted.initrd is mainly designed to allow system startup to occur in two phases,where the kernel comes up with a minimum set of compiled-in drivers, andwhere additional modules are loaded from initrd.Operation---------When using initrd, the system boots as follows:1) the boot loader loads the kernel and the initial RAM disk2) the kernel converts initrd into a "normal" RAM disk andfrees the memory used by initrd3) initrd is mounted read-write as root4) /linuxrc is executed (this can be any valid executable, includingshell scripts; it is run with uid 0 and can do basically everythinginit can do)5) when linuxrc terminates, the "real" root file system is mounted6) if a directory /initrd exists, the initrd is moved thereotherwise, initrd is unmounted7) the usual boot sequence (e.g. invocation of /sbin/init) is performedon the root file systemNote that moving initrd from / to /initrd does not involve unmounting it.It is therefore possible to leave processes running on initrd (or leavefile systems mounted, but see below) during that procedure. However, if/initrd doesn't exist, initrd can only be unmounted if it is not used byanything. If it can't be unmounted, it will stay in memory.Also note that file systems mounted under initrd continue to be accessible,but their /proc/mounts entries are not updated. Also, if /initrd doesn'texist, initrd can't be unmounted and will "disappear" and take those filesystems with it, thereby preventing them from being re-mounted. It istherefore strongly suggested to generally unmount all file systems (exceptof course for the root file system, but including /proc) before switchingfrom initrd to the "normal" root file system.In order to deallocate the memory used for the initial RAM disk, you haveto execute freeramdisk (see 'Resources' below) after unmounting /initrd.Boot command-line options-------------------------initrd adds the following new options:initrd=<path> (LOADLIN only)Loads the specified file as the initial RAM disk. When using LILO, youhave to specify the RAM disk image file in /etc/lilo.conf, using theINITRD configuration variable.noinitrdinitrd data is preserved but it is not converted to a RAM disk andthe "normal" root file system is mounted. initrd data can be readfrom /dev/initrd. Note that the data in initrd can have any structurein this case and doesn't necessarily have to be a file system image.This option is used mainly for debugging.Note that /dev/initrd is read-only and that it can only be used once.As soon as the last process has closed it, all data is freed and/dev/initrd can't be opened any longer.root=/dev/raminitrd is mounted as root, and /linuxrc is started. If no /linuxrcexists, the normal boot procedure is followed, with the RAM diskstill mounted as root. This option is mainly useful when booting froma floppy disk. Compared to directly mounting an on-disk file system,the intermediate step of going via initrd adds a little speedadvantage and it allows the use of a compressed file system.Also, together with LOADLIN you may load the RAM disk directly fromCDrom or disk, hence having a floppyless boot from CD,e.g.: E:\loadlin E:\bzImage root=/dev/ram initrd=E:\rdimageInstallation------------First, the "normal" root file system has to be prepared as follows:# mknod /dev/initrd b 0 250# chmod 400 /dev/initrd# mkdir /initrdIf the root file system is created during the boot procedure (i.e. ifyou're creating an install floppy), the root file system creationprocedure should perform these operations.Note that neither /dev/initrd nor /initrd are strictly required forcorrect operation of initrd, but it is a lot easier to experiment withinitrd if you have them, and you may also want to use /initrd to passdata to the "real" system.Second, the kernel has to be compiled with RAM disk support and withsupport for the initial RAM disk enabled. Also, at least all componentsneeded to execute programs from initrd (e.g. executable format and filesystem) must be compiled into the kernel.Third, you have to create the RAM disk image. This is done by creating afile system on a block device and then by copying files to it as needed.With recent kernels, at least three types of devices are suitable forthat:- a floppy disk (works everywhere but it's painfully slow)- a RAM disk (fast, but allocates physical memory)- a loopback device (the most elegant solution, but currently requires amodified mount)We'll describe the RAM disk method:1) make sure you have a RAM disk device /dev/ram (block, major 1, minor 0)2) create an empty file system of the appropriate size, e.g.# mke2fs -m0 /dev/ram 300(if space is critical, you may want to use the Minix FS instead of Ext2)3) mount the file system on an appropriate directory, e.g.# mount -t ext2 /dev/ram /mnt4) create the console device:# mkdir /mnt/dev# mknod /mnt/dev/tty1 c 4 15) copy all the files that are needed to properly use the initrdenvironment. Don't forget the most important file, /linuxrcNote that /linuxrc's permissions must include "x" (execute).6) unmount the RAM disk# umount /dev/ram7) copy the image to a file# dd if=/dev/ram bs=1k count=300 of=/boot/initrd8) deallocate the RAM disk# freeramdisk /dev/ramFor experimenting with initrd, you may want to take a rescue floppy (e.g.rescue.gz from Slackware) and only add a symbolic link from /linuxrc to/bin/sh, e.g.# gunzip <rescue.gz >/dev/ram# mount -t minix /dev/ram /mnt# ln -s /bin/sh /mnt/linuxrc# umount /dev/ram# dd if=/dev/ram bs=1k count=1440 of=/boot/initrd# freeramdisk /dev/ramFinally, you have to boot the kernel and load initrd. Currently,preliminary versions of LOADLIN 1.6 and LILO 18 support initrd (seebelow for where to get them). With LOADLIN, you simply executeLOADLIN <kernel> initrd=<disk_image>e.g. LOADLIN C:\LINUX\VMLINUZ initrd=C:\LINUX\INITRDWith LILO, you add the option INITRD=<path> to either the global sectionor to the section of the respective kernel in /etc/lilo.conf, e.g.image = /vmlinuzinitrd = /boot/initrdand run /sbin/liloNow you can boot and enjoy using initrd.Setting the root device-----------------------By default, the standard settings in the kernel are used for the rootdevice, i.e. the default compiled in or set with rdev, or what was passedwith root=xxx on the command line, or, with LILO, what was specified in/etc/lilo.conf It is also possible to use initrd with an NFS-mountedroot; you have to use the nfs_root_name and nfs_root_addrs boot optionsfor this.It is also possible to change the root device from within the initrdenvironment. In order to do so, /proc has to be mounted. Then, thefollowing files are available:/proc/sys/kernel/real-root-dev/proc/sys/kernel/nfs-root-name/proc/sys/kernel/nfs-root-addrsreal-root-dev can be changed by writing the number of the new root FSdevice to it, e.g.# echo 0x301 >/proc/sys/kernel/real-root-devfor /dev/hda1. When using an NFS-mounted root, nfs-root-name andnfs-root-addrs have to be set accordingly and then real-root-dev has tobe set to 0xff, e.g.# echo /var/nfsroot >/proc/sys/kernel/nfs-root-name# echo 193.8.232.2:193.8.232.7::255.255.255.0:idefix \>/proc/sys/kernel/nfs-root-addrs# echo 255 >/proc/sys/kernel/real-root-devIf the root device is set to the RAM disk, the root file system is notmoved to /initrd, but the boot procedure is simply continued by startinginit on the initial RAM disk.Usage scenarios---------------The main motivation for implementing initrd was to allow for modularkernel configuration at system installation. The procedure would workas follows:1) systems boots from floppy or other media with a minimal kernel(e.g. support for RAM disks, initrd, a.out, and the ext2 FS) andloads initrd2) /linuxrc determines what is needed to (1) mount the "real" root FS(i.e. device type, device drivers, file system) and (2) thedistribution media (e.g. CD-ROM, network, tape, ...). This can bedone by asking the user, by auto-probing, or by using a hybridapproach.3) /linuxrc loads the necessary modules4) /linuxrc creates and populates the root file system (this doesn'thave to be a very usable system yet)5) /linuxrc unmounts the root file system and possibly any other filesystems it has mounted, sets /proc/sys/kernel/..., and terminates6) the root file system is mounted7) now that we're sure that the file system is accessible and intact,the boot loader can be installed8) the boot loader is configured to load an initrd with the set ofmodules that was used to bring up the system (e.g. /initrd can bemodified, then unmounted, and finally, the image is written from/dev/ram to a file)9) now the system is bootable and additional installation tasks can beperformedThe key role of initrd here is to re-use the configuration data duringnormal system operation without requiring the use of a bloated "generic"kernel or re-compilation or re-linking of the kernel.A second scenario is for installations where Linux runs on systems withdifferent hardware configurations in a single administrative domain. Insuch cases, it is desirable to generate only a small set of kernels(ideally only one) and to keep the system-specific part of configurationinformation as small as possible. In this case, a common initrd could begenerated with all the necessary modules. Then, only /linuxrc or a fileread by it would have to be different.A third scenario are more convenient recovery disks, because informationlike the location of the root FS partition doesn't have to be provided atboot time, but the system loaded from initrd can use a user-friendlydialog and it can also perform some sanity checks (or even some form ofauto-detection).Last not least, CDrom distributors may use it for better installation from CD,either using a LILO boot floppy and bootstrapping a bigger ramdisk viainitrd from CD, or using LOADLIN to directly load the ramdisk from CDwithout need of floppies.Since initrd is a fairly generic mechanism, it is likely that additionaluses will be found.Resources---------The bzImage+initrd patch (bzImage is an extension to load kernels directlyabove 1 MB, which allows kernels sizes of up to approximately 2 MB) can befound atftp://lrcftp.epfl.ch/pub/people/almesber/lilo/bzImage+initrd-1.3.71.patch.gzandftp://elserv.ffm.fgan.de/pub/linux/loadlin-1.6/bzImage+initrd-1.3.71.patch.gzA preliminary version of LOADLIN 1.6 is available onftp://elserv.ffm.fgan.de/pub/linux/loadlin-1.6/loadlin-1.6-pre8-bin.tgzA preliminary version of LILO 18 is available onftp://lrcftp.epfl.ch/pub/people/almesber/lilo/lilo.18dev3.tar.gzA very simple example for building an image for initrd, also includingthe program 'freeramdisk', can be found onftp://elserv.ffm.fgan.de/pub/linux/loadlin-1.6/initrd-example.tgz
