ia64/linux-2.6.18-xen.hg

annotate Documentation/initrd.txt @ 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents 831230e53067
children
rev   line source
ian@0 1 Using the initial RAM disk (initrd)
ian@0 2 ===================================
ian@0 3
ian@0 4 Written 1996,2000 by Werner Almesberger <werner.almesberger@epfl.ch> and
ian@0 5 Hans Lermen <lermen@fgan.de>
ian@0 6
ian@0 7
ian@0 8 initrd provides the capability to load a RAM disk by the boot loader.
ian@0 9 This RAM disk can then be mounted as the root file system and programs
ian@0 10 can be run from it. Afterwards, a new root file system can be mounted
ian@0 11 from a different device. The previous root (from initrd) is then moved
ian@0 12 to a directory and can be subsequently unmounted.
ian@0 13
ian@0 14 initrd is mainly designed to allow system startup to occur in two phases,
ian@0 15 where the kernel comes up with a minimum set of compiled-in drivers, and
ian@0 16 where additional modules are loaded from initrd.
ian@0 17
ian@0 18 This document gives a brief overview of the use of initrd. A more detailed
ian@0 19 discussion of the boot process can be found in [1].
ian@0 20
ian@0 21
ian@0 22 Operation
ian@0 23 ---------
ian@0 24
ian@0 25 When using initrd, the system typically boots as follows:
ian@0 26
ian@0 27 1) the boot loader loads the kernel and the initial RAM disk
ian@0 28 2) the kernel converts initrd into a "normal" RAM disk and
ian@0 29 frees the memory used by initrd
ian@0 30 3) initrd is mounted read-write as root
ian@0 31 4) /linuxrc is executed (this can be any valid executable, including
ian@0 32 shell scripts; it is run with uid 0 and can do basically everything
ian@0 33 init can do)
ian@0 34 5) linuxrc mounts the "real" root file system
ian@0 35 6) linuxrc places the root file system at the root directory using the
ian@0 36 pivot_root system call
ian@0 37 7) the usual boot sequence (e.g. invocation of /sbin/init) is performed
ian@0 38 on the root file system
ian@0 39 8) the initrd file system is removed
ian@0 40
ian@0 41 Note that changing the root directory does not involve unmounting it.
ian@0 42 It is therefore possible to leave processes running on initrd during that
ian@0 43 procedure. Also note that file systems mounted under initrd continue to
ian@0 44 be accessible.
ian@0 45
ian@0 46
ian@0 47 Boot command-line options
ian@0 48 -------------------------
ian@0 49
ian@0 50 initrd adds the following new options:
ian@0 51
ian@0 52 initrd=<path> (e.g. LOADLIN)
ian@0 53
ian@0 54 Loads the specified file as the initial RAM disk. When using LILO, you
ian@0 55 have to specify the RAM disk image file in /etc/lilo.conf, using the
ian@0 56 INITRD configuration variable.
ian@0 57
ian@0 58 noinitrd
ian@0 59
ian@0 60 initrd data is preserved but it is not converted to a RAM disk and
ian@0 61 the "normal" root file system is mounted. initrd data can be read
ian@0 62 from /dev/initrd. Note that the data in initrd can have any structure
ian@0 63 in this case and doesn't necessarily have to be a file system image.
ian@0 64 This option is used mainly for debugging.
ian@0 65
ian@0 66 Note: /dev/initrd is read-only and it can only be used once. As soon
ian@0 67 as the last process has closed it, all data is freed and /dev/initrd
ian@0 68 can't be opened anymore.
ian@0 69
ian@0 70 root=/dev/ram0
ian@0 71
ian@0 72 initrd is mounted as root, and the normal boot procedure is followed,
ian@0 73 with the RAM disk still mounted as root.
ian@0 74
ian@0 75 Compressed cpio images
ian@0 76 ----------------------
ian@0 77
ian@0 78 Recent kernels have support for populating a ramdisk from a compressed cpio
ian@0 79 archive, on such systems, the creation of a ramdisk image doesn't need to
ian@0 80 involve special block devices or loopbacks, you merely create a directory on
ian@0 81 disk with the desired initrd content, cd to that directory, and run (as an
ian@0 82 example):
ian@0 83
ian@0 84 find . | cpio --quiet -c -o | gzip -9 -n > /boot/imagefile.img
ian@0 85
ian@0 86 Examining the contents of an existing image file is just as simple:
ian@0 87
ian@0 88 mkdir /tmp/imagefile
ian@0 89 cd /tmp/imagefile
ian@0 90 gzip -cd /boot/imagefile.img | cpio -imd --quiet
ian@0 91
ian@0 92 Installation
ian@0 93 ------------
ian@0 94
ian@0 95 First, a directory for the initrd file system has to be created on the
ian@0 96 "normal" root file system, e.g.
ian@0 97
ian@0 98 # mkdir /initrd
ian@0 99
ian@0 100 The name is not relevant. More details can be found on the pivot_root(2)
ian@0 101 man page.
ian@0 102
ian@0 103 If the root file system is created during the boot procedure (i.e. if
ian@0 104 you're building an install floppy), the root file system creation
ian@0 105 procedure should create the /initrd directory.
ian@0 106
ian@0 107 If initrd will not be mounted in some cases, its content is still
ian@0 108 accessible if the following device has been created:
ian@0 109
ian@0 110 # mknod /dev/initrd b 1 250
ian@0 111 # chmod 400 /dev/initrd
ian@0 112
ian@0 113 Second, the kernel has to be compiled with RAM disk support and with
ian@0 114 support for the initial RAM disk enabled. Also, at least all components
ian@0 115 needed to execute programs from initrd (e.g. executable format and file
ian@0 116 system) must be compiled into the kernel.
ian@0 117
ian@0 118 Third, you have to create the RAM disk image. This is done by creating a
ian@0 119 file system on a block device, copying files to it as needed, and then
ian@0 120 copying the content of the block device to the initrd file. With recent
ian@0 121 kernels, at least three types of devices are suitable for that:
ian@0 122
ian@0 123 - a floppy disk (works everywhere but it's painfully slow)
ian@0 124 - a RAM disk (fast, but allocates physical memory)
ian@0 125 - a loopback device (the most elegant solution)
ian@0 126
ian@0 127 We'll describe the loopback device method:
ian@0 128
ian@0 129 1) make sure loopback block devices are configured into the kernel
ian@0 130 2) create an empty file system of the appropriate size, e.g.
ian@0 131 # dd if=/dev/zero of=initrd bs=300k count=1
ian@0 132 # mke2fs -F -m0 initrd
ian@0 133 (if space is critical, you may want to use the Minix FS instead of Ext2)
ian@0 134 3) mount the file system, e.g.
ian@0 135 # mount -t ext2 -o loop initrd /mnt
ian@0 136 4) create the console device:
ian@0 137 # mkdir /mnt/dev
ian@0 138 # mknod /mnt/dev/console c 5 1
ian@0 139 5) copy all the files that are needed to properly use the initrd
ian@0 140 environment. Don't forget the most important file, /linuxrc
ian@0 141 Note that /linuxrc's permissions must include "x" (execute).
ian@0 142 6) correct operation the initrd environment can frequently be tested
ian@0 143 even without rebooting with the command
ian@0 144 # chroot /mnt /linuxrc
ian@0 145 This is of course limited to initrds that do not interfere with the
ian@0 146 general system state (e.g. by reconfiguring network interfaces,
ian@0 147 overwriting mounted devices, trying to start already running demons,
ian@0 148 etc. Note however that it is usually possible to use pivot_root in
ian@0 149 such a chroot'ed initrd environment.)
ian@0 150 7) unmount the file system
ian@0 151 # umount /mnt
ian@0 152 8) the initrd is now in the file "initrd". Optionally, it can now be
ian@0 153 compressed
ian@0 154 # gzip -9 initrd
ian@0 155
ian@0 156 For experimenting with initrd, you may want to take a rescue floppy and
ian@0 157 only add a symbolic link from /linuxrc to /bin/sh. Alternatively, you
ian@0 158 can try the experimental newlib environment [2] to create a small
ian@0 159 initrd.
ian@0 160
ian@0 161 Finally, you have to boot the kernel and load initrd. Almost all Linux
ian@0 162 boot loaders support initrd. Since the boot process is still compatible
ian@0 163 with an older mechanism, the following boot command line parameters
ian@0 164 have to be given:
ian@0 165
ian@0 166 root=/dev/ram0 init=/linuxrc rw
ian@0 167
ian@0 168 (rw is only necessary if writing to the initrd file system.)
ian@0 169
ian@0 170 With LOADLIN, you simply execute
ian@0 171
ian@0 172 LOADLIN <kernel> initrd=<disk_image>
ian@0 173 e.g. LOADLIN C:\LINUX\BZIMAGE initrd=C:\LINUX\INITRD.GZ root=/dev/ram0
ian@0 174 init=/linuxrc rw
ian@0 175
ian@0 176 With LILO, you add the option INITRD=<path> to either the global section
ian@0 177 or to the section of the respective kernel in /etc/lilo.conf, and pass
ian@0 178 the options using APPEND, e.g.
ian@0 179
ian@0 180 image = /bzImage
ian@0 181 initrd = /boot/initrd.gz
ian@0 182 append = "root=/dev/ram0 init=/linuxrc rw"
ian@0 183
ian@0 184 and run /sbin/lilo
ian@0 185
ian@0 186 For other boot loaders, please refer to the respective documentation.
ian@0 187
ian@0 188 Now you can boot and enjoy using initrd.
ian@0 189
ian@0 190
ian@0 191 Changing the root device
ian@0 192 ------------------------
ian@0 193
ian@0 194 When finished with its duties, linuxrc typically changes the root device
ian@0 195 and proceeds with starting the Linux system on the "real" root device.
ian@0 196
ian@0 197 The procedure involves the following steps:
ian@0 198 - mounting the new root file system
ian@0 199 - turning it into the root file system
ian@0 200 - removing all accesses to the old (initrd) root file system
ian@0 201 - unmounting the initrd file system and de-allocating the RAM disk
ian@0 202
ian@0 203 Mounting the new root file system is easy: it just needs to be mounted on
ian@0 204 a directory under the current root. Example:
ian@0 205
ian@0 206 # mkdir /new-root
ian@0 207 # mount -o ro /dev/hda1 /new-root
ian@0 208
ian@0 209 The root change is accomplished with the pivot_root system call, which
ian@0 210 is also available via the pivot_root utility (see pivot_root(8) man
ian@0 211 page; pivot_root is distributed with util-linux version 2.10h or higher
ian@0 212 [3]). pivot_root moves the current root to a directory under the new
ian@0 213 root, and puts the new root at its place. The directory for the old root
ian@0 214 must exist before calling pivot_root. Example:
ian@0 215
ian@0 216 # cd /new-root
ian@0 217 # mkdir initrd
ian@0 218 # pivot_root . initrd
ian@0 219
ian@0 220 Now, the linuxrc process may still access the old root via its
ian@0 221 executable, shared libraries, standard input/output/error, and its
ian@0 222 current root directory. All these references are dropped by the
ian@0 223 following command:
ian@0 224
ian@0 225 # exec chroot . what-follows <dev/console >dev/console 2>&1
ian@0 226
ian@0 227 Where what-follows is a program under the new root, e.g. /sbin/init
ian@0 228 If the new root file system will be used with udev and has no valid
ian@0 229 /dev directory, udev must be initialized before invoking chroot in order
ian@0 230 to provide /dev/console.
ian@0 231
ian@0 232 Note: implementation details of pivot_root may change with time. In order
ian@0 233 to ensure compatibility, the following points should be observed:
ian@0 234
ian@0 235 - before calling pivot_root, the current directory of the invoking
ian@0 236 process should point to the new root directory
ian@0 237 - use . as the first argument, and the _relative_ path of the directory
ian@0 238 for the old root as the second argument
ian@0 239 - a chroot program must be available under the old and the new root
ian@0 240 - chroot to the new root afterwards
ian@0 241 - use relative paths for dev/console in the exec command
ian@0 242
ian@0 243 Now, the initrd can be unmounted and the memory allocated by the RAM
ian@0 244 disk can be freed:
ian@0 245
ian@0 246 # umount /initrd
ian@0 247 # blockdev --flushbufs /dev/ram0
ian@0 248
ian@0 249 It is also possible to use initrd with an NFS-mounted root, see the
ian@0 250 pivot_root(8) man page for details.
ian@0 251
ian@0 252 Note: if linuxrc or any program exec'ed from it terminates for some
ian@0 253 reason, the old change_root mechanism is invoked (see section "Obsolete
ian@0 254 root change mechanism").
ian@0 255
ian@0 256
ian@0 257 Usage scenarios
ian@0 258 ---------------
ian@0 259
ian@0 260 The main motivation for implementing initrd was to allow for modular
ian@0 261 kernel configuration at system installation. The procedure would work
ian@0 262 as follows:
ian@0 263
ian@0 264 1) system boots from floppy or other media with a minimal kernel
ian@0 265 (e.g. support for RAM disks, initrd, a.out, and the Ext2 FS) and
ian@0 266 loads initrd
ian@0 267 2) /linuxrc determines what is needed to (1) mount the "real" root FS
ian@0 268 (i.e. device type, device drivers, file system) and (2) the
ian@0 269 distribution media (e.g. CD-ROM, network, tape, ...). This can be
ian@0 270 done by asking the user, by auto-probing, or by using a hybrid
ian@0 271 approach.
ian@0 272 3) /linuxrc loads the necessary kernel modules
ian@0 273 4) /linuxrc creates and populates the root file system (this doesn't
ian@0 274 have to be a very usable system yet)
ian@0 275 5) /linuxrc invokes pivot_root to change the root file system and
ian@0 276 execs - via chroot - a program that continues the installation
ian@0 277 6) the boot loader is installed
ian@0 278 7) the boot loader is configured to load an initrd with the set of
ian@0 279 modules that was used to bring up the system (e.g. /initrd can be
ian@0 280 modified, then unmounted, and finally, the image is written from
ian@0 281 /dev/ram0 or /dev/rd/0 to a file)
ian@0 282 8) now the system is bootable and additional installation tasks can be
ian@0 283 performed
ian@0 284
ian@0 285 The key role of initrd here is to re-use the configuration data during
ian@0 286 normal system operation without requiring the use of a bloated "generic"
ian@0 287 kernel or re-compiling or re-linking the kernel.
ian@0 288
ian@0 289 A second scenario is for installations where Linux runs on systems with
ian@0 290 different hardware configurations in a single administrative domain. In
ian@0 291 such cases, it is desirable to generate only a small set of kernels
ian@0 292 (ideally only one) and to keep the system-specific part of configuration
ian@0 293 information as small as possible. In this case, a common initrd could be
ian@0 294 generated with all the necessary modules. Then, only /linuxrc or a file
ian@0 295 read by it would have to be different.
ian@0 296
ian@0 297 A third scenario are more convenient recovery disks, because information
ian@0 298 like the location of the root FS partition doesn't have to be provided at
ian@0 299 boot time, but the system loaded from initrd can invoke a user-friendly
ian@0 300 dialog and it can also perform some sanity checks (or even some form of
ian@0 301 auto-detection).
ian@0 302
ian@0 303 Last not least, CD-ROM distributors may use it for better installation
ian@0 304 from CD, e.g. by using a boot floppy and bootstrapping a bigger RAM disk
ian@0 305 via initrd from CD; or by booting via a loader like LOADLIN or directly
ian@0 306 from the CD-ROM, and loading the RAM disk from CD without need of
ian@0 307 floppies.
ian@0 308
ian@0 309
ian@0 310 Obsolete root change mechanism
ian@0 311 ------------------------------
ian@0 312
ian@0 313 The following mechanism was used before the introduction of pivot_root.
ian@0 314 Current kernels still support it, but you should _not_ rely on its
ian@0 315 continued availability.
ian@0 316
ian@0 317 It works by mounting the "real" root device (i.e. the one set with rdev
ian@0 318 in the kernel image or with root=... at the boot command line) as the
ian@0 319 root file system when linuxrc exits. The initrd file system is then
ian@0 320 unmounted, or, if it is still busy, moved to a directory /initrd, if
ian@0 321 such a directory exists on the new root file system.
ian@0 322
ian@0 323 In order to use this mechanism, you do not have to specify the boot
ian@0 324 command options root, init, or rw. (If specified, they will affect
ian@0 325 the real root file system, not the initrd environment.)
ian@0 326
ian@0 327 If /proc is mounted, the "real" root device can be changed from within
ian@0 328 linuxrc by writing the number of the new root FS device to the special
ian@0 329 file /proc/sys/kernel/real-root-dev, e.g.
ian@0 330
ian@0 331 # echo 0x301 >/proc/sys/kernel/real-root-dev
ian@0 332
ian@0 333 Note that the mechanism is incompatible with NFS and similar file
ian@0 334 systems.
ian@0 335
ian@0 336 This old, deprecated mechanism is commonly called "change_root", while
ian@0 337 the new, supported mechanism is called "pivot_root".
ian@0 338
ian@0 339
ian@0 340 Resources
ian@0 341 ---------
ian@0 342
ian@0 343 [1] Almesberger, Werner; "Booting Linux: The History and the Future"
ian@0 344 http://www.almesberger.net/cv/papers/ols2k-9.ps.gz
ian@0 345 [2] newlib package (experimental), with initrd example
ian@0 346 http://sources.redhat.com/newlib/
ian@0 347 [3] Brouwer, Andries; "util-linux: Miscellaneous utilities for Linux"
ian@0 348 ftp://ftp.win.tue.nl/pub/linux-local/utils/util-linux/