Mar 2, 2012

ISO image editing

Recently I had to work with extracting and editing an existing Linux installation CD, and then to create my own image. To make it easier for those in my situation (and to make it easier for me to remember), here is my solution!!

Extracting CD for editing

You can directly extract the contents of a CD using the rsync command:

rsync -av /cdrom/ /opt/cd-image
Or, if you are using an ISO image, just mount the .iso and copy the contents directly to your working directory:
mount -o loop /path/to/iso /some/mountpoint
cp -rT /some/mountpoint /opt/cd
Creating boot-able CD from directory

This command will create a CD that is boot-able by most systems. If you don't want to create a boot-CD, you can skip most of the options in between -V and -o options. Anyway, the solution!

#!/bin/bash
#
# CD image name
IMAGE=bootcd.iso
# The build directory (where you extracted the CD earlier)
BUILD=/opt/cd/
#
# Create the bootable CD
mkisofs -r -V "AssetOS" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o $IMAGE $BUILD

Some hints to save you going through man pages:
  • -b parameter requires the location of the El Torito boot image. In the above command the location of this image is relative to the $BUILD directory
  • -c parameter requires the location of the boot catalog. Without this catalog the CD will not be bootable
  • -J parameter creates Joliet records in addition to standard ISO9660 filenames. This is useful only if the CD will be used on Windows systems.
  • -l parameter allows for the full length filenames
  • -r sets the permissions of all the files on the CD into values that are useful for future users of the system (i.e. GUID and UID are not set to something unusable on a different system)
  • -cache-inodes determines what the system should do with file links. In this case, the CD will have the same links as on the original filesystem.

No comments:

Post a Comment

Thanks for contributing!! Try to keep on topic and please avoid flame wars!!