LiveCD

From OpenBSD-Wiki

Jump to: navigation, search
Written for: OpenBSD Version 4.6

Contents

[edit] Summary

Since there isn't an official OpenBSD Live CD/DVD we will create one. We try to stick to the 'default system' as far as possible, this makes maintenance much easier.

Tested on: i386, amd64.

I (Andrew Dalgleish) added a few changes suggesting where you can use qemu (for i386).

I tried to make the minimum changes to this article, but it should be obvious you can skip quite a few steps and use less disk space, too.

For example, replace

  • mounting the qemu drive
  • creating a tarball
  • extracting the tarball into /usr/livecd

with

  • mount the qemu drive on /usr/livecd

[edit] Credits

Originally based on several sources:

ONLamp - Building an OpenBSD Live CD

OpenBSD CD Bootable Firewall System

Blackant.net: other: docs: howto bootable cd openbsd system

I, the author (Andreas Bihlmaier), hereby grant permission to redistribute this article under the BSD license.


[edit] Space Requirements

CD (700MB): X fine, but gets tight with (X) ports.

CD (800MB): X together with a couple of slim (X) ports will fit.

DVD: X together with a lot of big/fat (X) ports will fit.


[edit] Pre-Config

The best (and easiest) way to get a release with matching source code is buying an OpenBSD CD here. Alternatively you need -stable/-current source code, from which you create a release.

[edit] Steps

[edit] Step 1: Create build environment (on build host)

Command: Set umask to needed value
umask 022


Partition livecd dir is on (/usr) should NOT have nodev mount option set.

Command: Create a directory, this will become root '/' on the CD
mkdir -p /usr/livecd/backups/dev; chmod 755 /usr/livecd/backups/dev


NOTE:

If there is not enough free space on '/usr' you have to choose a different directory (of course you can do so anyway) and change the paths in all following commands accordingly. If you like copy/paste create a link from /usr/livecd to /path/foodir.

If your /usr is mounted with nodev, you could use vnconfig to mount a vnd(4) on /usr/livecd. See man 8 vnconfig

[edit] Step 2: Create LiveCD content (on LiveCD host)

Grab an empty hard drive and make a fresh nice and slim install of OpenBSD, including all packages/ports you want to be on the LiveCD. You should configure the system exactly like you want it to be on CD. As said above you need the matching source code to the version you install.


WARNING:

Some settings should be fairly generic, especially /etc/X11/xorg.conf should use the vesa driver and a resolution of "1024x768"! X -configure will be run to "autodetect" settings, if this fails, there is a fall back to the generic xorg.conf, you put there.

Do NOT use your normal root password!


HINT:

Against all good practices ONLY create an 'a' partition since it will make creating the CD much easier than having multiple partitions.

You really want to start up X and login with your default user once before proceeding, because we want .fonts.cache-1 to be created. Shut down X before transferring files.

You don't need a spare drive or second machine, you can use qemu.

Command: Install OpenBSD from CD image into qemu

install OpenBSD up to the halt & reboot step

qemu-img create ~/livecd.qemu.hd0 2G
qemu -hda ~/livecd.qemu.hd0 -cdrom /path/to/cd40.iso -boot d

boot from the emulated hard drive & complete installation

qemu -hda ~/livecd.qemu.hd0 -boot c

[edit] Step 3: Remove unwanted stuff (on LiveCD host)

CD only, for DVD you might even extract them.

Command: Remove ports and src (only on LiveCD)
rm -rf /usr/{src,ports,xenocara}/*


Some might want to keep them, I don't.

Command: Remove ssh host keys
rm /etc/ssh/*key*


We don't want other people to have a look at our log files.

Command: Empty log files
for log_file in `find /var/log -type f`
do
	echo "" > $log_file
done

[edit] Step 4: Transfer LiveCD content to build host (on LiveCD host)

Now mount this partition with another OpenBSD system in order to create a (compressed) tar archive.

Command: Create tar archive
cd / && tar pczf ~/livecd_root.tar.gz *


Of course you could also do this over the network.

Command: Create/Transfer tar archive with ssh
cd / && tar pczf - / | ssh user@buildhost 'cat >~/livecd_root.tar.gz'
Command: Create/Transfer tar archive from qemu drive
sudo vnconfig svnd0 ~/livecd.qemu.hd0
sudo mount /dev/svnd0a /mnt
(cd /mnt/ && sudo tar pczf ~/livecd_root.tar.gz *)
sudo umount /mnt
sudo vnconfig -u svnd0

[edit] Step 5: Extract LiveCD content (on build host)

After transfering above created archive to our build machine, we extract it into our livecd directory we created earlier. Do not forget the p flag!

Command: Extract tar archive
tar pxzf livecd_root.tar.gz -C /usr/livecd/

[edit] Step 6: Configure LiveCD (on build host)

[edit] Step 6.1: Delete sensitive information

Delete the "shell history", "viminfo" and other documents we do not want to have on our CD.

Command: Delete files with possibly sensitive information
cd /usr/livecd && rm -i root/{.history,.viminfo}
cd /usr/livecd && rm -i home/*/{.history,.viminfo}


