Hello misc@,

Quite a few people sent me emails about my earier instructions, I posted
here some time ago:
http://marc.theaimsgroup.com/?l=openbsd-misc&m=1

Now I finally got around to update my instructions on how to create an
OpenBSD-based LiveCD/DVD.

They are far from perfect, but it works reasonably well (for me).
With the instructions you can either create a CD or DVD.
I'm too tired to test on amd64 at the moment, but it _should_ work
exactly the same (that is one of the reasons I love OpenBSD, no as much
pitfalls as in other OS).

Also thanks to Stuart Henderson for his recent post about the "new" CD
boot method:
http://marc.theaimsgroup.com/?l=openbsd-misc&m=115926553800205&w=2


Regards,
ahb

Best viewed using vim: tw=80; syn on; filetype=conf
#----------------------- OpenBSD LiveCD ---------------------------------------#
-> <word>       # are 'links' to my private documentation, just ignore

# 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.

# We need a current system and create a release with source code
# -> release
# Alternatively you could use OpenBSD stable/release with matching source code

# For the paranoid, like myself, using a more strict umask than 022 (e.g. 027):
umask 022       # XXX IMPORTANT for everything that follows!

# Create a directory, this will become root '/' on the CD.
# 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
mkdir -p /usr/livecd/backups/dev; chmod 755 /usr/livecd/backups/dev

# COMPLICATED way SKIP this! (Life is to short for this kind of stuff!)
# <extract sets and manually adjust everything, normally done by install>

# SIMPLE way to get this done
# Grab an empty hard drive and make a fresh nice and SLIM install of OpenBSD. As
# said above you need the source code to the version you install!
# HINT: Against all good practices ONLY create an 'a' partition since it will
# make creating the CD much easier than having multiple partitions.
# This includes all packages/ports you want to be on the CD.

# CD: X fine, but gets tight with (X) ports.
# CD 800MB: Most sets (including) X + a couple of (X) SLIM ports will fit.
# Sets: ALL -game

# DVD: Install whatever you want, there is lots of space.
# Sets: ALL

# You should configure the system EXACTLY like you want it to be on CD.
# 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 generic xorg.conf, YOU put there.

# NOTE: Set a DIFFERENT root password!

# NOTE: 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.
# But shut X down again, before transferring files.

# Configuration hints:
# Remove:
rm -rf /usr/{src,ports}/*               # CD only, for DVD you might even 
extract them.
rm /etc/ssh/*key*                               # Some might want to keep them, 
I don't
# We don't want other people to have a look at our log files
for log_file in `find /var/log -type f`
do
        echo "" > $log_file
done

# Now mount this partition with another OpenBSD system in order to create a
# (compressed) tar archive.
# NOTE: Do not forget the 'p' flag!
cd /mnt/ && tar pczf ~/livecd_root.tar.gz *
# Of course you could also do this over the network, e.g.:
# cd / && tar pczf - / | ssh [EMAIL PROTECTED] 'cat >~/livecd_root.tar.gz'

# We transfer this archive to our build machine and extract into our livecd
# directory we created earlier:
tar pxzf livecd_root.tar.gz -C /usr/livecd/

# We have to copy "/var", "/etc", "/dev", "/root" and "/home" from "/usr/livecd"
# to "/usr/livecd/backup":
# WARNING: Delete the "shell history", "viminfo" and other documents we might
# NOT want to have on our CD:
cd /usr/livecd && rm -i root/{.history,.viminfo}
cd /usr/livecd && rm -i home/*/{.history,.viminfo}
cp -pR /usr/livecd/{var,etc,root,home} /usr/livecd/backups/
cp -pR /usr/livecd/dev/MAKEDEV /usr/livecd/backups/dev/
cd /usr/livecd && ln -s tmp/xorg.conf.new xorg.conf.new # dirty trick, NEEDED!

# WARNING: Check for permission issues in livecd directory

# 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 extract into these MFS partitions.

# We have to modify the "etc/rc" script in order for this to work:
#--------------------------- /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 2048 -i 128 -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'    # Can be smaller
(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

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

# Clean exit
exit 0
#------------------------------------------------------------------------------#

# READ FIRST LINE!
#----------------------- /usr/livecd/backups/etc/rc ---------------------------#
# XXX REMOVE these lines
umount -a >/dev/null 2>&1
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)
#------------------------------------------------------------------------------#

