Create a NetBSD LiveCD

Introduction
You may have various reasons to create a LiveCD.
Create a custom installer for your application and distribute it to the customers, create a desktop enviroment and boot it off your CD whenever you cannot access your own computer or maybe you have a diskless router and you want to run your O.S off the CD.
Implementation
There are two ways to create a LiveCD running NetBSD.
The “old” way is to create a boot floppy sized image.
The boot image must be exactly the size of either a 1200, 1440, or a 2880 kB floppy, and mkisofs will use this size when creating the output iso9660 filesystem.
The image will have a kernel with root file system inserted into it.
For i386, compile your custom kernel or you can use kernel config from /usr/src/sys/arch/i386/conf/INSTALL.
Then do following:

Create a directory where you will build your image and cd to it.
# cd /my_build/dir
Copy your custom kernel to this directory.
# cp /usr/src/sys/arch/i386/compile/obj/${MYKERNEL}/netbsd .
Create file system of the directory with files for your LiveCD.
# makefs -s ${FS_SIZE} -t ffs md.img ${IMG_DIR}
where ${FS_SIZE} is the size of your md.img and IMG_DIR is where you have your file system.

Now you need to insert the image into your kernel, wich then will get extracted of the kernel and mounted as memory file system:
# mdsetimage -v -s netbsd md.img
Compress your kernel to save space and rename it (optional step):
# gzip -f -9 netbsd ; mv netbsd.gz netbsd
For vnconfig, newfs and disklabel to “understand” the notion of floppy288 you need to edit your /etc/disktab and add there:

floppy288|2.88MB 3.5in Extra High Density Floppy:\
:ty=floppy:se#512:nt#2:rm#300:ns#36:nc#80:\
:pa#5760:oa#0:ba#4096:fa#512:ta=4.2BSD:\
:pb#5760:ob#0:\
:pc#5760:oc#0:

Create virtual disk and file system on it.
# dd if=/dev/zero of=image.fs count=5760
# vnconfig -t floppy288 -v -c /dev/vnd0d image.fs
# disklabel -rw /dev/vnd0d floppy288
# newfs -m 0 -o space -i 204800 /dev/rvnd0a

Bootstrap your virtual disk:
# /usr/sbin/installboot -v -m i386 -o timeout=3,console=pc -t ffs /dev/rvnd0a /usr/mdec/bootxx_ffsv1
Mount the virtual disk you just created and copy over your kernel and second stage boot loader.
# mount /dev/vnd0a /mnt
# cp /boot /mnt/
# cp netbsd /mnt/
# umount /mnt
# vnconfig -u vnd0d

Create a directory for your ISO image and copy your image there.
# cp image.fs cdisodir/
You can put some additional files to the cdisodir, they will be avaliable when you mounted your CD.

Create ISO image.
# mkisofs -l -J -R -o livecd.iso -c boot.catalog -b image.fs cdisodir

The new way is to use cdboot file instead of boot floppy.
This will allow you to use kernel beyond 2880 kB.
To compile cdboot, run:
# cd /usr/src/sys/arch/i386/stand/cdboot ; make
This time we will not create a floppy image. We dont need it since we can use cdboot instead.
Put cdboot to your cdisodir.
# cp /usr/src/sys/arch/i386/stand/cdboot/cdboot cdisodir/
Copy over your kernel with rootfs inserted into it and second stage boot loader to your ISO directory.
# cp netbsd cdisodir/
# cp /boot cdisodir/

Create ISO image
# mkisofs -l -J -R -o livecd.iso -c boot.catalog -b cdboot -no-emul-boot cdisodir
Notice the -no-emul-boot option. It’s becouse the boot image is not an image of a floppy.

To check your ISO image, you can mount it as virtual device:
# vnconfig -v -c /dev/vnd0d livecd.iso
# mount -t cd9660 /dev/vnd0a /mnt

When you’re done:
# umount /mnt
# vnconfig -u vnd0d

Thats all, its done. )

Special thanks to Yazzy )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: