Casper boot process

From FlimzyWiki

Jump to: navigation, search

This page is being compiled as I dig through all of the scripts that are run during the casper boot process, so it may be incomplete.

Contents

Boot order

  • /init
    • /scripts/init-premount
    • mountroot()
      • find_livefs()
        • mount mount_images_in_directory()
          • setup_unionfs()
      • /scripts/casper-bottom
    • /scripts/init-bottom

/init

The initial init that is run is a shell script contained within the initramfs image. This particular script is standard in all Debian (and likely other distros) initramfs images.

This script creates a basic filesystem (running in RAM) by creating and populating the following directories:

  • /dev
  • /root
  • /sys
  • /proc
  • /tmp
  • /var/lock
  • /dev/console
  • /dev/null

It also reads in the following config files include scripts:

  • /etc/udev/udev.conf (only present if udev is in use)
  • /conf/arch.conf (contains the Debian architecture. i.e. DPKG_ARCH=i386)
  • /conf/initramfs.conf
  • /scripts/functions

It then reads any relevant kernel command line options, then executes any scripts in /scripts/init-top. After essential modules are loaded any scripts in /scripts/init-premount are run.

This script will take any argument passed to the kernel as boot=<script> and source the script /scripts/<script>. This is how the /scripts/casper script is called. The casper script then overrides some essential functions, such as the mountroot() function.

Once mountroot() is complete, casper is essentially done, and the standard boot process continues by running the scripts in /scripts/init-bottom

/sys and /proc are mount-moved to the new root filesystem.

/scripts/casper

The following functions are all defined in the /scripts/casper file.

mountroot()

The first thing this function does is parse the kernel command line for casper-related options.

It then runs any scripts in /scripts/casper-premount (by default there are none).

If doing a netboot, the 'do_netmount()' function is then run, otherwise it runs the 'find_livefs()' function.

If toram or todisk is specified on the kernel commandline, then the live filesystem is copied to RAM or disk respectively. Then mount_images_in_directory() is called to mount the casper images into a unionfs.

Once these images are mounted, any scripts in /scripts/casper-bottom are run.

Then the casper.log file is moved to /var/log/casper.log.

find_livefs()

ARGUMENTS: timeout

If live-media= or bootfrom= is specified on the commandline, it probes the specified device to see if it is valid. If 'live-media-timeout' is set on the commandline, it waits this many seconds before probing the device.

If the specified device does not exist or does not contain a valid casper partition, a scan is done on all known block devices to find the correct live media.

mount_images_in_directory()

ARGUMENTS: directory, rootmnt

Makes sure that $directory/casper/ contains at least one valid image, then executes setup_unionfs().

setup_unionfs()

ARGUMENTS: image_directory, rootmnt

First loads the unionfs kernel module.

For each image file in $image_directory, a directory corresponding to the image name (without the extension) is created in /, then the image is mounted in that directory. For example, /casper/foo.squashfs would be mounted on /foo.

Once all the images are mounted, the COW tmpfs is created and mounted on /cow.

Then the unionfs is mounted with a command that resembles:

mount -t unionfs -o dirs=/cow=rw[:/<img1.fstype>=ro][:/<img1.fstype>=ro][...:/<imgN.fstype>=ro] unionfs /root

Then if a persistent /home is defined, it mounts it as /home.

If showmounts is specified, each mounted image is made accessable in /casper/<image name>.

Then the tmpfs filesystem is made accessable via /cow.

/scripts/casper-bottom/*

Any files found in this script are run, but not in any pre-defined order. Thus the prereqs() function is defined in each script to output the name of any other scripts it depends on before being run.

01integrity_check

If integrity-check is specified on the kernel command line, an MD5 check is done against $MOUNTPOINT, using $MOUNTPOINT/md5sum.txt as the source of the presumed 'good' MD5 sum.

02etc_casper_conf

If it /etc/casper.conf exists it is read from the live media and copied to the unionfs. If it does not exist, it is created on the unionfs and populated with values for username, userfullname, and hostname from the kernel command line or the defaults.

05mountpoints

This script moves /live_mount to /root/live_mount so that the live media will still be accessable to the running system.

10adduser

This creates some default users in /etc/passwd and /etc/group so the system has some sane values to work with.

12fstab

This creates a /etc/fstab file that looks like this:

unionfs / unionfs rw 0 0
tmpfs /tmp tmpfs nosuid,nodev 0 0

13swap

This searches for and activates any found swap partitions.

14locales

If a locale is specified on the kernel commandline, it is made active here. If not, it defaults to en_US.UTF-8.

15autologin

This configures GDM to automatically log in, rather than prompting for a password.

18hostname

This sets the hostname to 'live' by default, or to whatever was specified on the kernel commandline or in casper.conf. It also sets up the /etc/hosts file to look like this:

127.0.0.1 localhost
127.0.1.1 $HOSTNAME

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

19keyboard

This configures the keyboard layout as defined on the kernel command line.

20xconfig

This does some default X configuration.

22gnome_panel_data

22screensaver

23etc_modules

This adds "snd_powermac" to /etc/modules on PowerPC machines. It has no effect on other architectures.

23networking

This creates /etc/network/interfaces unless ip=frommedia was specified on the kernel command line *and* /etc/network/interfaces already exists. If it is created by this script it will look like this:

auto lo
iface lo inet loopback

24preseed

Populates the dpkg database.

25configure_init

Modifies /etc/inittab (only on the unionfs) to enable shells rather than login prompts on all virtual consoles.

It also removes any init files that would possibly set the hardware clock, and turns of readahead which doesn't work well with unionfs.

30accessibility

Sets up accessibility options according to the access= kernel command line option.

31disable_update_notifier

32disable_hibernation

33disable_binary_drivers

34disable_kwallet

35fix_language_selector