[a32a241] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
[5632009] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
[a42ba00] | 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
[5632009] | 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
| 8 | <sect1 id="initramfs">
|
---|
| 9 | <?dbhtml filename="initramfs.html"?>
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | <title>About initramfs</title>
|
---|
| 13 |
|
---|
[29244b7] | 14 | <para>
|
---|
| 15 | The only purpose of an initramfs is to mount the root filesystem. The
|
---|
| 16 | initramfs is a complete set of directories that you would find on a normal
|
---|
| 17 | root filesystem. It is bundled into a single cpio archive and compressed
|
---|
| 18 | with one of several compression algorithms.
|
---|
| 19 | </para>
|
---|
| 20 |
|
---|
| 21 | <para>
|
---|
| 22 | At boot time, the boot loader loads the kernel and the initramfs image
|
---|
| 23 | into memory and starts the kernel. The kernel checks for the presence
|
---|
| 24 | of the initramfs and, if found, mounts it as / and runs /init. The init
|
---|
| 25 | program is typically a shell script. Note that the boot process takes
|
---|
| 26 | longer, possibly significantly longer, if an initramfs is used.
|
---|
| 27 | </para>
|
---|
| 28 |
|
---|
| 29 | <para>
|
---|
| 30 | For most distributions, kernel modules are the biggest reason to have
|
---|
| 31 | an initramfs. In a general distribution, there are many unknowns such
|
---|
| 32 | as file system types and disk layouts. In a way, this is the opposite
|
---|
| 33 | of LFS where the system capabilities and layout are known and a custom
|
---|
| 34 | kernel is normally built. In this situation, an initramfs is rarely
|
---|
| 35 | needed.
|
---|
| 36 | </para>
|
---|
| 37 |
|
---|
| 38 | <para>
|
---|
| 39 | There are only four primary reasons to have an initramfs in the LFS
|
---|
| 40 | environment: loading the rootfs from a network, loading it from an LVM
|
---|
| 41 | logical volume, having an encrypted rootfs where a password is required, or
|
---|
| 42 | for the convenience of specifying the rootfs as a LABEL or UUID. Anything
|
---|
| 43 | else usually means that the kernel was not configured properly.
|
---|
| 44 | </para>
|
---|
[5632009] | 45 |
|
---|
| 46 | <sect2 id="initramfs-build">
|
---|
| 47 | <title>Building an initramfs</title>
|
---|
| 48 |
|
---|
[29244b7] | 49 | <para>
|
---|
| 50 | If you do decide to build an initramfs, the following scripts will
|
---|
| 51 | provide a basis to do it. The scripts will allow specifying a rootfs
|
---|
| 52 | via partition UUID or partition LABEL or a rootfs on an LVM logical
|
---|
| 53 | volume. They do not support an encrypted root file system or mounting
|
---|
| 54 | the rootfs over a network card. For a more complete capability see
|
---|
[c9aa980] | 55 | <ulink url="https://www.linuxfromscratch.org/hints/read.html"> the LFS
|
---|
[29244b7] | 56 | Hints</ulink> or <ulink
|
---|
[cd29bc9] | 57 | url="https://fedoraproject.org/wiki/Dracut">dracut</ulink>.
|
---|
[29244b7] | 58 | </para>
|
---|
[5632009] | 59 |
|
---|
[29244b7] | 60 | <para>
|
---|
| 61 | To install these scripts, run the following commands as the
|
---|
| 62 | <systemitem class="username">root</systemitem> user:
|
---|
| 63 | </para>
|
---|
[5632009] | 64 |
|
---|
[5804e5f] | 65 | <screen role="root"><userinput>cat > /usr/sbin/mkinitramfs << "EOF"
|
---|
[51dfb3e] | 66 | <literal>#!/bin/bash
|
---|
[fe58aa0] | 67 | # This file based in part on the mkinitramfs script for the LFS LiveCD
|
---|
[5632009] | 68 | # written by Alexander E. Patrakov and Jeremy Huntwork.
|
---|
| 69 |
|
---|
| 70 | copy()
|
---|
| 71 | {
|
---|
| 72 | local file
|
---|
| 73 |
|
---|
[6c183b56] | 74 | if [ "$2" = "lib" ]; then
|
---|
[5804e5f] | 75 | file=$(PATH=/usr/lib type -p $1)
|
---|
[5632009] | 76 | else
|
---|
[99ff4fad] | 77 | file=$(type -p $1)
|
---|
[5632009] | 78 | fi
|
---|
| 79 |
|
---|
[6e493187] | 80 | if [ -n "$file" ] ; then
|
---|
[5804e5f] | 81 | cp $file $WDIR/usr/$2
|
---|
[5632009] | 82 | else
|
---|
| 83 | echo "Missing required file: $1 for directory $2"
|
---|
| 84 | rm -rf $WDIR
|
---|
| 85 | exit 1
|
---|
| 86 | fi
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | if [ -z $1 ] ; then
|
---|
| 90 | INITRAMFS_FILE=initrd.img-no-kmods
|
---|
| 91 | else
|
---|
| 92 | KERNEL_VERSION=$1
|
---|
| 93 | INITRAMFS_FILE=initrd.img-$KERNEL_VERSION
|
---|
| 94 | fi
|
---|
| 95 |
|
---|
[5804e5f] | 96 | if [ -n "$KERNEL_VERSION" ] && [ ! -d "/usr/lib/modules/$1" ] ; then
|
---|
[5632009] | 97 | echo "No modules directory named $1"
|
---|
| 98 | exit 1
|
---|
| 99 | fi
|
---|
| 100 |
|
---|
| 101 | printf "Creating $INITRAMFS_FILE... "
|
---|
| 102 |
|
---|
[90c6607] | 103 | binfiles="sh cat cp dd killall ls mkdir mknod mount "
|
---|
[5632009] | 104 | binfiles="$binfiles umount sed sleep ln rm uname"
|
---|
[8b6d8b6] | 105 | binfiles="$binfiles readlink basename"
|
---|
[5632009] | 106 |
|
---|
[f350508] | 107 | # Systemd installs udevadm in /bin. Other udev implementations have it in /sbin
|
---|
[5804e5f] | 108 | if [ -x /usr/bin/udevadm ] ; then binfiles="$binfiles udevadm"; fi
|
---|
[f350508] | 109 |
|
---|
| 110 | sbinfiles="modprobe blkid switch_root"
|
---|
[90c6607] | 111 |
|
---|
[5804e5f] | 112 | # Optional files and locations
|
---|
[f8f7442] | 113 | for f in mdadm mdmon udevd udevadm; do
|
---|
[5804e5f] | 114 | if [ -x /usr/sbin/$f ] ; then sbinfiles="$sbinfiles $f"; fi
|
---|
[8253f9fc] | 115 | done
|
---|
[5632009] | 116 |
|
---|
[288c825] | 117 | # Add lvm if present (cannot be done with the others because it
|
---|
| 118 | # also needs dmsetup
|
---|
[5804e5f] | 119 | if [ -x /usr/sbin/lvm ] ; then sbinfiles="$sbinfiles lvm dmsetup"; fi
|
---|
[288c825] | 120 |
|
---|
[5632009] | 121 | unsorted=$(mktemp /tmp/unsorted.XXXXXXXXXX)
|
---|
| 122 |
|
---|
| 123 | DATADIR=/usr/share/mkinitramfs
|
---|
| 124 | INITIN=init.in
|
---|
| 125 |
|
---|
[f8f7442] | 126 | # Create a temporary working directory
|
---|
[5632009] | 127 | WDIR=$(mktemp -d /tmp/initrd-work.XXXXXXXXXX)
|
---|
| 128 |
|
---|
| 129 | # Create base directory structure
|
---|
[5804e5f] | 130 | mkdir -p $WDIR/{dev,run,sys,proc,usr/{bin,lib/{firmware,modules},sbin}}
|
---|
[5632009] | 131 | mkdir -p $WDIR/etc/{modprobe.d,udev/rules.d}
|
---|
| 132 | touch $WDIR/etc/modprobe.d/modprobe.conf
|
---|
[5804e5f] | 133 | ln -s usr/bin $WDIR/bin
|
---|
| 134 | ln -s usr/lib $WDIR/lib
|
---|
| 135 | ln -s usr/sbin $WDIR/sbin
|
---|
| 136 | ln -s lib $WDIR/lib64
|
---|
[5632009] | 137 |
|
---|
| 138 | # Create necessary device nodes
|
---|
| 139 | mknod -m 640 $WDIR/dev/console c 5 1
|
---|
| 140 | mknod -m 664 $WDIR/dev/null c 1 3
|
---|
| 141 |
|
---|
| 142 | # Install the udev configuration files
|
---|
[50f410f] | 143 | if [ -f /etc/udev/udev.conf ]; then
|
---|
| 144 | cp /etc/udev/udev.conf $WDIR/etc/udev/udev.conf
|
---|
| 145 | fi
|
---|
[5632009] | 146 |
|
---|
| 147 | for file in $(find /etc/udev/rules.d/ -type f) ; do
|
---|
| 148 | cp $file $WDIR/etc/udev/rules.d
|
---|
| 149 | done
|
---|
| 150 |
|
---|
[a32a241] | 151 | # Install any firmware present
|
---|
[5804e5f] | 152 | cp -a /usr/lib/firmware $WDIR/usr/lib
|
---|
[a32a241] | 153 |
|
---|
[f350508] | 154 | # Copy the RAID configuration file if present
|
---|
[5632009] | 155 | if [ -f /etc/mdadm.conf ] ; then
|
---|
| 156 | cp /etc/mdadm.conf $WDIR/etc
|
---|
| 157 | fi
|
---|
| 158 |
|
---|
| 159 | # Install the init file
|
---|
| 160 | install -m0755 $DATADIR/$INITIN $WDIR/init
|
---|
| 161 |
|
---|
[ea8a884] | 162 | if [ -n "$KERNEL_VERSION" ] ; then
|
---|
[5804e5f] | 163 | if [ -x /usr/bin/kmod ] ; then
|
---|
[ea8a884] | 164 | binfiles="$binfiles kmod"
|
---|
| 165 | else
|
---|
| 166 | binfiles="$binfiles lsmod"
|
---|
[64cb61a] | 167 | sbinfiles="$sbinfiles insmod"
|
---|
[ea8a884] | 168 | fi
|
---|
| 169 | fi
|
---|
| 170 |
|
---|
[5632009] | 171 | # Install basic binaries
|
---|
| 172 | for f in $binfiles ; do
|
---|
[5804e5f] | 173 | ldd /usr/bin/$f | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
---|
| 174 | copy /usr/bin/$f bin
|
---|
[5632009] | 175 | done
|
---|
| 176 |
|
---|
| 177 | for f in $sbinfiles ; do
|
---|
[5804e5f] | 178 | ldd /usr/sbin/$f | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
---|
[5632009] | 179 | copy $f sbin
|
---|
| 180 | done
|
---|
| 181 |
|
---|
[5804e5f] | 182 | # Add udevd libraries if not in /usr/sbin
|
---|
| 183 | if [ -x /usr/lib/udev/udevd ] ; then
|
---|
| 184 | ldd /usr/lib/udev/udevd | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
---|
| 185 | elif [ -x /usr/lib/systemd/systemd-udevd ] ; then
|
---|
| 186 | ldd /usr/lib/systemd/systemd-udevd | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
---|
[8253f9fc] | 187 | fi
|
---|
| 188 |
|
---|
[ea8a884] | 189 | # Add module symlinks if appropriate
|
---|
[5804e5f] | 190 | if [ -n "$KERNEL_VERSION" ] && [ -x /usr/bin/kmod ] ; then
|
---|
| 191 | ln -s kmod $WDIR/usr/bin/lsmod
|
---|
| 192 | ln -s kmod $WDIR/usr/bin/insmod
|
---|
[ea8a884] | 193 | fi
|
---|
| 194 |
|
---|
[5632009] | 195 | # Add lvm symlinks if appropriate
|
---|
[50f410f] | 196 | # Also copy the lvm.conf file
|
---|
[5804e5f] | 197 | if [ -x /usr/sbin/lvm ] ; then
|
---|
| 198 | ln -s lvm $WDIR/usr/sbin/lvchange
|
---|
| 199 | ln -s lvm $WDIR/usr/sbin/lvrename
|
---|
| 200 | ln -s lvm $WDIR/usr/sbin/lvextend
|
---|
| 201 | ln -s lvm $WDIR/usr/sbin/lvcreate
|
---|
| 202 | ln -s lvm $WDIR/usr/sbin/lvdisplay
|
---|
| 203 | ln -s lvm $WDIR/usr/sbin/lvscan
|
---|
| 204 |
|
---|
| 205 | ln -s lvm $WDIR/usr/sbin/pvchange
|
---|
| 206 | ln -s lvm $WDIR/usr/sbin/pvck
|
---|
| 207 | ln -s lvm $WDIR/usr/sbin/pvcreate
|
---|
| 208 | ln -s lvm $WDIR/usr/sbin/pvdisplay
|
---|
| 209 | ln -s lvm $WDIR/usr/sbin/pvscan
|
---|
| 210 |
|
---|
| 211 | ln -s lvm $WDIR/usr/sbin/vgchange
|
---|
| 212 | ln -s lvm $WDIR/usr/sbin/vgcreate
|
---|
| 213 | ln -s lvm $WDIR/usr/sbin/vgscan
|
---|
| 214 | ln -s lvm $WDIR/usr/sbin/vgrename
|
---|
| 215 | ln -s lvm $WDIR/usr/sbin/vgck
|
---|
[50f410f] | 216 | # Conf file(s)
|
---|
| 217 | cp -a /etc/lvm $WDIR/etc
|
---|
[5632009] | 218 | fi
|
---|
| 219 |
|
---|
| 220 | # Install libraries
|
---|
[8253f9fc] | 221 | sort $unsorted | uniq | while read library ; do
|
---|
[6e493187] | 222 | # linux-vdso and linux-gate are pseudo libraries and do not correspond to a file
|
---|
| 223 | # libsystemd-shared is in /lib/systemd, so it is not found by copy, and
|
---|
| 224 | # it is copied below anyway
|
---|
| 225 | if [[ "$library" == linux-vdso.so.1 ]] ||
|
---|
| 226 | [[ "$library" == linux-gate.so.1 ]] ||
|
---|
| 227 | [[ "$library" == libsystemd-shared* ]]; then
|
---|
[5632009] | 228 | continue
|
---|
| 229 | fi
|
---|
| 230 |
|
---|
| 231 | copy $library lib
|
---|
| 232 | done
|
---|
| 233 |
|
---|
[5804e5f] | 234 | if [ -d /usr/lib/udev ]; then
|
---|
| 235 | cp -a /usr/lib/udev $WDIR/usr/lib
|
---|
[f350508] | 236 | fi
|
---|
[5804e5f] | 237 | if [ -d /usr/lib/systemd ]; then
|
---|
| 238 | cp -a /usr/lib/systemd $WDIR/usr/lib
|
---|
[f350508] | 239 | fi
|
---|
[5804e5f] | 240 | if [ -d /usr/lib/elogind ]; then
|
---|
| 241 | cp -a /usr/lib/elogind $WDIR/usr/lib
|
---|
[2f6d8ec] | 242 | fi
|
---|
[5632009] | 243 |
|
---|
| 244 | # Install the kernel modules if requested
|
---|
| 245 | if [ -n "$KERNEL_VERSION" ]; then
|
---|
[889d6c4] | 246 | find \
|
---|
[5804e5f] | 247 | /usr/lib/modules/$KERNEL_VERSION/kernel/{crypto,fs,lib} \
|
---|
[889d6c4] | 248 | /usr/lib/modules/$KERNEL_VERSION/kernel/drivers/{block,ata,nvme,md,firewire} \
|
---|
[5804e5f] | 249 | /usr/lib/modules/$KERNEL_VERSION/kernel/drivers/{scsi,message,pcmcia,virtio} \
|
---|
| 250 | /usr/lib/modules/$KERNEL_VERSION/kernel/drivers/usb/{host,storage} \
|
---|
[5632009] | 251 | -type f 2> /dev/null | cpio --make-directories -p --quiet $WDIR
|
---|
| 252 |
|
---|
[889d6c4] | 253 | cp /usr/lib/modules/$KERNEL_VERSION/modules.{builtin,order} \
|
---|
[5804e5f] | 254 | $WDIR/usr/lib/modules/$KERNEL_VERSION
|
---|
[889d6c4] | 255 | if [ -f /usr/lib/modules/$KERNEL_VERSION/modules.builtin.modinfo ]; then
|
---|
| 256 | cp /usr/lib/modules/$KERNEL_VERSION/modules.builtin.modinfo \
|
---|
| 257 | $WDIR/usr/lib/modules/$KERNEL_VERSION
|
---|
| 258 | fi
|
---|
[8253f9fc] | 259 |
|
---|
[5632009] | 260 | depmod -b $WDIR $KERNEL_VERSION
|
---|
| 261 | fi
|
---|
| 262 |
|
---|
| 263 | ( cd $WDIR ; find . | cpio -o -H newc --quiet | gzip -9 ) > $INITRAMFS_FILE
|
---|
| 264 |
|
---|
[6e493187] | 265 | # Prepare early loading of microcode if available
|
---|
[5804e5f] | 266 | if ls /usr/lib/firmware/intel-ucode/* >/dev/null 2>&1 ||
|
---|
| 267 | ls /usr/lib/firmware/amd-ucode/* >/dev/null 2>&1; then
|
---|
[6e493187] | 268 |
|
---|
| 269 | # first empty WDIR to reuse it
|
---|
| 270 | rm -r $WDIR/*
|
---|
| 271 |
|
---|
| 272 | DSTDIR=$WDIR/kernel/x86/microcode
|
---|
| 273 | mkdir -p $DSTDIR
|
---|
| 274 |
|
---|
[5804e5f] | 275 | if [ -d /usr/lib/firmware/amd-ucode ]; then
|
---|
| 276 | cat /usr/lib/firmware/amd-ucode/microcode_amd*.bin > $DSTDIR/AuthenticAMD.bin
|
---|
[6e493187] | 277 | fi
|
---|
| 278 |
|
---|
[5804e5f] | 279 | if [ -d /usr/lib/firmware/intel-ucode ]; then
|
---|
| 280 | cat /usr/lib/firmware/intel-ucode/* > $DSTDIR/GenuineIntel.bin
|
---|
[6e493187] | 281 | fi
|
---|
| 282 |
|
---|
| 283 | ( cd $WDIR; find . | cpio -o -H newc --quiet ) > microcode.img
|
---|
| 284 | cat microcode.img $INITRAMFS_FILE > tmpfile
|
---|
| 285 | mv tmpfile $INITRAMFS_FILE
|
---|
| 286 | rm microcode.img
|
---|
| 287 | fi
|
---|
| 288 |
|
---|
| 289 | # Remove the temporary directories and files
|
---|
[5632009] | 290 | rm -rf $WDIR $unsorted
|
---|
| 291 | printf "done.\n"
|
---|
[51dfb3e] | 292 | </literal>
|
---|
[5712a7d] | 293 | EOF
|
---|
| 294 |
|
---|
[5804e5f] | 295 | chmod 0755 /usr/sbin/mkinitramfs</userinput></screen>
|
---|
[0d7900a] | 296 |
|
---|
[5632009] | 297 | <screen role="root"><userinput>mkdir -p /usr/share/mkinitramfs &&
|
---|
| 298 | cat > /usr/share/mkinitramfs/init.in << "EOF"
|
---|
[51dfb3e] | 299 | <literal>#!/bin/sh
|
---|
[5632009] | 300 |
|
---|
[5804e5f] | 301 | PATH=/usr/bin:/usr/sbin
|
---|
[5632009] | 302 | export PATH
|
---|
| 303 |
|
---|
| 304 | problem()
|
---|
| 305 | {
|
---|
| 306 | printf "Encountered a problem!\n\nDropping you to a shell.\n\n"
|
---|
| 307 | sh
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | no_device()
|
---|
| 311 | {
|
---|
| 312 | printf "The device %s, which is supposed to contain the\n" $1
|
---|
| 313 | printf "root file system, does not exist.\n"
|
---|
| 314 | printf "Please fix this problem and exit this shell.\n\n"
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | no_mount()
|
---|
| 318 | {
|
---|
| 319 | printf "Could not mount device %s\n" $1
|
---|
| 320 | printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n"
|
---|
| 321 | printf "Maybe the device is formatted with an unsupported file system?\n\n"
|
---|
| 322 | printf "Or maybe filesystem type autodetection went wrong, in which case\n"
|
---|
| 323 | printf "you should add the rootfstype=... parameter to the kernel command line.\n\n"
|
---|
| 324 | printf "Available partitions:\n"
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | do_mount_root()
|
---|
| 328 | {
|
---|
| 329 | mkdir /.root
|
---|
| 330 | [ -n "$rootflags" ] && rootflags="$rootflags,"
|
---|
| 331 | rootflags="$rootflags$ro"
|
---|
| 332 |
|
---|
| 333 | case "$root" in
|
---|
[99ff4fad] | 334 | /dev/* ) device=$root ;;
|
---|
| 335 | UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID" ;;
|
---|
| 336 | PARTUUID=*) eval $root; device="/dev/disk/by-partuuid/$PARTUUID" ;;
|
---|
| 337 | LABEL=* ) eval $root; device="/dev/disk/by-label/$LABEL" ;;
|
---|
| 338 | "" ) echo "No root device specified." ; problem ;;
|
---|
[5632009] | 339 | esac
|
---|
| 340 |
|
---|
| 341 | while [ ! -b "$device" ] ; do
|
---|
| 342 | no_device $device
|
---|
| 343 | problem
|
---|
| 344 | done
|
---|
| 345 |
|
---|
| 346 | if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then
|
---|
| 347 | no_mount $device
|
---|
| 348 | cat /proc/partitions
|
---|
| 349 | while true ; do sleep 10000 ; done
|
---|
| 350 | else
|
---|
| 351 | echo "Successfully mounted device $root"
|
---|
| 352 | fi
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[2f6d8ec] | 355 | do_try_resume()
|
---|
| 356 | {
|
---|
| 357 | case "$resume" in
|
---|
| 358 | UUID=* ) eval $resume; resume="/dev/disk/by-uuid/$UUID" ;;
|
---|
| 359 | LABEL=*) eval $resume; resume="/dev/disk/by-label/$LABEL" ;;
|
---|
| 360 | esac
|
---|
| 361 |
|
---|
| 362 | if $noresume || ! [ -b "$resume" ]; then return; fi
|
---|
| 363 |
|
---|
| 364 | ls -lH "$resume" | ( read x x x x maj min x
|
---|
| 365 | echo -n ${maj%,}:$min > /sys/power/resume )
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[5632009] | 368 | init=/sbin/init
|
---|
| 369 | root=
|
---|
| 370 | rootdelay=
|
---|
| 371 | rootfstype=auto
|
---|
| 372 | ro="ro"
|
---|
| 373 | rootflags=
|
---|
| 374 | device=
|
---|
[2f6d8ec] | 375 | resume=
|
---|
| 376 | noresume=false
|
---|
[5632009] | 377 |
|
---|
| 378 | mount -n -t devtmpfs devtmpfs /dev
|
---|
[a32a241] | 379 | mount -n -t proc proc /proc
|
---|
| 380 | mount -n -t sysfs sysfs /sys
|
---|
| 381 | mount -n -t tmpfs tmpfs /run
|
---|
[5632009] | 382 |
|
---|
| 383 | read -r cmdline < /proc/cmdline
|
---|
| 384 |
|
---|
| 385 | for param in $cmdline ; do
|
---|
| 386 | case $param in
|
---|
| 387 | init=* ) init=${param#init=} ;;
|
---|
| 388 | root=* ) root=${param#root=} ;;
|
---|
| 389 | rootdelay=* ) rootdelay=${param#rootdelay=} ;;
|
---|
| 390 | rootfstype=*) rootfstype=${param#rootfstype=} ;;
|
---|
| 391 | rootflags=* ) rootflags=${param#rootflags=} ;;
|
---|
[2f6d8ec] | 392 | resume=* ) resume=${param#resume=} ;;
|
---|
| 393 | noresume ) noresume=true ;;
|
---|
[5632009] | 394 | ro ) ro="ro" ;;
|
---|
| 395 | rw ) ro="rw" ;;
|
---|
| 396 | esac
|
---|
| 397 | done
|
---|
| 398 |
|
---|
[8253f9fc] | 399 | # udevd location depends on version
|
---|
| 400 | if [ -x /sbin/udevd ]; then
|
---|
[f350508] | 401 | UDEVD=/sbin/udevd
|
---|
| 402 | elif [ -x /lib/udev/udevd ]; then
|
---|
| 403 | UDEVD=/lib/udev/udevd
|
---|
| 404 | elif [ -x /lib/systemd/systemd-udevd ]; then
|
---|
| 405 | UDEVD=/lib/systemd/systemd-udevd
|
---|
[8253f9fc] | 406 | else
|
---|
[f350508] | 407 | echo "Cannot find udevd nor systemd-udevd"
|
---|
| 408 | problem
|
---|
[8253f9fc] | 409 | fi
|
---|
| 410 |
|
---|
[f350508] | 411 | ${UDEVD} --daemon --resolve-names=never
|
---|
[5632009] | 412 | udevadm trigger
|
---|
| 413 | udevadm settle
|
---|
| 414 |
|
---|
[50f410f] | 415 | if [ -f /etc/mdadm.conf ] ; then mdadm -As ; fi
|
---|
| 416 | if [ -x /sbin/vgchange ] ; then /sbin/vgchange -a y > /dev/null ; fi
|
---|
| 417 | if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi
|
---|
[5632009] | 418 |
|
---|
[2f6d8ec] | 419 | do_try_resume # This function will not return if resuming from disk
|
---|
[5632009] | 420 | do_mount_root
|
---|
| 421 |
|
---|
[f350508] | 422 | killall -w ${UDEVD##*/}
|
---|
[5632009] | 423 |
|
---|
| 424 | exec switch_root /.root "$init" "$@"
|
---|
[51dfb3e] | 425 | </literal>
|
---|
[5632009] | 426 | EOF</userinput></screen>
|
---|
[0d7900a] | 427 |
|
---|
[5632009] | 428 | </sect2>
|
---|
| 429 |
|
---|
| 430 | <sect2 id="initramfs-install">
|
---|
| 431 | <title>Using an initramfs</title>
|
---|
| 432 |
|
---|
[ea8a884] | 433 | <bridgehead renderas="sect3">Required Runtime Dependency</bridgehead>
|
---|
| 434 |
|
---|
| 435 | <para role="required">
|
---|
[96e9478] | 436 | <xref role="runtime" linkend="cpio"/>
|
---|
[ea8a884] | 437 | </para>
|
---|
[20598a7] | 438 |
|
---|
| 439 | <bridgehead renderas="sect3">Other Runtime Dependencies</bridgehead>
|
---|
| 440 |
|
---|
| 441 | <para role="optional">
|
---|
| 442 | <xref role="runtime" linkend="lvm2"/> and/or
|
---|
| 443 | <xref role="runtime" linkend="mdadm"/> must be installed before
|
---|
| 444 | generating the initramfs, if the system partition uses them.
|
---|
| 445 | </para>
|
---|
[ea8a884] | 446 |
|
---|
| 447 |
|
---|
| 448 |
|
---|
[29244b7] | 449 | <para>
|
---|
| 450 | To build an initramfs, run the following as the <systemitem
|
---|
| 451 | class="username">root</systemitem> user:
|
---|
| 452 | </para>
|
---|
[5632009] | 453 |
|
---|
[7b82eb14] | 454 | <screen role="nodump"><userinput>mkinitramfs [KERNEL VERSION]</userinput></screen>
|
---|
[5632009] | 455 |
|
---|
[29244b7] | 456 | <para>
|
---|
| 457 | The optional argument is the directory where the appropriate kernel
|
---|
| 458 | modules are located. This must be a subdirectory of <filename
|
---|
| 459 | class='directory'> /lib/modules</filename>. If no modules are specified,
|
---|
| 460 | then the initramfs is named <emphasis>initrd.img-no-kmods</emphasis>.
|
---|
| 461 | If a kernel version is specified, the initrd is named
|
---|
| 462 | <emphasis>initrd.img-$KERNEL_VERSION</emphasis> and is only appropriate
|
---|
| 463 | for the specific kernel specified. The output file will be placed in the
|
---|
| 464 | current directory.
|
---|
| 465 | </para>
|
---|
[5632009] | 466 |
|
---|
[29244b7] | 467 | <para>
|
---|
| 468 | If early loading of microcode is needed (see <xref
|
---|
| 469 | linkend="cpu-microcode"/>), you can install the appropriate blob or
|
---|
| 470 | container in <filename class="directory">/lib/firmware</filename>.
|
---|
| 471 | It will be automatically added to the initrd when running
|
---|
| 472 | <command>mkinitramfs</command>.
|
---|
| 473 | </para>
|
---|
[6e493187] | 474 |
|
---|
[29244b7] | 475 | <para>
|
---|
| 476 | After generating the initrd, copy it to the <filename
|
---|
| 477 | class='directory'>/boot</filename> directory.
|
---|
| 478 | </para>
|
---|
[5632009] | 479 |
|
---|
[29244b7] | 480 | <para>
|
---|
| 481 | Now edit <filename>/boot/grub/grub.cfg</filename> and add a new
|
---|
| 482 | menuentry. Below are several examples.
|
---|
| 483 | </para>
|
---|
[5632009] | 484 |
|
---|
[7b82eb14] | 485 | <screen role="nodump"><userinput># Generic initramfs and root fs identified by UUID
|
---|
[0d7900a] | 486 | menuentry "LFS Dev (LFS-7.0-Feb14) initrd, Linux 3.0.4"
|
---|
[5632009] | 487 | {
|
---|
| 488 | linux /vmlinuz-3.0.4-lfs-20120214 root=UUID=54b934a9-302d-415e-ac11-4988408eb0a8 ro
|
---|
| 489 | initrd /initrd.img-no-kmods
|
---|
| 490 | }</userinput></screen>
|
---|
| 491 |
|
---|
[7b82eb14] | 492 | <screen role="nodump"><userinput># Generic initramfs and root fs on LVM partition
|
---|
[0d7900a] | 493 | menuentry "LFS Dev (LFS-7.0-Feb18) initrd lvm, Linux 3.0.4"
|
---|
[5632009] | 494 | {
|
---|
| 495 | linux /vmlinuz-3.0.4-lfs-20120218 root=/dev/mapper/myroot ro
|
---|
| 496 | initrd /initrd.img-no-kmods
|
---|
| 497 | }</userinput></screen>
|
---|
| 498 |
|
---|
[7b82eb14] | 499 | <screen role="nodump"><userinput># Specific initramfs and root fs identified by LABEL
|
---|
[0d7900a] | 500 | menuentry "LFS Dev (LFS-7.1-Feb20) initrd label, Linux 3.2.6"
|
---|
[5632009] | 501 | {
|
---|
| 502 | linux /vmlinuz-3.2.6-lfs71-120220 root=LABEL=lfs71 ro
|
---|
| 503 | initrd /initrd.img-3.2.6-lfs71-120220
|
---|
| 504 | }</userinput></screen>
|
---|
| 505 |
|
---|
[29244b7] | 506 | <para>
|
---|
| 507 | Finally, reboot the system and select the desired system.
|
---|
| 508 | </para>
|
---|
[5632009] | 509 |
|
---|
| 510 | </sect2>
|
---|
| 511 |
|
---|
| 512 | </sect1>
|
---|