Difference between revisions of "Building a Live CD"

From ArchWiki
Jump to: navigation, search
(Created Category Association)
 
(Added initial content)
Line 1: Line 1:
 
[[Category:CD/DVD]]
 
[[Category:CD/DVD]]
 +
 +
=== How to build your own live CD===
 +
 +
====1. Motivation - Why?====
 +
To have a bootable version of Arch Linux running totally off a CD, is useful in many ways. It can be made to rescue your HD system, test new machines / hardwares if Linux compatible, keep an updated installer with latest packages, or make a demo CD to show your projects, and much more.
 +
 +
====2. Before we start - What you'll need====
 +
A. To create an iso, format a filesystem, and to resize an image download \"cdrtools\" and \"e2fsprogs\" packages.
 +
 +
<verbatim>
 +
# pacman -S cdrtools
 +
# pacman -S e2fsprogs
 +
</verbatim>
 +
 +
B. Free hard disk space:
 +
* 1 fresh partition to install the distro.
 +
* 1 folder in your active partition to copy the distro to be put on the CD.
 +
 +
C. A CD-RW to test burning various images and a CD burner.
 +
D. Install CD burning package (if you don't know what package to install, try \"k3b\").
 +
 +
<verbatim>
 +
# pacman -S k3b
 +
</verbatim>
 +
 +
==== 3. Steps involved - Overview====
 +
Arch Linux is an ideal distro for live CD with its lightweight and simplicity. With a small number of packages a bootable CD can be created and use as a base for whatever usage you plan to use the live CD.
 +
 +
* <i>3.1. Install system and packages to a new partition you want in live CD.</i>
 +
 +
* <i>3.2. In your active partition make one folder and two sub-folders for stuff to be put in the live CD.</i>
 +
 +
* <i>3.3. Install isolinux.</i>
 +
 +
* <i>3.4. Building an initial RAM Disk (miniroot).</i>
 +
 +
* <i>3.5. Create an iso image.</i>
 +
 +
* <i>3.6. Burn image in CD.</i>
 +
 +
==== 4. Steps involved - Details====
 +
As an example, here we are creating a mini Arch Linux live CD (110MB). It is based on packages installed from Arch Linux's CD installer ver. 0.5.
 +
 +
==== 4.1 (3.1). Boot with Arch Linux CD installer and install the base packages.====
 +
 +
When the packages are installed, install the kernel but don't install LILO or Grub. You can also copy your own kernel image (/boot/vmlinuz), and related modules (/lib/modules/2.x.x) from your active partition. To boot the new install, configure lilo.conf or grub in your active partition.
 +
 +
<b>Hint:</b><small> For test purpose, to check for errors in the booting process, in your active partition mount the new partition and edit /etc/rc.local with the following lines to pause before login:<br></small>
 +
<verbatim>
 +
echo \"Press any key to continue...\"
 +
read KEY
 +
</verbatim>
 +
<small><b>NOTE:</b> Don't forget to remove the pause!!</small>
 +
 +
==== 4.2 (3.2). In your active partition, in /root make one folder \"<i>mylivecd</i>\" and two sub-folders: \"<i>isolinux</i>\" and \"<i>system</i>\" (any names can be used).====
 +
 +
<verbatim>
 +
# cd /root
 +
# mkdir mylivecd
 +
# cd mylivecd
 +
# mkdir isolinux
 +
# mkdir system
 +
</verbatim>
 +
 +
==== 4.3 (3.3). Install isolinux. Copy it from an existing live CD.====
 +
 +
==== 1. Download \"<i>isolinux.bin</i>\" and \"<i>boot.cat</i>\" to /root/mylivecd/isolinux/ :====
 +
http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/isolinux/
 +
 +
==== 2. Create boot message \"<i>boot.msg</i>\" (text file) and include a short description about the live CD. Save the file in /root/mylivecd/isolinux/. Copy this text to boot.msg:====
 +
 +
<verbatim>
 +
This is a Live CD test ver. 0.1.
 +
F1 - boot message
 +
F2 - package list
 +
 +
Press Enter
 +
</verbatim>
 +
 +
==== 3. Create \"<i>isolinux.cfg</i>\" (text file) and include the following text. Save the file in /root/mylivecd/isolinux/.====
 +
 +
<verbatim>
 +
prompt 1
 +
timeout 0
 +
display boot.msg
 +
F1 boot.msg
 +
F2 package.txt
 +
default vmlinuz initrd<code>miniroot.gz init</code>/sbin/init ramdisk''size<code>100000 load''ramdisk</code>1 prompt_ramdisk<code>0 vga</code>788 root=/dev/ram0
 +
</verbatim>
 +
 +
==== 4.4 (3.4). Build one miniroot image. Miniroot is loaded in RAM during booting and operates same as in HD. Use Ext2 filesystem.====
 +
 +
<b>NOTE:</b> Miniroot setup depends on /etc/inittab, /etc/rc.sysinit, /etc/rc.multi, and /etc/rc.shutdown. Before building the miniroot image, study these files and plan how they can be modified whenever is needed. In /sbin the following files are required: <br>
 +
http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/miniroot/init/sbin/
 +
 +
==== 1. Create \"<i>miniroot</i>\" (text file) in /root/mylivecd with Ext2 filesystem. The image size depends how much stuff you plan to include. In this sample we will make the image 15.8MB but its recommended to make the image as small as possible. When you are ready, mount the image in /mnt/xxx (here we mount in /mnt/image).====
 +
 +
<verbatim>
 +
# cd /root/mylivecd
 +
# touch miniroot
 +
# mkfs.ext2 miniroot 15840 (press \"y\" for each question)
 +
# mkdir /mnt/image
 +
# mount -t auto -o loop miniroot /mnt/image
 +
# rm -R /mnt/image/lost+found
 +
</verbatim>
 +
 +
<b>NOTE:</b> If you want to resize, run the following codes (e.g. to 11.5MB):
 +
 +
<verbatim>
 +
# e2fsck -f miniroot (press \"y\" for /lost+found not found.  Create<y>?)
 +
# resize2fs miniroot 11520
 +
</verbatim>
 +
 +
==== 2. Mount the new partition (e.g. /dev/hda3). Copy the below folders and files from the new partition to /mnt/image (use code \"cp -Ra\" to maintain the file permissions).====
 +
 +
<verbatim>
 +
# mkdir /mnt/tmp
 +
# mount /dev/hda3 /mnt/tmp
 +
# cp -Ra /mnt/tmp/bin /mnt/image/
 +
# cp -Ra /mnt/tmp/etc /mnt/image/
 +
# cp -Ra /mnt/tmp/sbin /mnt/image/
 +
# cp -Ra /mnt/tmp/tmp /mnt/image/
 +
# cp -Ra /mnt/tmp/var /mnt/image/
 +
</verbatim>
 +
 +
==== 3. Copy /usr and /lib/modules/2.x.x/, /lib/modules/evms/, /lib/modules/security/ to /root/mylivecd/system/ :====
 +
 +
<verbatim>
 +
# cp -Ra /mnt/tmp/usr /root/mylivecd/system/
 +
# cp -Ra /mnt/tmp/opt /root/mylivecd/system/
 +
# mkdir /root/mylivecd/system/lib
 +
# cp -Ra /mnt/tmp/lib/modules /root/mylivecd/system/lib/
 +
# cp -Ra /mnt/tmp/lib/evms /root/mylivecd/system/lib/
 +
# cp -Ra /mnt/tmp/lib/security /root/mylivecd/system/lib/
 +
</verbatim>
 +
 +
<b>NOTE</b>: If /bin and /sbin are too big you may consider using busybox:
 +
http://www.busybox.net/]http://www.busybox.net/<br>
 +
<b>Or</b> temporary folders, which will be removed or renamed at the boot by codes in /rc.sysinit. Here is an example:<br>
 +
http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/miniroot/init/sbin/rc.sysinit
 +
 +
==== 4. Create the following folders in /mnt/image and copy /mnt/tmp/lib files to  /mnt/image/lib/ (don't copy  /mnt/tmp/lib/module, ~/lib/evms and ~/lib/security):====
 +
 +
<verbatim>
 +
# cd /mnt/image
 +
# mkdir dev
 +
# mkdir home
 +
# mkdir lib
 +
# mkdir mnt/cdrom
 +
# mkdir mnt/floppy
 +
# mkdir root
 +
# mkdir proc
 +
# mkdir lib/modules
 +
# cd /mnt/tmp/lib/
 +
# cp -a l* /mnt/image/lib/
 +
</verbatim>
 +
 +
==== 5.With the folders /usr and /opt create links in /mnt/image/. Also link the /system/lib/modules/2.x.x/. Copy kernel image to /root/mylivecd/isolinux/ :====
 +
 +
<verbatim>
 +
# cd /mnt/image
 +
# ln -sf /mnt/cdrom/system/usr usr
 +
# ln -sf /mnt/cdrom/system/opt opt
 +
# cd /mnt/image/lib/modules/
 +
# ln -sf /mnt/cdrom/system/lib/modules/2.4.22 2.4.22
 +
# cd /mnt/image/lib/
 +
# ln -sf /mnt/cdrom/system/lib/evms evms
 +
# ln -sf /mnt/cdrom/system/lib/security security
 +
# cp /mnt/tmp/boot/vmlinuz /root/mylivecd/isolinux/
 +
</verbatim>
 +
 +
==== 5. Edit /mnt/image/etc/fstab as shown here below:====
 +
<verbatim>
 +
/dev/root      /      ext2    defaults 0 0
 +
none          /proc  proc    defaults 0 0
 +
/dev/floppy/0          /mnt/floppy  auto      user,rw,noauto,unhide    0      0
 +
/dev/cdroms/cdrom0    /mnt/cdrom  iso9660  ro,user,noauto,unhide  0      0
 +
</verbatim>
 +
 +
==== 6. Add the following line in rc.sysinit (after  line: stat_busy \"Mounting Local Filesystems\") in /mnt/image/etc/. This enables reading files from the CD's /system folder.====
 +
 +
<verbatim>
 +
/bin/mount /dev/cdroms/cdrom0 /mnt/cdrom -o ro -t iso9660
 +
</verbatim>
 +
 +
==== 7. Compress the miniroot and move miniroot.gz to /root/mylivecd/isoliux/====
 +
<verbatim>
 +
# cd /root/mylivecd/
 +
# umount /mnt/image
 +
# gzip -c miniroot >> miniroot.gz
 +
# mv miniroot.gz isolinux/
 +
</verbatim>
 +
 +
==== 4.5 (3.5). Before compiling iso, move the /root/mylivecd/miniroot to a safe place. Make  a temporary folder to put the iso image (not within /mylivecd). Run the following code (don't miss the \".\" at the end of line):====
 +
 +
<verbatim>
 +
# cd /root/mylivecd
 +
# mkdir /root/isotmp
 +
</verbatim>
 +
mkisofs -o /root/isotmp/test-livecd-0.1.iso -R -V \"Test 0.1\" -T -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -A \"Test Live CD 0.1\" .
 +
 +
==== 4.6 (3.6). Use CD-RW and burn /tmp/test-livecd-0.1.iso====
 +
We hope this document gets you started. Any comments or addition, please either edit the content or post reply (requires to register). Good luck!
 +
 +
------
 +
 +
=== ADDITIONAL INFO:===
 +
 +
Codes, content of AMLUG Live CD, and how to compress:
 +
http://www.amlug.net/new-projects/forum/index.php?showforum=23
 +
 +
How other distros build live CDs:
 +
http://www.babytux.org/articles/howto/how2livecd.php
 +
 +
----

Revision as of 16:44, 23 July 2005


Contents

How to build your own live CD

1. Motivation - Why?

To have a bootable version of Arch Linux running totally off a CD, is useful in many ways. It can be made to rescue your HD system, test new machines / hardwares if Linux compatible, keep an updated installer with latest packages, or make a demo CD to show your projects, and much more.

2. Before we start - What you'll need

A. To create an iso, format a filesystem, and to resize an image download \"cdrtools\" and \"e2fsprogs\" packages.

<verbatim>

  1. pacman -S cdrtools
  2. pacman -S e2fsprogs

</verbatim>

B. Free hard disk space:

  • 1 fresh partition to install the distro.
  • 1 folder in your active partition to copy the distro to be put on the CD.

C. A CD-RW to test burning various images and a CD burner. D. Install CD burning package (if you don't know what package to install, try \"k3b\").

<verbatim>

  1. pacman -S k3b

</verbatim>

3. Steps involved - Overview

Arch Linux is an ideal distro for live CD with its lightweight and simplicity. With a small number of packages a bootable CD can be created and use as a base for whatever usage you plan to use the live CD.

  • 3.1. Install system and packages to a new partition you want in live CD.
  • 3.2. In your active partition make one folder and two sub-folders for stuff to be put in the live CD.
  • 3.3. Install isolinux.
  • 3.4. Building an initial RAM Disk (miniroot).
  • 3.5. Create an iso image.
  • 3.6. Burn image in CD.

4. Steps involved - Details

As an example, here we are creating a mini Arch Linux live CD (110MB). It is based on packages installed from Arch Linux's CD installer ver. 0.5.

4.1 (3.1). Boot with Arch Linux CD installer and install the base packages.

When the packages are installed, install the kernel but don't install LILO or Grub. You can also copy your own kernel image (/boot/vmlinuz), and related modules (/lib/modules/2.x.x) from your active partition. To boot the new install, configure lilo.conf or grub in your active partition.

Hint: For test purpose, to check for errors in the booting process, in your active partition mount the new partition and edit /etc/rc.local with the following lines to pause before login:
<verbatim> echo \"Press any key to continue...\" read KEY </verbatim> NOTE: Don't forget to remove the pause!!

4.2 (3.2). In your active partition, in /root make one folder \"mylivecd\" and two sub-folders: \"isolinux\" and \"system\" (any names can be used).

<verbatim>

  1. cd /root
  2. mkdir mylivecd
  3. cd mylivecd
  4. mkdir isolinux
  5. mkdir system

</verbatim>

4.3 (3.3). Install isolinux. Copy it from an existing live CD.

1. Download \"isolinux.bin\" and \"boot.cat\" to /root/mylivecd/isolinux/ :

http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/isolinux/

2. Create boot message \"boot.msg\" (text file) and include a short description about the live CD. Save the file in /root/mylivecd/isolinux/. Copy this text to boot.msg:

<verbatim> This is a Live CD test ver. 0.1. F1 - boot message F2 - package list

Press Enter </verbatim>

3. Create \"isolinux.cfg\" (text file) and include the following text. Save the file in /root/mylivecd/isolinux/.

<verbatim> prompt 1 timeout 0 display boot.msg F1 boot.msg F2 package.txt default vmlinuz initrdminiroot.gz init/sbin/init ramdisksize100000 loadramdisk1 prompt_ramdisk0 vga788 root=/dev/ram0 </verbatim>

4.4 (3.4). Build one miniroot image. Miniroot is loaded in RAM during booting and operates same as in HD. Use Ext2 filesystem.

NOTE: Miniroot setup depends on /etc/inittab, /etc/rc.sysinit, /etc/rc.multi, and /etc/rc.shutdown. Before building the miniroot image, study these files and plan how they can be modified whenever is needed. In /sbin the following files are required:
http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/miniroot/init/sbin/

1. Create \"miniroot\" (text file) in /root/mylivecd with Ext2 filesystem. The image size depends how much stuff you plan to include. In this sample we will make the image 15.8MB but its recommended to make the image as small as possible. When you are ready, mount the image in /mnt/xxx (here we mount in /mnt/image).

<verbatim>

  1. cd /root/mylivecd
  2. touch miniroot
  3. mkfs.ext2 miniroot 15840 (press \"y\" for each question)
  4. mkdir /mnt/image
  5. mount -t auto -o loop miniroot /mnt/image
  6. rm -R /mnt/image/lost+found

</verbatim>

NOTE: If you want to resize, run the following codes (e.g. to 11.5MB):

<verbatim>

  1. e2fsck -f miniroot (press \"y\" for /lost+found not found. Create<y>?)
  2. resize2fs miniroot 11520

</verbatim>

2. Mount the new partition (e.g. /dev/hda3). Copy the below folders and files from the new partition to /mnt/image (use code \"cp -Ra\" to maintain the file permissions).

<verbatim>

  1. mkdir /mnt/tmp
  2. mount /dev/hda3 /mnt/tmp
  3. cp -Ra /mnt/tmp/bin /mnt/image/
  4. cp -Ra /mnt/tmp/etc /mnt/image/
  5. cp -Ra /mnt/tmp/sbin /mnt/image/
  6. cp -Ra /mnt/tmp/tmp /mnt/image/
  7. cp -Ra /mnt/tmp/var /mnt/image/

</verbatim>

3. Copy /usr and /lib/modules/2.x.x/, /lib/modules/evms/, /lib/modules/security/ to /root/mylivecd/system/ :

<verbatim>

  1. cp -Ra /mnt/tmp/usr /root/mylivecd/system/
  2. cp -Ra /mnt/tmp/opt /root/mylivecd/system/
  3. mkdir /root/mylivecd/system/lib
  4. cp -Ra /mnt/tmp/lib/modules /root/mylivecd/system/lib/
  5. cp -Ra /mnt/tmp/lib/evms /root/mylivecd/system/lib/
  6. cp -Ra /mnt/tmp/lib/security /root/mylivecd/system/lib/

</verbatim>

NOTE: If /bin and /sbin are too big you may consider using busybox: http://www.busybox.net/]http://www.busybox.net/
Or temporary folders, which will be removed or renamed at the boot by codes in /rc.sysinit. Here is an example:
http://amlug.bliss-solutions.org/live-cd/distfiles/0.5.1/miniroot/init/sbin/rc.sysinit

4. Create the following folders in /mnt/image and copy /mnt/tmp/lib files to /mnt/image/lib/ (don't copy /mnt/tmp/lib/module, ~/lib/evms and ~/lib/security):

<verbatim>

  1. cd /mnt/image
  2. mkdir dev
  3. mkdir home
  4. mkdir lib
  5. mkdir mnt/cdrom
  6. mkdir mnt/floppy
  7. mkdir root
  8. mkdir proc
  9. mkdir lib/modules
  10. cd /mnt/tmp/lib/
  11. cp -a l* /mnt/image/lib/

</verbatim>

5.With the folders /usr and /opt create links in /mnt/image/. Also link the /system/lib/modules/2.x.x/. Copy kernel image to /root/mylivecd/isolinux/ :

<verbatim>

  1. cd /mnt/image
  2. ln -sf /mnt/cdrom/system/usr usr
  3. ln -sf /mnt/cdrom/system/opt opt
  4. cd /mnt/image/lib/modules/
  5. ln -sf /mnt/cdrom/system/lib/modules/2.4.22 2.4.22
  6. cd /mnt/image/lib/
  7. ln -sf /mnt/cdrom/system/lib/evms evms
  8. ln -sf /mnt/cdrom/system/lib/security security
  9. cp /mnt/tmp/boot/vmlinuz /root/mylivecd/isolinux/

</verbatim>

5. Edit /mnt/image/etc/fstab as shown here below:

<verbatim> /dev/root / ext2 defaults 0 0 none /proc proc defaults 0 0 /dev/floppy/0 /mnt/floppy auto user,rw,noauto,unhide 0 0 /dev/cdroms/cdrom0 /mnt/cdrom iso9660 ro,user,noauto,unhide 0 0 </verbatim>

6. Add the following line in rc.sysinit (after line: stat_busy \"Mounting Local Filesystems\") in /mnt/image/etc/. This enables reading files from the CD's /system folder.

<verbatim> /bin/mount /dev/cdroms/cdrom0 /mnt/cdrom -o ro -t iso9660 </verbatim>

7. Compress the miniroot and move miniroot.gz to /root/mylivecd/isoliux/

<verbatim>

  1. cd /root/mylivecd/
  2. umount /mnt/image
  3. gzip -c miniroot >> miniroot.gz
  4. mv miniroot.gz isolinux/

</verbatim>

4.5 (3.5). Before compiling iso, move the /root/mylivecd/miniroot to a safe place. Make a temporary folder to put the iso image (not within /mylivecd). Run the following code (don't miss the \".\" at the end of line):

<verbatim>

  1. cd /root/mylivecd
  2. mkdir /root/isotmp

</verbatim> mkisofs -o /root/isotmp/test-livecd-0.1.iso -R -V \"Test 0.1\" -T -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -A \"Test Live CD 0.1\" .

4.6 (3.6). Use CD-RW and burn /tmp/test-livecd-0.1.iso

We hope this document gets you started. Any comments or addition, please either edit the content or post reply (requires to register). Good luck!


ADDITIONAL INFO:

Codes, content of AMLUG Live CD, and how to compress: http://www.amlug.net/new-projects/forum/index.php?showforum=23

How other distros build live CDs: http://www.babytux.org/articles/howto/how2livecd.php