old-www/LDP/LG/issue54/nielsen.html

435 lines
19 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>First Attempt at Creating a Bootable Live Filesystem on a CDROM LG #54</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<CENTER>
<A HREF="http://www.linuxgazette.com/">
<H1><IMG ALT="LINUX GAZETTE" SRC="../gx/lglogo.jpg"
WIDTH="600" HEIGHT="124" border="0"></H1></A>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="frost.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue54/nielsen.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../faq/index.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="okopnik.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
<P>
</CENTER>
<!--endcut ============================================================-->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">First Attempt at Creating a Bootable Live Filesystem on a CDROM</font></H1>
<H4>By <a href="mailto:mark@tcu-inc.com">Mark Nielsen</a>
<P> If this document changes, it will be available at
<a href="http://genericbooks.com/Literature/Articles/3/cdburn_2.html">
http://genericbooks.com/Literature/Articles/3/cdburn_2.html</a>
</H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h3>
Contents</h3>
<ol>
<li>
<a href="#Ref">References</a></li>
<li>
<a href="#Intro">Introduction to cdrom burning and bootable cdroms.</a></li>
<li>
<a href="#ext2">Creating an EXT2 cdrom and a bootable floppy disk</a></li>
<li>
<a href="#iso">Creating a bootable installation CDROM using ISO9660 </a>and
Rock-Ridge extensions (for my MILAS project). This is the preferred way
of making CDROMs.</li>
<li>
<a href="#config">Configuring the boot-up process</a> so that the computer
is useable.</li>
<li>
<a href="#conclusions">Conclusions and future articles</a></li>
<li>
<a href="misc/nielsen/Milas-0_1.pl.txt">A crude Perl script</a> to make a bootable iso9660
formatted cdrom of RedHat 5.1 from my computer.</li>
<li>
<a href="misc/nielsen/rc.sysinit.txt">My rc.sysinit</a> file for RedHat 6</li>
<li>
<a href="misc/nielsen/lilo.conf.txt">My example lilo.conf</a> file.</li>
<li>
<a href="misc/nielsen/fstab.txt">My example fstab</a>.</li>
<li> <a href="misc/nielsen/Install_pl.txt"> My old Install.pl script.</a> This is where
MILAS came from. This Perl scripts will eventually be integrated with the
bootable cdrom.
</ol>
<hr><a NAME="Ref"></a>
<h1>
References</h1>
<ol>
<li>
<a href="http://www.guug.de/~winni/linux/cdr/html/">CD-Writing HOWTO</a>
by Winfried Tr&uuml;mper</li>
<li>
<a href="http://www.linuxdoc.org/HOWTO/mini/LILO.html">Lilo mini-Howto</a></li>
<li>
<a href="http://www.fh-muenchen.de/rz/xcdroast">Xcdroast</a>&nbsp; -- read
about cdrecord with "man cdrecord".</li>
</ol>
<hr><a NAME="Intro"></a>
<h1>
Introduction to cdrom burning.</h1>
First off, you should read the previous article <a href="http://www.tcu-inc.com/mark/articles/cdburn.html">Creating
Installation Cds from various Linux Distributions. </a>This article will
assume you know how to make cdroms using cdrecord. Now the, the next step.
Why make a Live Linux Filesystem for a cdrom?
<br>&nbsp;
<ol>
<li>
You want to make an installation cdrom (like MILAS).</li>
<li>
You want to boot off the cdrom and use it for most of the core files for
your operating system and use your hard drive for other stuff.</li>
<li>
You want to make it real easy to do upgrades. Use a rewritable cdrom and
just swap out the old cdrom with a new one.</li>
</ol>
The long term direction is to use a cdrom to create computers without hard
drives. You use the cdrom for most of the core filesystem, a ramdisk for
/tmp, and NFS for everything else. I really really dislike professional
network computers that are diskless and hope that creating your own
diskless workstations will be the way of the future.
<p>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.
<p>
<hr WIDTH="100%">
<br><a NAME="ext2"></a>
<h1>
Creating an EXT2 cdrom and a bootable floppy disk</h1>
For this exersize, we will do something a little strange. We will make
an ext2 formatted cdrom and a floppy disk that is bootable. For people
want to use the easier iso9660 format, skip this section.
<p>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:
<ol>
<li>
You can use a spare partition on your hard drive to test the image you
want to put on your cdrom. If you boot off of a floppy disk, you can point
it to the hard drive partition, and if it works out great, then on the
next floppy disk you make bootable, have it point to your cdrom. Remember
to mount the hard-drive partition read-only to simulate a read-only cdrom.
Hard drive partitions are a good way to test images before you put them
on your cdrom (especially when it is a write-once cdrom).</li>
</ol>
OPTIONAL: First, create an ext2 filesystem (using the hard drive for testing purposes):
<ol>
<li>
Have a spare partition on your hard drive to use for your image for the
cdrom.</li>
<li>
Format the partition as an ext2 format. Example: "mkfs -t ext2 /dev/hda3".
This formats the third partition on your primary hard drive. Make sure
you change the number "3" to the correct number used for your spare partition.</li>
<li>
Copy over all critical directories and configure the files in ROOT/etc
to correctly reflect your new installation.</li>
<li>
Use a ramdisk for "/tmp" and point "/var" to "/tmp/var".</li>
<li>
Make a bootable floppy disk, and either configure it to use the cdrom drive
as "root" or "/" or if you get lilo installed on the floppy drive, you
can type in a command at boottime to use a different partition for "/".
You can do this with the command</li>
<br>lilo root=/dev/hdc
<br>if your cdrom drive is "/dev/hdc". Notice I did not specify a partition
number. There is none.
<br>There are also other ways to make bootable floppies. For my redhat
installation
<br>&nbsp;&nbsp; ### Make a copy of the kernel
<br>cp /boot/vmlinuz-2.2.12-32 /tmp/Vmlinuz
<br>&nbsp;&nbsp; ### Make the copy boot from the cdrom on /dev/hdc
<br>rdev /tmp/Vmlinuz /dev/hdc
<br>ramsize /tmp/Vmlinuz 20000
<br>&nbsp;&nbsp; ### copy the kernel directly to the floppy disk, you might
have to format it first, mkfs -t ext2 /dev/fd0
<br>dd if=/tmp/Vmlinuz of=/dev/fd0</ol>
For examples of how to copy over directories and files, look at the Perl
script at the end of the document.
<br>For examples on how to use a ramdisk, read about this RamDisk article
I wrote a while ago, and also "man lilo.conf".
<p>
Second, either using the files from a partition you were using for testing purposes,
or if you want to start from scratch,
<p>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?
<br>Assume that "/mnt/Partition" is the directory you have all the files
that you want to make an image out of.
<p>&nbsp; ## Create a blank file or image
<br>dd if=/dev/zero of=/tmp/Image bs=1024k count=650
<br>&nbsp;&nbsp;&nbsp; ### Format this blank image
<br>/sbin/mke2fs&nbsp; -b 2048 /tmp/Image
<br>&nbsp;&nbsp; ### Answer "y" to mkfs if it says that it doesn't recognize
the device
<br>mkdir -p /mnt/CDROM_IMAGE
<br>&nbsp;&nbsp; ### Mount the blank formatted image to a directory
<br>mount&nbsp; -t ext2 -o loop=/dev/loop1 /tmp/Image mnt/CDROM_IMAGE
<br>&nbsp;&nbsp; ### Copy over the stuff from your hard drive partition
to your image for the cdrom.
<br>tar -C /mnt/Partition -pc . | tar -C /mnt/CDROM_IMAGE -xvp
<br>&nbsp; ### Or just use rsync to copy it over
<br>#&nbsp;&nbsp;&nbsp; rsync -a /mnt/Partition/* /mnt/CDROM_IMAGE
<br>&nbsp; ### Umount the image
<br>umount /mnt/CDROM_IMAGE
<p>OR, if you don't mind using an ISO9660 formatted cdrom, which will work
the same with rock-ridge extensions, enter this command.
<br>mkisofs -aJlL&nbsp; -r -o /tmp/Image /mnt/Partition
<br>NOTE: Making an iso9660 cdrom in one step is a lot easier and is described
in the section below.
<p>Now burn the image located at "/tmp/Image" to your cdrom.
<p>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.
<p>&nbsp; ### Note, I never tested this yet.
<br>&nbsp; ### Unmount our partition that we copied files to
<br>umount /dev/hda4
<br>&nbsp; ### Make an image of the partition
<br>dd if=/dev/hda4 of=/tmp/Image.raw
<p>Now just take Image.raw and burn it to your cdrom.
<p>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?
<p>
<hr WIDTH="100%"><a NAME="iso"></a>
<h2>
Creating an installation CDROM using ISO9660 and Rock-Ridge extensions
(for my MILAS project)</h2>
The big deal about make ISO9660 formatted cdroms with Rock-Ridge extensions
is that fact that you can make cdroms bootable. This is very useful for
creating your own diskless workstations, creating boot-able installation
cdroms, creating a cdrom to fix hard drives, and probably other stuff.
<p>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.
<p>&nbsp;&nbsp;&nbsp;&nbsp; The key to making a bootable cdrom is the "mkisofs"
program. Here is a typical command that I use,
<br>mkisofs -aJlL&nbsp; -r -o /tmp/Boot_Image /CDROM
<br>&nbsp;&nbsp;&nbsp; "/CDROM" is the directory that you want to burn
onto a cdrom. To add the boot file,
<br>mkisofs -aJlL&nbsp; -r -b /tmp/Boot.image -o /tmp/Boot_Image /CDROM
<br>&nbsp;&nbsp;&nbsp; In the next section we discuss how to make a bootable
floppy disk that you can put on your cdrom.
<p>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
<p>
<hr><a NAME="config"></a>
<h1>
Configuring the boot-up process so that the computer is useable.</h1>
The toughest part about creating a live filesystem is copying over the
critical files and configuring them. You should have the same directory
structure as your Linux filesystem, except the stuff under /usr should
not be critical, but perhaps helpful. Remember to mount a ramdisk to /tmp,
remember that you should point /var to /tmp/var, and remember to configure
the files in /etc correctly. This could be a whole article itself. I try
to do it in the Perl script below. If you combine a live filesytem on a
cdrom with a hard drive or NFS, you will have more options as to what you
can do.
<p>Here is an example of how to copy over files and configure the bootup
process.
<br>Assume the directory you are making an image of is, "/tmp/Boot_Image".
<p>cd /tmp/Boot_Image
<br>mkdir root
<br>mkdir mnt
<br>mkdir proc
<br>mkdir tmp
<br>mkdir home
<br>mkdir misc
<br>mkdir opt
<br>### Yes, tmp/var doesn't exist, but it will after bootime
<br>ln -s tmp/var var
<br>mkdir dev
<br>rsync -a /dev/* dev
<br>mkdir lib
<br>rsync -a /lib/* lib
<br>mkdir bin
<br>rsync -a /bin/* bin
<br>mkdir sbin
<br>rsync -a /sbin/* sbin
<br>mkdir usr
<br>mkdir etc
<br>rsync -a /etc/* etc
<br>mkdir boot
<br>rsync -a /boot/* boot
<p>Now, configure etc/inittab to boot at runlevel "1".
<br>Change
<br>id:5:initdefault:
<br>to
<br>id:1:initdefault:
<br>in the file etc/inittab
<p>Now, change your etc/fstab to this,
<p>&nbsp;&nbsp;&nbsp; #### change /dev/hdc to wherever your cdrom is located
<br>/dev/hdc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ext2&nbsp;&nbsp;&nbsp; defaults&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1 1
<br>/dev/fd0&nbsp;&nbsp;&nbsp;&nbsp; /mnt/floppy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ext2&nbsp;&nbsp;&nbsp; noauto,owner&nbsp;&nbsp;&nbsp; 0 0
<br>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /proc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
proc&nbsp;&nbsp;&nbsp; defaults&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0 0
<br>none&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /dev/pts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
devpts&nbsp; gid=5,mode=620&nbsp; 0 0
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ### Note, this is using
a swap partition from a hard drive.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #### Delete this is or change
this
<br>/dev/hda6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
swap&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
swap&nbsp;&nbsp;&nbsp; defaults
<p>Now, add to the end of etc/rc.d/rc.local the following commands
<p>mkfs -t ext2 /dev/ram0
<br>mount /dev/ram0 /tmp
<br>chmod 777 /tmp
<br>chmod +t /tmp
<p>Now you need to make a bootdisk with a larger ramdisk on it.
<br>&nbsp; ### This makes a bootdisk, put a floppy disk in
<br>mkbootdisk `uname -r`
<br>&nbsp; ### This makes the directory to mount the floppy disk
<br>mkdir&nbsp; /mnt/floppy_test
<br>&nbsp; ### Mount the floppy disk
<br>mount /dev/fd0 /mnt/floppy_test
<br>&nbsp; ### Edit the lilo.conf file and put "ramdisk=35000" in the lilo.conf
file, mine looks like
<p>boot=/dev/fd0
<br>timeout=100
<br>message=/boot/message
<br>prompt
<br>image=/vmlinuz-2.2.12-32
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label=linux
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ### Change
/dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root=/dev/hdc
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ramdisk=35000
<br>image=/vmlinuz-2.2.12-32
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label=rescue
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; append="load_ramdisk=2 prompt_ramdisk=1"
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root=/dev/fd0
<p>&nbsp;&nbsp; ### Now execute the lilo command on the floppy drive
<br>lilo -r /mnt/floppy_test
<br>&nbsp; ### Now umount the floppy disk
<br>umount /dev/fd0
<p>Now you have a bootable floppy disk that uses your cdrom as root.
<br>If you are going to burn the floppy disk image onto your cdrom using
mkisofs, then change lilo.conf to this,
<p>boot=/dev/hdc
<br>timeout=100
<br>message=/boot/message
<br>prompt
<br>image=/vmlinuz-2.2.12-32
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label=linux
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ### Change
/dev/hdc to /dev/hdb or /dev/hdd or wherever your cdrom is
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root=/dev/hdc
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ramdisk=35000
<p>&nbsp;&nbsp; ### After you umount the floppy disk, make an image of
the floppy disk to burn on a cdrom
<br>dd if=/dev/fd0 of=/tmp/Boot.image
<p>
<hr><a NAME="conclusions"></a>
<h1>
Conclusions and future articles</h1>
I wanted to make it easier to create bootable cdroms with a live filesystem.
From here, I will make an article on how to use a bootable cdrom to
<ol>
<li>
Create installation cdroms to burn your image of an operating system to
your hard drive.</li>
<li>
How to use a bootable cdrom and a hard drive and/or NFS.</li>
<li>
Finish up my MILAS project. My MILAS project started when I needed a way
to configure custom-made computers that I used to sell (and probably will
again someday to help force competitors to do cool things).</li>
<li>
Make a more accurate Perl script to take the version of Linux you have
on your computer and put it on a cdrom. I will probably end up using
the iso9660 format for the cdrom. </li>
</ol>
I apologize for the roughness of this article. It was a pain in the butt
to figure out how to make bootable cdroms. I imagine other people have
documented it much better than I have. In my next article, I will clean
it up a lot.
<p>
<EM><a href="mailto:mark@tcu-inc.com">Mark Nielsen</a> works for
<a href="http://www.tcu-inc.com">The
Computer Underground</a> as a clerk and as a book binder at <a href="http://www.genericbooks.com">ZING</a>.
In his spare time, he does volunteer stuff, like writing articles for The
Linux Gazette and developing ZING's website.</EM>
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2000, Mark Nielsen<BR>
Published in Issue 54 of <i>Linux Gazette</i>, June 2000</H5>
<!-- *** END copyright *** -->
<!--startcut ==========================================================-->
<HR><P>
<CENTER>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="frost.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue54/nielsen.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../faq/index.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="okopnik.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>