If this document changes, it will be available at https://genericbooks.com/Literature/Articles/3/cdburn_2.html
STRING NOTE: The perl scripts and methods I use to make bootable cdroms is NOT NOT NOT very clean yet. I am still working to perfect the process. I want to have it all run in Python or Perl (preferrably Python). Once making bootable cdroms is well documented, I am going to merge this with my MILAS project.
What advantages do you have by doing this in my strange way? Well, first, realize something before I answer that question. Realize that a floppy, cdrom, or a hard drive partition can be treated the same in most respects. Okay, now I will answer the question:
Second, either using the files from a partition you were using for testing purposes, or if you want to start from scratch,
Make an image that is 600 megs but using "dd"
and a loopback device. Then copy this image to your cdrom. How do you make
an image?
Assume that "/mnt/Partition" is the directory you have all the files
that you want to make an image out of.
## Create a blank file or image
dd if=/dev/zero of=/tmp/Image bs=1024k count=650
### Format this blank image
/sbin/mke2fs -b 2048 /tmp/Image
### Answer "y" to mkfs if it says that it doesn't recognize
the device
mkdir -p /mnt/CDROM_IMAGE
### Mount the blank formatted image to a directory
mount -t ext2 -o loop=/dev/loop1 /tmp/Image mnt/CDROM_IMAGE
### Copy over the stuff from your hard drive partition
to your image for the cdrom.
tar -C /mnt/Partition -pc . | tar -C /mnt/CDROM_IMAGE -xvp
### Or just use rsync to copy it over
# rsync -a /mnt/Partition/* /mnt/CDROM_IMAGE
### Umount the image
umount /mnt/CDROM_IMAGE
OR, if you don't mind using an ISO9660 formatted cdrom, which will work
the same with rock-ridge extensions, enter this command.
mkisofs -aJlL -r -o /tmp/Image /mnt/Partition
NOTE: Making an iso9660 cdrom in one step is a lot easier and is described
in the section below.
Now burn the image located at "/tmp/Image" to your cdrom.
Actually, I was thinking, you can probably just make a hard drive partition 600 megs and copy it over directlly without having to make an image. If your hard drive partition is "/dev/hda4", then do this.
### Note, I never tested this yet.
### Unmount our partition that we copied files to
umount /dev/hda4
### Make an image of the partition
dd if=/dev/hda4 of=/tmp/Image.raw
Now just take Image.raw and burn it to your cdrom.
For better examples on how to do this, look at my Perl script below. Anybody want to convert this into a Python Script? Perhaps a Python/TK script?
With this section, you don't need a to use a loopback device, you don't need to use any partitions, you just need a directory somewhere on your computer and the program "mkisofs". This probably is the easiest way to create an image that you want to use for a cdrom.
The key to making a bootable cdrom is the "mkisofs"
program. Here is a typical command that I use,
mkisofs -aJlL -r -o /tmp/Boot_Image /CDROM
"/CDROM" is the directory that you want to burn
onto a cdrom. To add the boot file,
mkisofs -aJlL -r -b /tmp/Boot.image -o /tmp/Boot_Image /CDROM
In the next section we discuss how to make a bootable
floppy disk that you can put on your cdrom.
The key item to remember is that you need a directory for this program. This nice thing is, it doesn't grab the empty space on a partition when it creates its image. You can use a spare
Here is an example of how to copy over files and configure the bootup
process.
Assume the directory you are making an image of is, "/tmp/Boot_Image".
cd /tmp/Boot_Image
mkdir root
mkdir mnt
mkdir proc
mkdir tmp
mkdir home
mkdir misc
mkdir opt
### Yes, tmp/var doesn't exist, but it will after bootime
ln -s tmp/var var
mkdir dev
rsync -a /dev/* dev
mkdir lib
rsync -a /lib/* lib
mkdir bin
rsync -a /bin/* bin
mkdir sbin
rsync -a /sbin/* sbin
mkdir usr
mkdir etc
rsync -a /etc/* etc
mkdir boot
rsync -a /boot/* boot
Now, configure etc/inittab to boot at runlevel "1".
Change
id:5:initdefault:
to
id:1:initdefault:
in the file etc/inittab
Now, change your etc/fstab to this,
#### change /dev/hdc to wherever your cdrom is located
/dev/hdc /
ext2 defaults
1 1
/dev/fd0 /mnt/floppy
ext2 noauto,owner 0 0
none /proc
proc defaults
0 0
none /dev/pts
devpts gid=5,mode=620 0 0
### Note, this is using
a swap partition from a hard drive.
#### Delete this is or change
this
/dev/hda6
swap
swap defaults
Now, add to the end of etc/rc.d/rc.local the following commands
mkfs -t ext2 /dev/ram0
mount /dev/ram0 /tmp
chmod 777 /tmp
chmod +t /tmp
Now you need to make a bootdisk with a larger ramdisk on it.
### This makes a bootdisk, put a floppy disk in
mkbootdisk `uname -r`
### This makes the directory to mount the floppy disk
mkdir /mnt/floppy_test
### Mount the floppy disk
mount /dev/fd0 /mnt/floppy_test
### Edit the lilo.conf file and put "ramdisk=35000" in the lilo.conf
file, mine looks like
boot=/dev/fd0
timeout=100
message=/boot/message
prompt
image=/vmlinuz-2.2.12-32
label=linux
### Change
/dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is
root=/dev/hdc
ramdisk=35000
image=/vmlinuz-2.2.12-32
label=rescue
append="load_ramdisk=2 prompt_ramdisk=1"
root=/dev/fd0
### Now execute the lilo command on the floppy drive
lilo -r /mnt/floppy_test
### Now umount the floppy disk
umount /dev/fd0
Now you have a bootable floppy disk that uses your cdrom as root.
If you are going to burn the floppy disk image onto your cdrom using
mkisofs, then change lilo.conf to this,
boot=/dev/hdc
timeout=100
message=/boot/message
prompt
image=/vmlinuz-2.2.12-32
label=linux
### Change
/dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is
root=/dev/hdc
ramdisk=35000
### After you umount the floppy disk, make an image of
the floppy disk to burn on a cdrom
dd if=/dev/fd0 of=/tmp/Boot.image
Mark Nielsen works for The Computer Underground as a clerk and as a book binder at ZING. In his spare time, he does volunteer stuff, like writing articles for The Linux Gazette and developing ZING's website.