[edit] Step 6.2: Create backup directories

We have to copy "/var", "/etc", "/dev", "/root" and "/home" from "/usr/livecd" to "/usr/livecd/backup" and create a link (dirty hack).

Command: Copy real dirs to backup dirs
mkdir -p /usr/livecd/backups/dev
cp -pR /usr/livecd/{var,etc,root,home} /usr/livecd/backups/
cp -p /usr/livecd/dev/MAKEDEV /usr/livecd/backups/dev/
cd /usr/livecd && ln -s tmp/xorg.conf.new xorg.conf.new

[edit] Step 6.3: Modify etc/rc

We have to create virtual partitions in memory (MFS) since we want them to be faster and more important writeable. On boot the content of the tar files located in "livecd/backups" is extracted into these MFS partitions. Note comment about size of /var.

Command: Content of /usr/livecd/etc/rc
# Create/mount mfs partitions, better do be done inside subshells
echo -n 'Replacing with mfs:'
echo -n ' /tmp'    # Can be smaller
(mount_mfs -s 204800 -o async,nosuid,nodev,noatime swap /tmp; \
    sleep 1; chmod 1777 /tmp)

echo -n ' /dev'
(mount_mfs -s 4096 -i 64 -o async,noatime swap /dev; \
    sleep 1; tar pzxf /backups/dev.tar.gz -C /; cd /dev && sh MAKEDEV all) \
    >>/tmp/livecd_boot.log 2>&1

echo -n ' /var'    # If you have many packages installed use 204800
(mount_mfs -s 51200 -o async,nosuid,nodev,noatime swap /var; \
    sleep 1; tar pzxf /backups/var.tar.gz -C /; \
    test -d /var/tmp && (/bin/rm -rf /var/tmp; /bin/ln -sf /tmp /var/tmp)) \
    >>/tmp/livecd_boot.log 2>&1

echo -n ' /root'
(mount_mfs -s 8192 -o async,nosuid,nodev,noatime swap /root; \
    sleep 1; tar pzxf /backups/root.tar.gz -C /) \
    >>/tmp/livecd_boot.log 2>&1

echo -n ' /home'    # Can be smaller
(mount_mfs -s 204800 -o async,nosuid,nodev,noatime swap /home; \
    sleep 1; tar pzxf /backups/home.tar.gz -C /) \
    >>/tmp/livecd_boot.log 2>&1

echo ' /etc'
(mount_mfs -s 20480 -i 4096 -o async,nosuid,nodev,noatime swap /etc; \
    sleep 1; tar pzxf /backups/etc.tar.gz -C /) \
    >>/tmp/livecd_boot.log 2>&1

# Workaround for a bug in either CDBOOT or mkisofs, use containers for a big
# part of the file system (to reduce number of files in ISO9660)
echo -n 'Mounting images:'
echo ' /usr/local'
(vnconfig svnd3c /usrlocal.img && mount -r /dev/svnd3a /usr/local)

# Start regular rc
. /etc/rc
echo "regular /etc/rc terminated with: $?"	# debug

# Clean exit
exit 0

[edit] Step 6.4: Remove lines from backups/etc/rc

Command: Remove these lines from /usr/livecd/backups/etc/rc
# REMOVE these lines
umount -a >/dev/null 2>&1
mount -a -t nonfs,vnd
mount -uw /            # root on nfs requires this, others aren't hurt
rm -f /fastboot                # XXX (root now writeable)

mount -s /usr >/dev/null 2>&1
mount -s /var >/dev/null 2>&1

echo clearing /tmp
# prune quickly with one rm, then use find to clean up /tmp/[lq]*
# (not needed with mfs /tmp, but doesn't hurt there...)
(cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
    find . ! -name . ! -name lost+found ! -name quota.user \
        ! -name quota.group -execdir rm -rf -- {} \; -type d -prune)

[edit] Step 6.5: Append to backups/etc/rc

Have a look at the comments.

Command: Insert these lines just before block starting with "# Alternatively, on some arch..." in /usr/livecd/backups/etc/rc
# We need a root password
while true; do
	echo -n 'Please enter a root '
	passwd && break
done

# We need a password for our default user as well
while true; do
	echo -n "Please enter default user ahb "
	passwd ahb && break
done

# Start X environment?
echo -n 'Do you want to have a [G]raphical environment or [C]onsole only: '
read ans
if [ x"$ans" == x"G" -o x"$ans" == x"g" -o x"$ans" == x"Graphical" ] ; then
	# Configure X
	echo 'Configuring X'
	/usr/X11R6/bin/X -configure >/tmp/X-configure.log 2>&1
	if [ $? -eq 0 ] ; then
		cp /xorg.conf.new /etc/X11/xorg.conf

		# If you want to use a different keyboard layout (e.g. dvorak):
		#/usr/bin/sed '
		#/Driver[ ]*"kbd"/ a\
		#Option      "XkbRules" "xorg"\
		#Option      "XkbModel" "pc105"\
		#Option      "XkbLayout" "dvorak"\
		#' < /etc/X11/xorg.conf > /tmp/xorg.conf
		#cp /tmp/xorg.conf /etc/X11/xorg.conf

		# If you are using other fonts (e.g. terminus) than in default fontpath:
		#/usr/bin/sed '
		#/FontPath.*100dpi\/"/ a\
		#FontPath     "/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"\
		#FontPath     "/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"\
 		#FontPath     "/usr/local/lib/X11/fonts/terminus/"\
		#FontPath     "/usr/local/lib/X11/fonts/mscorefonts/"\
		#FontPath     "/usr/local/lib/X11/fonts/ghostscript/"\
		#FontPath     "/usr/local/lib/X11/fonts/freefont/"\
		#FontPath     "/usr/local/share/fonts"\
		#FontPath     "/usr/local/share/fonts/override"\
		#' < /etc/X11/xorg.conf > /tmp/xorg.conf
		#cp /tmp/xorg.conf /etc/X11/xorg.conf
		
		chmod 644 /etc/X11/xorg.conf
	else
		echo 'FAILED will use default xorg.conf'
	fi

	rm -f /tmp/.X11-unix/*			# Remove stale socket!

	xdm_flags=""	# Start xdm
else
	echo -n 'Does your graphics card support 80x50 consoles? (y/n): '
	read ans
	if [ x"$ans" == x"y" -o x"$ans" == x"yes" -o x"$ans" == x"Y" ] ; then
		wsfontload -h 8 -e ibm /usr/share/misc/pcvtfonts/vt220l.808
		for Terminal in 1 2 3
		do
			wsconscfg -dF $Terminal
			wsconscfg -t 80x50 $Terminal
		done
		echo 'ttyC1, ttyC2 and ttyC3 set to 80x50 mode'
	fi
        xdm_flags=NO
fi

[edit] Step 6.6: Create etc/boot.conf

We have to modify this file in order to be able to boot

Command: Set boot(8) options, content of /usr/livecd/etc/boot.conf
set image /bsd
set timeout 5


[edit] Step 6.7: Modify etc/fstab

Command: Content of /usr/livecd/etc/fstab
/dev/cd0a	/	cd9660 ro,noatime 0 0
Command: Content of /usr/livecd/backups/etc/fstab
/dev/cd0a	/	cd9660 ro,noatime 0 0
# You may have other (noauto) entries here, of course.

[edit] Step 6.8: (Optional) Modify backups/etc/ttys

You might want to have the serial console activated otherwise keep defaults.

Command: Change in /usr/livecd/backups/etc/ttys
tty00   "/usr/libexec/getty std.9600"   vt100   on secure local


[edit] Step 6.9: Create devices

Not all of created devs would be necessary, but they don't hurt either since we mount a mfs partition on the real /dev and create devices on boot.

Command: Create devices we need to boot
cd /usr/livecd/dev && ./MAKEDEV all


[edit] Step 7: (Optional) Tune bufcache for LIVE_CD kernel

To speed up the LiveCD, one might want to increase kern.bufcachepercent to a value >= 25

Command: Tune bufcache
cd /usr/livecd && (echo "kern.bufcachepercent=25" >> etc/sysctl.conf)

NOTE: If you intend to run the LiveCD on systems with large amounts of RAM (>=1GB) you might want to raise 25.


[edit] Step 8: backups/ and move usr/local to container

[edit] Step 8.1: Archive backups/ and remove leftover files (on build host)

Since a CD is not huge we will compress the "backup" directories into compressed tar archives. NOTE: This is ONE long command line, you could split it into several steps, but it isn't necessary.

Command: Archive backups/; remove files
cd /usr/livecd/backups && \
    tar zcf var.tar.gz var && \
    tar zcf etc.tar.gz etc && \
    tar zcf dev.tar.gz dev && \
    tar zcf home.tar.gz home && \
    tar zcf root.tar.gz root && \
	mv /usr/livecd/etc/{rc,fstab,group,passwd,boot.conf,login.conf} \
	    /usr/livecd/ && \
    rm -rf /usr/livecd/{root,home,var,etc}/* && \
	mv /usr/livecd/{rc,fstab,group,passwd,boot.conf,login.conf} \
	    /usr/livecd/etc/ && \
    rm -rf /usr/livecd/backups/{var,etc,dev,home,root}

[edit] Step 8.2: Move usr/local into container file

You must either free svnd0 or use another svnd device in all commands below. Copy and paste this into one /bin/sh shell, but do it line by line and check for errors.

Command: Create, format and fill usr/local container
# Calculate size for container file
usrlocsize=$(du -ks /usr/livecd/usr/local | awk '{print $1}')
usrlocsize=$((($usrlocsize / 1024) + 200))
if [ $usrlocsize -gt 4000 ] ; then		# ISO9660 limitation
	echo "/usr/local is too large!"
	return 1
fi

# Create, fdisk, disklabel, newfs and mount container file
dd if=/dev/zero of=/usr/livecd/usrlocal.img bs=1m count=$usrlocsize
mkdir /usr/livecd/usr/localtmp
mount_vnd /usr/livecd/usrlocal.img svnd0
fdisk -yi svnd0 >/dev/null
# Important: THREE new lines between "a a" and "q"
disklabel -E svnd0 << _END_DISKLABEL >/dev/null 2>&1
a a



q
y
_END_DISKLABEL
newfs svnd0a >/dev/null 2>&1
mount /dev/svnd0a /usr/livecd/usr/localtmp

# Move usr/local content into container file
mv /usr/livecd/usr/local/* /usr/livecd/usr/localtmp/

# Clean up
umount /usr/livecd/usr/localtmp
vnconfig -u svnd0
rmdir /usr/livecd/usr/localtmp


[edit] Step 9: Create MFS mount points (on build host)

Make sure (empty) directories (with the right permissions) exist for ALL MFS mount points: /var, /etc, /dev, /home, /root, /tmp

Command: Create mount points
cd /usr/livecd/ && \
    chmod 700 root && \
    chmod 755 {var,etc,dev,home,backups} && \
    chmod 1777 tmp


[edit] Step 10: Create ISO image (on build host)

We need to copy cdbr and cdboot to root of livecd

Command: Copy bootstrap files
cp /usr/livecd/usr/mdec/{cdbr,cdboot} /usr/livecd/


Finally we can create the CD/DVD .iso image

Command: Create LiveCD ISO
vers="42"
/usr/local/bin/mkisofs \
    -no-iso-translate \
    -R -T \
    -allow-leading-dots \
    -l -d -D -N -v \
    -V "LiveCD OpenBSD${vers}" \
    -A "LiveCD OpenBSD${vers}" \
    -p "Your Name <your.mail@address.de>" \
    -publisher "Your Name <your.mail@address.de>" \
    -b cdbr -no-emul-boot \
    -c boot.catalog \
    -o /home/livecd.iso \
    /usr/livecd/


[edit] Step 11: Burn the ISO image to CD/DVD

Command: Test CD in qemu
qemu -cdrom livecd.iso -boot d ''<other options>''
Command: Burn CD image
cdrecord [-speed=16] [-overburn] -data livecd.iso


Command: Burn DVD image
growisofs -dvd-compat -Z /dev/rcd1c=livecd.iso


[edit] Additional info

Read excellent OpenBSD man pages and the OpenBSD FAQ.

If you need further explanations or want to give feedback, please send an email to Andreas Bihlmaier <andreas dot bihlmaier at gmx dot de>

Personal tools