Use libguestfs to edit a CD ISO

If you want to install a virtual machine from a CD, but you need to pass extra parameters to the Linux kernel, how can you do it?

Virt-install has an option to pass extra parameters to the kernel, but it doesn’t work with CD images because Linux CDs contain their own boot configuration system called ISOLINUX. Of course you can manually type in the extra parameters at the boot prompt, but that cannot be automated.

I was asked today can we use libguestfs to edit the ISOLINUX configuration inside the ISO directly? My first answer was yes, just do:

guestfish -a boot.iso -m /dev/sda edit /isolinux/isolinux.cfg

Unfortunately this doesn’t work for CD ISOs formatted using the standard ISO9660 filesystem. The kernel driver that guestfish uses is read-only, and you’ll get an error when the edit command tries to save the file. (As an aside, it should just work on UDF-formatted ISOs such as DVD images, but I didn’t try it).

Still, all is not lost and we can use guestfish to make the edit and still not require root. We just have to unpack the ISO, make the edit, and pack it up again, like this:

mkdir /tmp/iso
cd /tmp/iso
guestfish -a ../boot.iso -m /dev/sda tar-out / - | tar xvf -
vi isolinux/isolinux.cfg
mkisofs [flags - see comments] -o ../newboot.iso .


Filed under Uncategorized

6 responses to “Use libguestfs to edit a CD ISO

  1. Jesse Keating

    Perhaps you were just trying to be brief, but if you want that boot.iso to be actually bootable, you’ll need to pass a lot more flags to mkisofs, and those flags differ based on which arch you want it to be bootable on.

  2. rich

    That’s true Jesse – I elided a lot of the mkisofs flags needed to make it actually boot, actually because I lost the shell history of the final command which worked 😦

  3. Ron Yorston

    I have a small utility that replaces files in ISO filesystem images (under some constraints):

    Saves having to run mkisofs.

  4. rich

    Nice – so you could use guestfish to extract the file, and isocp to copy it back, something like:

    guestfish [...] cat /some/file > file
    vi file
    isocp [...]

    An additional complication with some live CDs is that the live image is “wrapped” in multiple layers. IIRC it was something like ISO9660 -> squashfs -> ext3 filesystem image.

  5. Alan Pevec

    For we created a script for crack-opening Fedora LiveCDs:;a=blob;f=edit-livecd;hb=refs/heads/next

    It has one issue which I need yet to investigate: repackaging the ISO increases its size for few MBs:

    Did you see the same effect with boot.iso?

  6. Pingback: Unpack the “Russian doll” of a F11 live CD « Richard WM Jones

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.