Where'd My Files Go?
A Guide to Modern Ubuntu Distributions
Kyle Rankin
Systems Architect
Quinstreet Inc.
Some Background
Agenda
- Ubuntu Boot
- Grub
- Initrd
- SysV Init
- Upstart
- udev
- Orientation for RedHat Users
Ubuntu Boot
Similar to Most Other Linuxes
- Boot Loader (grub) Loads
- Kernel and initrd (initramfs) Load
- initramfs /init script runs
- /sbin/init runs
- /sbin/init starts SysV init scripts
- Login prompt
Grub
- Multi-stage program in MBR and file system
- Can boot multiple OSes
- Nice menu system
- File system aware
- Edit most settings on the fly
Grub and Ubuntu
- Main config file in /boot/grub/menu.lst
- Kernels, initramfs, etc in /boot (more later)
- Hard Way: edit menu.lst manually...
- Ubuntu Way: update-grub script
update-grub
- Uses menu.lst as its configuration file
- Configuration in menu.lst comments
# kopt=root=UUID=665d7008-fde9-4055-8af9-483697acb005 ro
# groot=(hd0,0)
# defoptions=splash
# altoptions=(recovery mode) single
Can run with no arguments
Reads config, updates based on available kernels
Options well-documented in default menu.lst
Classic Initrd
- Short for Initial Ramdisk
- Sits in /boot/ directory with kernel
- Contains an actual small / directory structure
- Minimal /bin, /sbin, /lib and so on
- Kernel runs /linuxrc script inside / structure
- Everything kernel needs to mount real root partition
- Didn't used to need initrd...
Initrd and the Modular Kernel
- Kernel originally not too modular
- Then got some modules with important drivers built-in
- Became heavily modular, had chicken-or-egg problem
- Initrd contains all essential modules to find and mount /
- Includes SCSI, LVM, Software RAID, loop-aes, display drivers
Ubuntu's Initramfs
- Initramfs instead of initrd
- cpio archive instead of loopback ext2 file system
- Runs /init instead of /linuxrc
- use update-initramfs (and files in /etc/initramfs-tools) to update
- For fun:
$ cp initrd.img-2.6.24-19-server \
/tmp/initrd.img-2.6.24-19-server.gz
$ cd /tmp
$ gunzip initrd.img-2.6.24-19-server.gz
$ mkdir initrd
$ cd initrd
$ cpio -idv < /tmp/initrd.img-2.6.24-19-server
SysV Init
- Classic Unix bootup mechanism
- Configured by /etc/inittab
- Separated system states with runlevels
- All init scripts in /etc/init.d/
- Runlevels symlink to /etc/rcX.d
- S = start on entering runlevel
- K = stop on entering runlevel
- D = Disabled
- Executed in numerical order
SysV Init
Standard Runlevels
- 0 = halt
- 1 = single user mode
- 6 = reboot
- 2-5 = used by system
- Ubuntu/Debian default: 2
- Redhat: 3 = console, 5 = X
SysV Init
Boot Process
- Reads inittab, finds default runlevel
- Runs /etc/rcS.d/ scripts with start argument
- Runs /etc/rc2.d/ scripts with start argument
- Runs /etc/rc.local
- Can Manually start/stop script in /etc/init.d/
Upstart
- Designed to replace/improve SysV init
- Replaced SysV init in Ubuntu 6.10
- Event-driven
- Asynchronous
- Currently backwards-compatible with SysV init
- Management programs: initctl, start, stop, status
- Scripts reside in /etc/events.d/
Upstart Events
- Upstart scripts triggered by events
- Events: runlevels changing, other scripts starting/stopping
start on runlevel 2
stop on runlevel [!2]
console output
script
set $(runlevel --set 2 || true)
if [ "$1" != "unknown" ]; then
PREVLEVEL=$1
RUNLEVEL=$2
export PREVLEVEL RUNLEVEL
fi
exec /etc/init.d/rc 2
end script
Upstart vs. SysV
- Upstart scripts can automatically respawn (sshd anyone?)
- Easily check status/PID of all Upstart scripts (initctl status)
- Can trigger scripts after initial boot
- Upstart = Parallel, SysV = serial
- Can create your own events to trigger
- Easy to create new scripts
- The NFS example
Sample Upstart Script
on bounce
exec echo --Bounced--
console output
To start:
# initctl emit bounce
# --Bounced--
Can use pre-start, pre-stop, post-start, post-stop scripts
Future of Upstart
- Already used by Fedora 9
- No Runlevels (or infinite?)
- Replacing cron and at
- Events triggered by file/directory changes
- User-owned services
udev
- Replaces programs like hotplug
- Eliminates static device files in /dev
- Creates dynamic device directory in /dev
- Try it: Boot with a rescue disk and mount /
- udev config in /etc/udev/
- udev rules in /etc/udev/rules.d/
udev rules
- Can match a number of things including:
- Device events
- Device attributes (IDs, device paths)
- Variables set by other rules
- Many other attributes
- Once matched, rules define actions to take:
- device files to create
- modules to load
- external programs to run
- settings to trigger other rules
Sample udev rule
- Sierra wireless 3G card
- Shows up as /dev/ttyUSB0-5
- Insert card, run udevinfo -a -p $(udevinfo -q path -n /dev/ttyUSB0)
- Look for identifying Product ID or other key in output
- Create rule to match idProduct = 6880
- /etc/udev/rules.d/95-sierra.rules
KERNELS=="5-1", ATTRS{idProduct}=="6880", ENV{ACTION}=="add", \
RUN+="/sbin/ifup ppp0"
KERNELS=="5-1", ATTRS{idProduct}=="6880", ENV{ACTION}=="remove", \
RUN+="/sbin/ifdown ppp0"
UUID
- Problem: /dev entries don't "stick" to partitions
- Solution: Assign each partition a Universally Unique IDentifier
- Ubuntu uses UUIDs for /etc/fstab, grub, etc.
- Managed by udev
- To see current UUID->device mappings:
greenfly@minimus:~$ ls -l /dev/disk/by-uuid/
total 0
[truncated] 634719fd-a6da-4fee-8646-0d485d7681db -> ../../sda2
[truncated] 665d7008-fde9-4055-8af9-483697acb005 -> ../../sda1
[truncated] cf3892fd-e3d8-446f-8552-4c633be9c382 -> ../../sda3
Orientation for RedHat Users
- Networking
- Redhat: /etc/sysconfig/network-scripts/ifcfg-*
- Ubuntu: /etc/network/interfaces
- Service Management
- Redhat: service, chkconfig
- Ubuntu: service, update-rc.d (sorta)
- Package Management
- Redhat: yum, rpm
- Ubuntu: apt, dpkg
Questions?
Some useful links