#----------------------- /usr/livecd/backups/etc/rc.local ---------------------#
# Insert at the very END

# We need a root Password
echo 'Need to set a root password'
passwd

# We need a password for our default user as well
echo "Need to set a password for default user 'ahb'"
passwd ahb


# 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
        fi
fi
#------------------------------------------------------------------------------#

# Create devices we need to boot
# WARNING: Partition livecd dir is on (/usr) should NOT have "nodev" set!
# NOTE: 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.
cd /usr/livecd/dev && ./MAKEDEV all


# WARNING:
# As said several times use the source MATCHING YOUR BINARIES!
# Bad things will happen if your kernel is not in sync with userland!


# Now we need to compile a modified GENERIC kernel that is able to boot from CD.
cd /usr/src/sys/arch/$arch/conf    # NOTE: Only tested for i386, amd64
cp GENERIC LIVE_CD
------------------- /usr/src/sys/$arch/conf/LIVE_CD ----------------------------
# config bsd swap generic               < - we have to change this entry
config  bsd root on cd0
--------------------------------------------------------------------------------

# Compile the modified kernel:
config LIVE_CD && cd ../compile/LIVE_CD/ && make clean && make depend && make
# -> kernel_compilieren

# Copy the compiled kernel in the root directory of livecd:
cp bsd /usr/livecd && chown root:wheel /usr/livecd/bsd && \
    chmod 644 /usr/livecd/bsd

# XXX Repeat above for GENERIC.MP
------------------- /usr/src/sys/$arch/conf/LIVE_CD.MP -------------------------
# include "arch/i386/conf/GENERIC"    <- change this entry
include "arch/i386/conf/LIVE_CD"
--------------------------------------------------------------------------------


# We have to modify these files in order to be able to boot:
#------------------------ /usr/livecd/etc/boot.conf ----------------------------
set image /bsd
set timeout 5
/dev/cd0a       /       cd9660 ro,noatime 0 0
/dev/cd0a       /               cd9660  ro,noatime 0 0
# Of course you may have other (noauto) entries here.
--------------------------------------------------------------------------------

# This is optional, but think about if before going on
-------------------- /usr/livecd/backups/etc/ttys ------------------------------
# You might want to have the serial console activated otherwise keep defaults
tty00   "/usr/libexec/getty std.9600"   vt100   on secure local
--------------------------------------------------------------------------------

# 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
cd /usr/livecd/backups && \
    tar pzcf var.tar.gz var && \
    tar pzcf etc.tar.gz etc && \
    tar pzcf dev.tar.gz dev && \
    tar pzcf home.tar.gz home && \
    tar pzcf 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}

# Make sure (empty) directories (with the right permissions) exist for ALL mount
# points: /var, /etc, /dev, /home, /root, /tmp
cd /usr/livecd/ && \
    chmod 700 root && \
    chmod 755 {var,etc,dev,home,backups} && \
        chmod 1777 tmp

# We need to copy cdbr and cdboot to livecd /
cp /usr/livecd/usr/mdec/{cdbr,cdboot} /usr/livecd/

# To speed up the livecd, one might want to tune kernel's cachepct:
cd /usr/livecd && \
    (echo "cachepct 20"; echo "quit") | config -e -o nbsd bsd && \
        mv nbsd bsd
# XXX Repeat for bsd.mp

# Finally we can create the CD .iso image:
vers="40"
/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 "Andreas Bihlmaier <[EMAIL PROTECTED]>" \
    -publisher "Andreas Bihlmaier <[EMAIL PROTECTED]>" \
    -b cdbr -no-emul-boot \
    -c boot.catalog \
    -o /home/livecd.iso \
    /usr/livecd/

# Burn the image as usuall:
cdrecord -speed=12 -overburn -data livecd.iso                   # CD
growisofs -dvd-compat -Z /dev/rcd1c=/home/livecd.iso    # DVD
# -> brennen -> cdrecord -> growisofs
#------------------------------------------------------------------------------#

Reply via email to