![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 | |||
|
Way Too Much Ubuntu
![]() Join Date: Nov 2006
Location: Cairo, Egypt
Beans: 292
|
Transforming your Installation into a Live DVD/CD
This HOWTO is about making a live CD/DVD from the main system on your hard drive. This might be desired if you have customized your system and want to have it on CD. Another approach that will be discussed here is building your live CD/DVD from scratch. This will be done by building a new system using debootstrap. This is usefull if you want to build a clean live CD, or if you want to build a minimal rescue cd. (Consult Appendix.2 for more details about building a CD from scratch). The live CD is usually created with a filesystem called squashfs. Squashfs is read only compressed filesystem that allow us to squeeze our system into a single CD. Note that your system has to be about 2GB (this might need some trial an error) to produce a compressed image that fits on the CD. Quote:
What you need:
Outline of the steps: A. Prepare Our work environment. B. Copy the Source system to the target directory. Note: People building a live CD/DVD from scratch using debootstrap: This step and replaced with the instructions listed here. C. Chroot into the new system and make some modifications. D. Prepare The CD directory tree. E. Build the CD/DVD Appendix 1. Adapting this guide to Debian. Appendix 2. Building the live media form scratch using Debootstrap. Conventions used in this HOWTO:
A. Preparing the environment 1. Set some variables Code:
export WORK=~/work export CD=~/cd export FORMAT=squashfs export FS_DIR=casper The WORK Directory is where our temporary files and mount point will reside. The CD is the location of the CD tree. FORMAT is the filesystem type. We you are going to use a compressed squashfs FS_DIR is the location of the actual filesystem image within the cd tree. Replace only the values highlighted in Magenta. 2. Create the CD and the WORK directory structure: Code:
sudo mkdir -p ${CD}/{${FS_DIR},boot/grub} ${WORK}/rootfs
3. Install some packages on your current system: Code:
sudo apt-get update Code:
sudo apt-get install mkisofs grub squashfs-tools qemu qemu is optional. It is only needed for testing the cd before burning it. It can be substituted with any other virtualization software like virtualbox. Quote:
B. Copy your installation into the new filesystem. Note: People building a live CD/DVD from scratch using debootstrap: skip this step and replace it with the instructions listed here. Code:
sudo rsync -av --one-file-system --exclude=/proc/* --exclude=/dev/*\
--exclude=/sys/* --exclude=/tmp/* --exclude=/home/*\
--exclude=/lost+found / ${WORK}/rootfs
Note: rsync is used instead of cp to take advantage of the --one-file-system and the --exclude options. If you have a separate boot partition you will have to copy it using the following command: Code:
sudo cp -av /boot/* ${WORK}/rootfs/boot
(Optional) Copy settings in your home dir: If you want to preseve your user account settings which are stored in your home directory, you can copy them to ${WORK}/rootfs/etc/skel/. But first we have to define what files we want to copy. For example I am using xcfe4 as my DE, and it stores all it settings in a directory called .config in my home directory, so I am going to add .config to the variable $CONFIG: Code:
CONFIG='.config .bashrc' Code:
cd ~ && for i in $CONFIG
do
sudo cp -rpv --parents $i ${WORK}/rootfs/etc/skel
done
C. Chroot into the new system and modify it: 1. Chroot into the copied system after mounting proc and dev: Note: People building a live CD/DVD from scratch using debootstrap: skip this step. Code:
sudo mount -o bind /dev/ ${WORK}/rootfs/dev
Code:
sudo mount -t proc proc ${WORK}/rootfs/proc
Code:
sudo mount -t sysfs sysfs ${WORK}/rootfs/sys
Code:
sudo chroot ${WORK}/rootfs /bin/bash
N.B: All commands in Blue are done within a chroot. Now you are within chroot environment, type the following command: Code:
LANG= Note: People building a live CD/DVD from scratch using debootstrap: Resume the steps of the guide here. 2. Install Packages Essential for live CD: Code:
apt-get update Code:
apt-get install casper xresprobe discover1 & xresprobe are used for autodetectin hardware at startup. 3. (Optional) If you want your live cd to have an installer, install the Ubuntu installer: Code:
apt-get install ubiquity Quote:
(Optional Step)Install any packages you want to be in the CD. Some of the following packages are useful in emergency situations: Code:
sudo apt-get install gparted ms-sys testdisk wipe partimage xfsprogs reiserfsprogs jfsutils ntfs-3g ntfsprogs dosfstools mtools ms-sys: writing a Microsoft compatible boot record (MBR). testdisk: Partition scanner and disk recovery tool. wipe: Secure file deletion. partimage: backup partitions into a compressed image file (like norton ghost). xfsprogs reiserfsprogs jfsutils: Tools for handling different filesystems. mtools: Tools for manipulating MSDOS files Note: People building a live CD/DVD from scratch using debootstrap: Additional step right here. Look in appendix.2 for details. 4. Update the initramfs: Note: People building a live CD/DVD from scratch using debootstrap: Commands in this step are to be modified. Look in appendix.2 for details. First update modules.dep: Code:
depmod -a $(uname -r) Code:
update-initramfs -u -k $(uname -r) 5. Delete these files. Code:
for i in "/etc/hosts /etc/hostname /etc/resolv.conf /etc/timezone /etc/fstab /etc/mtab /etc/shadow /etc/shadow- /etc/gshadow /etc/gshadow- /etc/gdm/gdm-cdd.conf /etc/gdm/gdm.conf-custom /etc/X11/xorg.conf /boot/grub/menu.lst /boot/grub/device.map" do rm $i done 2>/dev/null 6. Clean apt cache Code:
apt-get clean 7. Clean some dirs and files: Code:
rm -r /tmp/* /root/* 2>/dev/null Code:
rm /boot/*.bak 2>/dev/null 8. Remove non system users Note: People building a live CD/DVD from scratch using debootstrap: skip this step. Code:
for i in `cat /etc/passwd | awk -F":" '{print $1}'`
do
uid=`cat /etc/passwd | grep "^${i}:" | awk -F":" '{print $3}'`
[ "$uid" -gt "999" -a "$uid" -ne "65534" ] && userdel --force ${i} 2>/dev/null
done
9. Clean the chroot environment form unnecessary files: Note: People building a live CD/DVD from scratch using debootstrap: skip this step. Code:
find /var/run /var/log /var/mail /var/spool /var/lock /var/backups /var/tmp -type f -exec rm {} \;
10. If you are using GDM recreate it's config file: Note: People building a live CD/DVD from scratch using debootstrap: skip this step. Code:
[ -f "/etc/gdm/factory-gdm.conf" ] && cp -f /etc/gdm/factory-gdm.conf /etc/gdm/gdm.conf 2>/dev/null 11. Create some files in /var/log: Note: People building a live CD/DVD from scratch using debootstrap: skip this step. Code:
for i in dpkg.log lastlog mail.log syslog auth.log daemon.log faillog lpr.log mail.warn user.log boot debug mail.err messages wtmp bootstrap.log dmesg kern.log mail.info
do
touch /var/log/${i}
done
12. Exit chroot Code:
exit D. Prepare The CD directory tree: 1. Copy the kernel, the updated initrd and memtest prepared in the chroot: Note: People building a live CD/DVD from scratch using debootstrap: Commands in this step are to be modified. Look in appendix.2 for details. Code:
sudo cp -vp ${WORK}/rootfs/boot/vmlinuz-$(uname -r) ${CD}/boot/vmlinuz
Code:
sudo cp -vp ${WORK}/rootfs/boot/initrd.img-$(uname -r) ${CD}/boot/initrd.gz
Code:
sudo cp -vp ${WORK}/rootfs/boot/memtest86+.bin ${CD}/boot
2. Generate manifest: Note: This step is only needed if you installed the Ubuntu installer ubiquity. This step generates two files (filesystem.manifest & filesystem.manifest-desktop). Code:
sudo chroot ${WORK}/rootfs dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee ${CD}/${FS_DIR}/filesystem.manifest
Code:
sudo cp -v ${CD}/${FS_DIR}/filesystem.manifest{,-desktop}
Code:
REMOVE='ubiquity casper user-setup discover1 xresprobe os-prober libdebian-installer4' Code:
for i in $REMOVE
do
sudo sed -i "/${i}/d" ${CD}/${FS_DIR}/filesystem.manifest-desktop
done
3. Unmount bind mounted dirs: Code:
sudo umount ${WORK}/rootfs/proc
Code:
sudo umount ${WORK}/rootfs/sys
Code:
sudo umount ${WORK}/rootfs/dev
4. Convert the directory tree into a squashfs: Code:
sudo mksquashfs ${WORK}/rootfs ${CD}/${FS_DIR}/filesystem.${FORMAT}
Note: Compression might incur a slight performace penalty. If you are using DVD and your overall system size is less than 4GB you don't have to use compression, instead you can use squashfs without compression by adding the -noI -noD -noF switches to mksquashfs. 5. Make Grub the bootloader of the CD Copy grub file: Code:
sudo find /boot /usr/lib/grub/ -iname 'stage2_eltorito' -exec cp -v {} ${CD}/boot/grub \;
Make the menu.lst Code:
sudo gedit ${CD}/boot/grub/menu.lst
Copy the following text into it and save it. Code:
# By default, boot the first entry. default 0 # Boot automatically after 30 secs. timeout 30 color cyan/blue white/blue title Start Linux in Graphical Mode kernel /boot/vmlinuz BOOT=casper boot=casper nopersistent rw quiet splash initrd /boot/initrd.gz title Start Linux in Safe Graphical Mode kernel /boot/vmlinuz BOOT=casper boot=casper xforcevesa rw quiet splash initrd /boot/initrd.gz title Start Linux in Text Mode kernel /boot/vmlinuz BOOT=casper boot=casper nopersistent textonly rw quiet initrd /boot/initrd.gz title Start Presistent Live CD kernel /boot/vmlinuz BOOT=casper boot=casper persistent rw quiet splash initrd /boot/initrd.gz title Start Linux Graphical Mode from RAM kernel /boot/vmlinuz BOOT=casper boot=casper toram nopersistent rw quiet splash initrd /boot/initrd.gz title Memory Test kernel /boot/memtest86+.bin title Boot the First Hard Disk root (hd0) chainloader +1 6. Calculate MD5 Code:
cd $CD && find . -type f -print0 | xargs -0 sudo md5sum | sudo tee ${CD}/md5sum.txt
E. Build the CD/DVD 1. Make the ISO file Code:
sudo mkisofs -b boot/grub/stage2_eltorito \ -no-emul-boot -boot-load-size 4 -boot-info-table \ -V "Custom Live CD" -cache-inodes -r -J -l \ -o ~/live-cd.iso $CD 2. Test the CD Test using qemu emulator Code:
qemu -cdrom ~/live-cd.iso -boot d Update: As noted by az in this post, while testing the iso with qemu sometimes it drops you to an initramfs shell because of a problem with qemu. This behaviour has been confirmed by other users. In this case it is advisable to retest the iso with another virtualization software like virtualbox or to burn the iso to REWRITABLE cd and test directly on your pc. 3. (Optional) Clean our workspace Code:
[ -d "$WORK" ] && rm -r $WORK $CD Final Notes:
Appendix 1. Adapting this guide to Debian This guide can be modified to apply to Debian systems as well. There are number of differeces between Ubuntu and Debian that we must take into account:
So in light of the points mentioned above we have to make the following modifications to adapt the guide to Debian:
Appendix 2. Building the live media form scratch using debootstrap. Instead of using your current installation to be the basis of you live CD, you can build a custom system from scratch into any directory in your system using debootstrap, and then use that as the basis of your CD. The modifications you have to make are:
Edit (1): 20/02/08
Update (2): 14/03/08 Fragadelic kindly posted this guide on his website. Fragadelic is the author of remastersys. Remastersys is a tool that can create a live CD/DVD in an automated manner as opposed to the step by step nature of this guide. Another advantage of remastersys is that it has a GUI for those who do not want to miss with the command line. Edit (3): 12/04/08 Correcting a typo in step E.2 as pointed out by vbgeek Edit (4): 21/04/08 Removed live-initramfs from the variable REMOVE (in step D.2) as pointed out by gjhicks Edit (5): 05/05/08 Removed the appendix of how to make the cd using a unix filesystem like ext2. This is now obsolete as you can use squashfs without compression by adding the -noI -noD -noF switches to mksquashfs. Last edited by capink; July 19th, 2009 at 02:06 PM.. |
|||
|
|
|
|
|
#2 |
|
First Cup of Ubuntu
![]() Join Date: Jan 2008
Location: Republic of Korea
My beans are hidden!
Ubuntu 7.10 Gutsy Gibbon
|
Re: How to make a live CD/DVD from your harddisk installation
정말 유용한 정보이군요.
감사합니다. Happy New Year! (7. Feb is Korean Traditional New Year's day
__________________
虛主하늘도깨비 |
|
|
|
|
|
#3 |
|
Just Give Me the Beans!
![]() Join Date: Feb 2008
Beans: 57
|
Re: How to make a live CD/DVD from your harddisk installation
Great post! Thanks. I was looking at switching back to Ubuntu and this seals it.
|
|
|
|
|
|
#4 |
|
Way Too Much Ubuntu
![]() Join Date: Nov 2006
Location: Cairo, Egypt
Beans: 292
|
Re: How to make a live CD/DVD from your harddisk installation
|
|
|
|
|
|
#5 |
|
Just Give Me the Beans!
![]() Join Date: Feb 2008
Beans: 57
|
Re: How to make a live CD/DVD from your harddisk installation
I'm using Gutsy 64 alternate install.
I've added the apps I need, my system is up to 2.5 GB so I'll use ext2, DVD. I'm on step C, but when I "sudo LANG= chroot ${WORK}/rootfs /bin/bash", I get "sudo: LANG=: command not found" error. I'll keep trying, but if you know the problem, that would help ( to resume, do I need to reset the variables at the beginning of step A ?) Last edited by RumorsOfWar; February 16th, 2008 at 02:52 PM.. |
|
|
|
|
|
#6 | |
|
Way Too Much Ubuntu
![]() Join Date: Nov 2006
Location: Cairo, Egypt
Beans: 292
|
Re: How to make a live CD/DVD from your harddisk installation
Quote:
Code:
sudo chroot ${WORK}/rootfs /bin/bash
Code:
LANG= You do not need to reset any of the variables as long as you are still working in the same terminal. |
|
|
|
|
|
|
#7 |
|
Just Give Me the Beans!
![]() Join Date: Feb 2008
Beans: 57
|
Re: How to make a live CD/DVD from your harddisk installation
And now I'm replying from my own live CD
![]() I think I messed up my first effort by missing some ext2 changes, so I redid it in squashfs. In step C, using 'LANG=' after chroot worked. I had to change a line at D/5 so grub set up for an x86_64-pc rather than i86, and this live cd environment hangs if I enable 3D. But this is very cool. I can restore or duplicate my Ubuntu setup faster, and without an internet. Thanks Capink If I may suggest, edit lines at C/1 and D/5 in the first post, and put a "*ext2" tag beside things that need appendix1. This tutorial is worthy of being Sticky Last edited by RumorsOfWar; February 17th, 2008 at 12:23 AM.. |
|
|
|
|
|
#8 | |
|
Way Too Much Ubuntu
![]() Join Date: Nov 2006
Location: Cairo, Egypt
Beans: 292
|
Re: How to make a live CD/DVD from your harddisk installation
Quote:
Glad it worked for you. Can you post the exact modification you did to menu.lst so that I can add it to my post (with credits ofcourse). Also, what do you think messed up for you in ext2? |
|
|
|
|
|
|
#9 | ||
|
Just Give Me the Beans!
![]() Join Date: Feb 2008
Beans: 57
|
Re: How to make a live CD/DVD from your harddisk installation
Quote:
Code:
sudo cp -pv /usr/lib/grub/x86_64-pc/* ${CD}/boot/grub
Code:
sudo cp -pv /usr/lib/grub/i386-pc/* ${CD}/boot/grub
Quote:
I just wasn't patient enough to read ahead and understand as much as I needed to. My bad. But a hint marker like "*ext2*" would have stopped me. *edit* Now I see you did have the line there. I may have had it right. Oh well, I'm still reading through it and seeing how it works. ![]() Last edited by RumorsOfWar; February 17th, 2008 at 12:19 PM.. |
||
|
|
|
|
|
#10 |
|
Spilled the Beans
![]() Join Date: Jul 2007
Location: Newcastle, Australia
Beans: 13
Xubuntu
|
Re: How to make a live CD/DVD from your harddisk installation
Thanks, capink. This is brilliant. I am pasting it into a customized script specifically for me, but leaving all your comments in the script.
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|