- Loading...
- No images or files uploaded yet.
|
|
Remastersys Capink Transforming your Installation Manually into a Live DVD/CD
by capink from the Ubuntu Forums
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. It can be useful also if you want to create a recovery CD from scratch, as you can make a minimal system using debootstrap and transform it into a live CD.
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. Ofcourse compression incurs performance penalties. If you are using DVD and your installation is less than 4GB you don't have to use compression, instead you can use ordinary unix (e.g ext2) filesystem as pointed out at the end of this guide. Quote:
What you need:
Outline of the steps:
A. Prepare Our work environment.
B. Copy the Source system to the target directory.
C. Chroot into the new system and make some modifications.
D. Prepare The CD directory tree.
E. Build the CD/DVD
Appendix 1. Using a non compressed filesystem. Appendix 2. Adapting this guide to Debian. Appendix 3. 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 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.
< People opting for ext2 look at Appendix.1 for modification of this step >
UPDATE: Using ext2 is not necessary as you can use squashfs without compression. See appendix 1 for more details
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 the source system: Code:
sudo apt-get update Code:
sudo apt-get install mkisofs grub squashfs-tools linux-ubuntu-modules-$(uname -r) 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.
linux-ubuntu-modules-$(uname -r) is only needed for Ubuntu Gutsy and later. If using an Ubuntu version prior to Gutsy omit this package as it is part of the main kerenl package.
< People opting for ext2 look at Appendix.1 for additional step to done right here >.
UPDATE: Using ext2 is not necessary as you can use squashfs without compression. See appendix 1 for more details
B. Copy your installation into the new filesystem. Code:
sudo rsync -av --one-file-system --exclude=/proc/* --exclude=/dev/*\ 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:
C. Chroot into the new system and modify it:
1. Chroot into the copied system after mounting proc and dev: Code:
CONFIG='.config .bashrc' Now, Copy the CONFIG files using the following command: Code:
cd ~ && for i in $CONFIG
Code:
sudo mount -o bind /dev/ ${WORK}/rootfs/dev Code:
sudo mount -t proc proc ${WORK}/rootfs/proc 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=
2. Install Packages Essential for live CD: Code:
apt-get update Code:
apt-get install casper discover1 xresprobe casper contain the live scirpts. 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
(Optional Step)Install any packages you want to be in the CD. Some of the following packages are useful in emergency situations:
sudo apt-get install gparted ms-sys testdisk wipe partimage xfsprogs reiserfsprogs jfsutils ntfs-3g ntfsprogs dosfstools mtools[/code]
gparted: patitioning tool. It is automatically installed as a dependecy of ubiquity.
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
4. Update the initramfs:
First update modules.dep: Code:
depmod -a $(uname -r)
Code:
update-initramfs -u -k $(uname -r) As already metioned above, the initramfs is reponsible for much of the preparation required at the boot time of the CD/DVD. The updated initramfs now contain the live scirpts installed with casper.
5. Remove non system users Code:
for i in `cat /etc/passwd | awk -F":" '{print $1}'` Non-system users are users created by you that have user id more than 999.
6. 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" These files are not needed in the CD/DVD. some of them are could interfer with the CD/DVD boot process. (e.g. shadow and gdm.conf-custom can interfere with autologin).
7. Clean the chroot environment form unnecessary files: Code:
apt-get clean Code:
find /var/run /var/log /var/mail /var/spool /var/lock /var/backups /var/tmp -type f -exec rm {} \; Code:
rm -r /tmp/* /root/* 2>/dev/null
8. If you are using GDM recreate it's config file: Code:
Sometimes a customized /etc/gdm/gdm.conf can interfere with the live CD/DVD autologin.
9. Create some files in /var/log: 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 Most of these files are log files that have been cleaned in step 7. We created an empty files in their place to prevent the system from complaining at boot.
10. Exit chroot Code:
exit
D. Prepare The CD directory tree:
1. Copy the kernel, the updated initrd and memtest prepared in the chroot: 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).
3. Unmount bind mounted dirs: 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 live-initramfs user-setup discover1 xresprobe os-prober libdebian-installer4' Code:
for i in $REMOVE These two files are used by the ubiquity installer when installing to harddisk. These two files are just lists of packages. Ubiquity compares these two files and removes packages unique to filesystem.manifest. This way when installing to harddisk, packages like casper which is only useful in a live CD/DVD are removed. These packages that will be removed at install are defined in the variable $REMOVE Code:
sudo umount ${WORK}/rootfs/dev ${WORK}/rootfs/proc
4. Convert the directory tree into a squashfs: Code:
sudo mksquashfs ${WORK}/rootfs ${CD}/${FS_DIR}/filesystem.${FORMAT} Note: Make sure the resulting file size can fit into your live media.
< People opting for ext2 look at Appendix.1 for modification of this step >
UPDATE: Using ext2 is not necessary as you can use squashfs without compression. See appendix 1 for more details
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.
6. Calculate MD5 Code:
E. Build the CD/DVD
1. Make the ISO file Code:
sudo mkisofs -b boot/grub/stage2_eltorito \
2. Test the CD
Test using qemu emulator Code:
qemu -cdrom ~\live-cd.iso -boot d Or use any other virtualization program you like.
3. (Optional) Clean our workspace
Final Notes: Code:
[ -d "$WORK" ] && rm -r $WORK $CD Note: If you are using ext2 instead of squashfs you may want to skip this step. Keeping these files in place will be handy whenever you update your CD. UPDATE: Using ext2 is not necessary as you can use squashfs without compression. See appendix 1 for more details
Appendix 1. Building the CD/DVD using a non compressed filesystem (e.g. ext2)
Update: You can use squashfs without compression by adding the -noI -noD -noF switches to mksquashfs. This is easier than using a unix filesystem. It also has the advantage that you do not have to predict the size of the system in advance, which is needed for ext2 in order to create a virtual filesystem with enough space ( with squashfs you do not need to create a virtual filesystem, you just use mksquashfs to create the squashfs form a directory tree ). I have not tried this option yet. But I imagine it would make using a unix filesystem totally unnecessary.
Instead of using squashfs for the live DVD filesystem you can use an ordinary unix filesystem like ext2.
Advantages of using a unix filesystem:
- The CD/DVD will be faster than a CD/DVD with a compressed fileystem. - Easier update of the live media provided you have not cleaned your workspace. An ordinary filesystem can be remounted and modified, then you can recreate the ISO image. Squashfs on the other hand, is a read only filesystem so it not as easy to update.
Disadvantages of using a unix filesystem:
- You lose the advantages of filesystem compression. So you will end up with large image. - You need a DVD unless you are building a minimal system that can fit within a CD without compression (e.g. a non graphical rescue disk). - Your system size cannot exceed 4GB as that is the maximum filesize supported by ISO9660. Of course this also applies when using squahsfs. But the differece is that a 4GB squashfs can contain roughly 12GB of data within it.
Note: If you are opting for the non compressed filesystem, it makes sesne to go for ext2 instead of ext3. It does not make sense to user a journaling filesystem with it's overhead in a read only media
To use ext2 instead of squashf follow the same steps above with the following modifications:
NOTE: The only filesystem I have tried is ext2. I have not tried any other filesystem and I do not know if they will work.
Appendix 2. 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 3. Building the live media form Debootstrap installed system.
Instead of using your current installation to be the basis of you live CD, you can install a custom system 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
Replace ~/debootstrap/* with the path of the debootstrap installed system.[/list]
Edit (1): 20/02/08
Edit (2): 22/02/08 If you want a non compressed filesystem (in case of DVD), using a unix filesystem like ext2 is not recommended anymore as you can use squashfs without compression by adding the -noI -noD -noF switches to mksquashfs. The option for creating ext2 filesystem is still present in the guide but with notes to use an uncom |
Comments (0)
You don't have permission to comment on this page.