{"id":326,"date":"2009-04-21T18:26:32","date_gmt":"2009-04-21T12:56:32","guid":{"rendered":"http:\/\/brainstorms.in\/?p=326"},"modified":"2009-04-24T22:05:13","modified_gmt":"2009-04-24T16:35:13","slug":"building-an-ubuntu-live-cd-from-scratch","status":"publish","type":"post","link":"https:\/\/brainstorms.in\/?p=326","title":{"rendered":"Building an Ubuntu  Live CD from Scratch"},"content":{"rendered":"<p style=\"margin-bottom: 0cm;\" lang=\"en\">( This document was written in connection with the one day Live Cd workshop held at college of Engineering Attingal. )<\/p>\n<p lang=\"en\"><span style=\"font-size: medium;\"><strong>1.  Introduction<\/strong><\/span><\/p>\n<p lang=\"en\">This document describes how to build a minimal live CD based on ubuntu 8.10.. The most recent version of  this document can be found at http:\/\/brainstorms.in.<\/p>\n<p lang=\"en\"><span style=\"font-size: medium;\"><strong>2. System Requirements<\/strong><\/span><\/p>\n<ol>\n<li> A Host System with ubuntu 8.10 installed. ( Other \tversions will also work)<\/li>\n<li> Plenty of Disk space.<\/li>\n<li> A steady Internet  connection or access  to ubuntu \trepositories.<\/li>\n<li> Root access on the host system.<\/li>\n<\/ol>\n<p lang=\"en\"><span style=\"font-size: medium;\"><strong>3  Exploring an existing ubuntu CD.<\/strong><\/span><\/p>\n<p lang=\"en\">In order to understand the working of a live CD, let us look at an existing ubuntu CD<\/p>\n<p lang=\"en\">If you have the  CD with you , put it into your CD drive. If you have an image ,  mount it on the loop device.<\/p>\n<p lang=\"en\"># mount -o loop ubuntu-8.10-desktop-i386.iso  \/cdrom<\/p>\n<p lang=\"en\">\n<p lang=\"en\">The directory structure of a typical ubuntu CD look as below.<\/p>\n<p lang=\"en\">\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" valign=\"top\">\n<p lang=\"en\">autorun.inf  dists    isolinux    pics  preseed       \t\t\t      ubuntu     wubi.exe<\/p>\n<p lang=\"en\">casper       install  md5sum.txt  pool  \t\t\tREADME.diskdefines  umenu.exe<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\">\n<p lang=\"en\">The exe files and autorun.inf   are for installing under MS Windows. Some of the other files are self explanatory. Our main focus will be on isolinux and casper directories..<\/p>\n<p lang=\"en\">The isolinux directory contains files needed to boot from the live CD, Infact, isolinux belongs to a set of bootloaders written by Peter. H Anwin. The home page is here.  As I mentioned isolinux , is the bootloader.. If you look at  isolinux subdirectory, you will  find several files. Some of them will be  as shown below.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" valign=\"top\">\n<p lang=\"en\">isolinux.bin   isolinuc binary<\/p>\n<p lang=\"en\">isolinux.cfg    Configuration File<\/p>\n<p lang=\"en\">boot.cat          boot catlogue<\/p>\n<p lang=\"en\">bootlogo        Logo<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\">\n<p lang=\"en\">There are several  other files. They are mainly for providing language  support. ( Please feel free to  look at some of them).  The isolinux.cfg includes several other configuration files corresponding to differnt boot options. We  will write a simple  isolinux.cfg later.<\/p>\n<p lang=\"en\">\n<p lang=\"en\">The casper directory contains the following.<\/p>\n<p lang=\"en\">\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" valign=\"top\">\n<p lang=\"en\">filesystem.manifest          filesystem.squashfs  \t\t\tvmlinuz<\/p>\n<p lang=\"en\">filesystem.manifest-desktop  initrd.gz<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\">\n<p lang=\"en\">vmlinuz and initrd.gz are the kernel and ram image  from which isolinux will boot the system.<\/p>\n<p lang=\"en\">The filesystem.squashfs contains a compressed image of the filesystem. When we boot the live CD, this image will be uncompressed and moounted as the root filesystem.. All  remastering programs and custom distros  try to rebuild this image.. Filesystem,manifest and filesystem.manifest-desktop  are text files which contain a list of packages inside the squashfs image.<\/p>\n<p lang=\"en\">The squashfs image can be loop mounted like an iso image.<\/p>\n<p lang=\"en\"># mount -o loop filesystem.squashfs  \/mnt \/tmp<\/p>\n<p lang=\"en\">\n<p lang=\"en\"><span style=\"font-size: medium;\"><strong>4 Preparing the host system.<\/strong><\/span><\/p>\n<p lang=\"en\">Ensure that the Ubuntu 8.10 is installed on the host system. Log  to the host system  and update the system  using apt. (I am assuming that you have direct access to Internet..)<\/p>\n<p lang=\"en\">a) Install necessary packages<\/p>\n<p lang=\"en\">apt-get install syslinux squashfs-tools mkisofs sbm<\/p>\n<p lang=\"en\">b) Prepare a working directory<\/p>\n<p lang=\"en\">Open a terminal on the host system,  Become root.<\/p>\n<p lang=\"en\">$sudo su<\/p>\n<p lang=\"en\">#<\/p>\n<p lang=\"en\">Create a temporary work directory.<\/p>\n<p lang=\"en\"># mkdir work<\/p>\n<p lang=\"en\">Inside  work  create the following.<\/p>\n<p lang=\"en\"># mkdir work\/filesys<\/p>\n<p lang=\"en\">#mkdir work\/image<\/p>\n<p lang=\"en\">#mkdir  work\/image\/casper<\/p>\n<p lang=\"en\">#mkdir work\/image\/isolinux<\/p>\n<p>#mkdir work\/image\/install<\/p>\n<p lang=\"en\">We will be building the iso image from the image directory. We will populate the image directory one by one and finally build a  CD image. The filesys directory is a temporary  area where we will build  the root filesystem of the Live CD.<\/p>\n<p lang=\"en\">\n<p lang=\"en\">\n<p lang=\"en\">\n<p lang=\"en\">\n<p lang=\"en\"><span style=\"font-size: medium;\"><strong>5   Building a Squashfs image<\/strong><\/span><\/p>\n<p lang=\"en\">\n<p lang=\"en\">For  building the compressed root image,<\/p>\n<p lang=\"en\">we will build a  bare minimum filesystem under filesys  directory and then convert it into squashfs.<\/p>\n<p lang=\"en\">Step 1.<\/p>\n<p lang=\"en\">Install debootstrap on the host system<\/p>\n<p lang=\"en\"># apt-get install  debootstrap.<\/p>\n<p lang=\"en\">Debootstrap is a program to bootstrap a basic debian system.<\/p>\n<p lang=\"en\"># cd work<\/p>\n<p># debootstrap &#8211;arch i386 intrepid filesys<\/p>\n<p>This will create a bare minimum filesystem inside the filesys directory. If you look inside the filesys directory, you can see that the structure resembles root directory as shown below.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" valign=\"top\">bin   dev  home        lib    mnt  proc  sbin  sys  usr  vmlinuz<br \/>\nboot  etc  initrd.img  media  opt  root  srv   tmp  var<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Step 2<\/p>\n<p>Copy the \/etc\/resolv.conf and  \/etc\/apt\/sources.list to  the corresponding locations inside the filesys directrory.<\/p>\n<p># cp \/etc\/resolv.conf filesys\/etc\/resolv.conf<\/p>\n<p># cp \/etc\/apt\/sources.list filesys\/etc\/apt\/sources.list<br \/>\nStep 3<\/p>\n<p>Now, we will  use chroot command to change the root directory to filesys.<\/p>\n<p># chroot filesys<\/p>\n<p>You will get back the #  prompt. However  inside this terminal you will be referring to  filesys directory as \/ .<br \/>\nNow run the following  ( You are inside chroot )<br \/>\n# mount \/proc<\/p>\n<p># mount \/sys<\/p>\n<p># mount -t devpts none \/dev\/pts<br \/>\nThe above commands mount the respective directories inside chroot.<br \/>\nStep 4<\/p>\n<p>Update the system. (Note that we are inside the chroot jail  not on your host system.)<\/p>\n<p># apt-get update<\/p>\n<p lang=\"en\">To avoid locale issues and in order to import GPG keys  set  the following shell variables.<\/p>\n<p>#export HOME=\/root<\/p>\n<p>#export LC_ALL=C<br \/>\nStep 5<\/p>\n<p lang=\"en\">Install packages needed for Live System:<\/p>\n<p>#apt-get install &#8211;yes ubuntu-standard casper<\/p>\n<p>#apt-get install &#8211;yes discover\u00a0 laptop-detect os-prober<\/p>\n<p>#apt-get install &#8211;yes linux-generic<\/p>\n<p>The package ubuntu-standard  will install most of the packages needed for a working installation.<\/p>\n<p>The other packages are mainly for hardware detection. Linux generic will  install the kernel..<\/p>\n<p lang=\"en\">Step 6<\/p>\n<p lang=\"en\">Install additional\u00a0 packages.<\/p>\n<p lang=\"en\">You can get the list of currently installed packages with<\/p>\n<p lang=\"en\"># dpkg -l<\/p>\n<p lang=\"en\">You can remove some of the packages and try to save space.<\/p>\n<p lang=\"en\">Step 7<\/p>\n<p lang=\"en\">Cleanup  the unwanted files.<\/p>\n<p>#apt-get clean<br \/>\n#rm -rf \/tmp\/*<br \/>\n#rm \/etc\/resolv.conf<br \/>\n#umount -l -f \/proc<\/p>\n<p>#umount -l -f \/sys<\/p>\n<p>#umount \/dev\/pts<\/p>\n<p>#exit<\/p>\n<p>Now you are out of chroot and your filesys  directoy is ready to be compressed into a squashfs image.<\/p>\n<p>Step 8<\/p>\n<p># mksquashfs filesys  image\/casper\/filesystem.squashfs -e filesys\/boot<\/p>\n<p>Note: If the system you are building will only be used as a live system and you will never use it to install, you can exclude the \/boot folder. The live system boots from outside the chroot and so the \/boot folder is not used. If you will be using ubiquity to install the custom-built system, you will need to keep the \/boot folder. Use this instead of the previous command to preserve the \/boot folder.<\/p>\n<p># mksquashfs filesys  image\/casper\/filesystem.squashfs.<\/p>\n<p><span style=\"font-size: medium;\"><strong>6 Populate rest of the casper directory<\/strong><\/span><\/p>\n<p>Step 1<\/p>\n<p>Copy kernel and initrd image.<\/p>\n<p>#cp filesys\/boot\/vmlinuz-2.6.**-**-generic image\/casper\/vmlinuz<\/p>\n<p># cp filesys\/boot\/initrd.img-2.6.**-**-generic image\/casper\/initrd.gz<\/p>\n<p>Step 2<\/p>\n<p lang=\"en\">Create manifest:<\/p>\n<p lang=\"en\">Run the following  commands.<\/p>\n<pre lang=\"en\"># chroot filesys  dpkg-query -W --showformat='${Package} ${Version}\\n' |  tee image\/casper\/filesystem.manifest<\/pre>\n<p>#cp -v image\/casper\/filesystem.manifest{,-desktop}<br \/>\n# REMOVE=&#8217;ubiquity casper live-initramfs user-setup discover\u00a0 xresprobe os-prober libdebian-installer4&#8242;<br \/>\n# for i in $REMOVE<\/p>\n<p>do<\/p>\n<p>sed -i &#8220;\/${i}\/d&#8221; image\/casper\/filesystem.manifest-desktop<\/p>\n<p>done<\/p>\n<p style=\"margin-bottom: 0.5cm;\" lang=\"en\">Now all the files in the Casper directory are ready.<\/p>\n<p style=\"margin-bottom: 0.5cm;\" lang=\"en\"><span style=\"font-size: medium;\"><strong>7 Building  the isolinux directory<\/strong><\/span><\/p>\n<p style=\"margin-bottom: 0.5cm;\" lang=\"en\">The isolinux directory contains files needed for booting the live CD.<\/p>\n<p>Step 1<\/p>\n<p><span lang=\"en\"> Copy isolinux and  memtest to isolinux directory<\/span><br \/>\n<span lang=\"en\">#cp \/usr\/lib\/syslinux\/isolinux.bin image\/isolinux\/<\/span><\/p>\n<p><span lang=\"en\">#cp \/boot\/memtest86+.bin image\/install\/memtest<\/span><br \/>\n<span lang=\"en\">#cp \/boot\/sbm.img image\/install\/<\/span><br \/>\n<span lang=\"en\">Step 2<\/span><\/p>\n<p lang=\"en\">Create an isolinux.txt file in image\/isolinux to display at boot time.<\/p>\n<p lang=\"en\">Eg.<\/p>\n<p style=\"margin-bottom: 0cm;\" lang=\"en\">\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" valign=\"top\">This is a Live CD created at College of Engineering Attingal.For the default live system, enter &#8220;live&#8221;.<br \/>\nTo verify the CD for errors, enter &#8220;check&#8221;.<br \/>\nTo run memtest86+, enter &#8220;memtest&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\">\n<p>Step 2a  (optional)<\/p>\n<p>If you put the name of a speacilly encoded image file file in the beginning of isolinux.txt ,it will be displayed when we boot up.<\/p>\n<p>^Xsplash.rle<\/p>\n<p>The filename should be preceded by  ^X .<\/p>\n<p>( To enter <tt><span lang=\"en\">^X in  vi editor, do ctrl-V and follow with ctrl-X). <\/span><\/tt><\/p>\n<p lang=\"en\"><tt>To create the splash.rle file, create an image 480 pixels wide, and convert it to 15 colors, indexed, using the gimp. Save it as .bmp.<\/tt><\/p>\n<p lang=\"en\"><tt>Install the netpbm package.<\/tt><\/p>\n<p lang=\"en\"><tt>#apt-get install netpbm<\/tt><\/p>\n<p lang=\"en\"><tt>#bmptoppm splash.bmp &gt; splash.ppm   <span lang=\"en\">#ppmtolss16 '#ffffff=7' &lt; splash.ppm &gt; splash.rle<\/span><\/tt><\/p>\n<p lang=\"en\"><tt>Step 3<\/tt><\/p>\n<p lang=\"en\"><tt>Create an isolinux.cfg file in image\/isolinux\/\u00a0 \/usr\/share\/doc\/syslinux\/syslinux.doc is an idea place to start\u00a0 looking for information on\u00a0 various\u00a0 configuration options. Here is an example\u00a0 that you can use as a starting point.<br \/>\n<\/tt><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<tbody>\n<tr>\n<td>DEFAULT live<br \/>\nLABEL live<br \/>\nmenu label ^Start or install Ubuntu<br \/>\nkernel \/casper\/vmlinuz<br \/>\nappend  file=\/cdrom\/preseed\/ubuntu.seed boot=casper initrd=\/casper\/initrd.gz quiet splash &#8212;<br \/>\nLABEL check<br \/>\nmenu label ^Check CD for defects<br \/>\nkernel \/casper\/vmlinuz<br \/>\nappend  boot=casper integrity-check initrd=\/casper\/initrd.gz quiet splash &#8212;<br \/>\nLABEL memtest<br \/>\nmenu label ^Memory test<br \/>\nkernel \/install\/memtest<br \/>\nappend &#8211;<br \/>\nLABEL hd<br \/>\nmenu label ^Boot from first hard disk<br \/>\nlocalboot 0x80<br \/>\nappend &#8211;<br \/>\nDISPLAY isolinux.txt<br \/>\nTIMEOUT 300<br \/>\nPROMPT 1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\">\n<p lang=\"en\"><span style=\"font-size: medium;\"><tt><strong>8 Create miscellaneous  files<\/strong><\/tt><\/span><\/p>\n<p lang=\"en\"><tt>Step 1<\/tt><\/p>\n<p lang=\"en\"><tt>Create a diskdefines:<\/tt><\/p>\n<p><tt>vi  image\/README.diskdefines<\/tt><\/p>\n<p lang=\"en\"><tt>example:<\/tt><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\" bordercolor=\"#000000\">\n<col width=\"256\"><\/col>\n<tbody>\n<tr>\n<td width=\"100%\" height=\"14\" valign=\"top\">#define DISKNAME  Ubuntu 8.10 &#8220;Intrepid&#8221; &#8211; Release i386 **Remix**<\/p>\n<p>#define TYPE  binary<\/p>\n<p>#define TYPEbinary  1<\/p>\n<p>#define ARCH  i386<\/p>\n<p>#define ARCHi386  1<\/p>\n<p>#define DISKNUM  1<\/p>\n<p>#define DISKNUM1  1<\/p>\n<p>#define TOTALNUM  0<\/p>\n<p>#define TOTALNUM0  1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p lang=\"en\"><tt>Step 2<\/tt><\/p>\n<p lang=\"en\"><tt>Calculate MD5<\/tt><\/p>\n<p><tt># cd image &amp;&amp; find . -type f -print0 | xargs -0 md5sum &gt; md5sum.txt<\/tt><\/p>\n<p><strong><tt>9 Create and Test the CD image<\/tt><\/strong><\/p>\n<p lang=\"en\"><tt>Create iso image using the following command<\/tt><\/p>\n<p lang=\"en\">\n<p><tt><br \/>\n<\/tt><\/p>\n<p><tt>#mkisofs -r -V \"MyUbuntu\" -cache-inodes -J -l -b isolinux\/isolinux.bin -c isolinux\/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ..\/ubuntu-remix.iso .<\/tt><\/p>\n<p><tt># cd ..<\/tt><\/p>\n<p lang=\"en\"><tt>The boot.cat file will be automatically created.<\/tt><\/p>\n<p lang=\"en\"><tt>Now, the image is ready for testing. You can install virtual box and mount the image as a cdrom and try booting from it.<\/tt><\/p>\n<p lang=\"en\">\n<h2><tt>10 To Do<\/tt><\/h2>\n<p><tt>Installing the live CD  into a hard disk<\/tt><\/p>\n<p><tt>Ubiquity.<\/tt><\/p>\n","protected":false},"excerpt":{"rendered":"<p>( This document was written in connection with the one day Live Cd workshop held at college of Engineering Attingal. ) 1. Introduction This document describes how to build a minimal live CD based on ubuntu 8.10.. The most recent version of this document can be found at http:\/\/brainstorms.in. 2. System Requirements A Host System&hellip; <a href=\"https:\/\/brainstorms.in\/?p=326\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Building an Ubuntu  Live CD from Scratch<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-326","post","type-post","status-publish","format-standard","hentry","category-computers","category-gnulinux"],"_links":{"self":[{"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/posts\/326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brainstorms.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=326"}],"version-history":[{"count":22,"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":345,"href":"https:\/\/brainstorms.in\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions\/345"}],"wp:attachment":[{"href":"https:\/\/brainstorms.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brainstorms.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brainstorms.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}