5

I am trying to install an OS via console. This means modifying the ISO file for the OS. I unpacked it, edited the grub.cfg file i.e. just the section that is relevant, I left all other sections alone:

menuentry "Install Ubuntu Server" {
    set gfxpayload=keep
    linux   /install/vmlinuz  console=tty0 console=ttyS0,115200n8 ---
    initrd  /install/initrd.gz
    }

Then used Brasero to generate the new ISO. However, I get the error when I try to boot from this modified .iso:

Booting from DVD/CD.. Boot failed: Could not read from CDROM (code 0004) Booting from ROM... iPXE (PCI 0:12.0) starting execution...

The boot process stops here.

I have no idea where to start troubleshooting this.

P.S. I also tried the following grub.cfg (again, just the section that is relevant. The rest of the grub.cfg file was left alone):

menuentry "Install Ubuntu Server" {
    set gfxpayload=keep
    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed vga=normal console=tty0 console=ttyS0,115200n8 ---
    initrd  /install/initrd.gz
    }

Which is a direct copy from this GitHub repo:

No luck with that one either. Same error.

Giacomo1968
  • 58,727
Xoteric
  • 151

4 Answers4

9

Thanks Rohit, you prompted me to realise that Brasero isn't able to create bootable media.

The solution is simple, as per above... extract the iso we want to modify. Modify the grub.cfg file and then simply:

sudo apt install xorriso
grub-mkrescue -o <name of output iso>.iso <folder of the files we extracted from the iso>
Xoteric
  • 151
6

An ISO file is not like an APK or ZIP file. It is not an archive. Its a disk image.

Therefore you cant just edit it.

You need to extract all the files and then "reburn" them into a disk image.

Supposedly some tools can do the whole process. Have a look at tools such as ImgBurn, PowerISO and UltraISO.

Giacomo1968
  • 58,727
Rohit Gupta
  • 5,096
5

ISO format is rather complicated. To rebuild the ISO and keep it booting in both BIOS Legacy and UEFI mode, you need something like this:

dd if=original.iso bs=1 count=432 of=isohdpfx.bin

xorriso -as mkisofs -V "Mint" -o rebuilt.iso -J -joliet-long -cache-inodes -isohybrid-mbr isohdpfx.bin -b isolinux/isolinux.bin -c isolinux/boot.cat -boot-load-size 4 -boot-info-table -no-emul-boot -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat unpacked

ValdikSS
  • 371
  • 2
  • 6
3

Single files in an ISO can be easily replaced without re-spinning the whole image.

While a complete respin will do the trick if you get all the settings right (which might be a tad tricky, especially for "hybrid" images meant to work both on an actual CD/DVD as well as on a USB mass storage stick), it might be quite an overkill if all you need is to make a minor change to a single configuration file.

Instead, you can use a small utility such as isocp (https://frippery.org/isocp/index.html, no affiliation) to safely replace the content of files inside of the existing image.

The program isocp can replace the contents of an existing file in an ISO9660 image. The command take the form:

isocp imagefile file path

where imagefile is an ISO9660 image file; file is the file to be written to the image; and path is the path to the file in the ISO9660 image.

The file must already exist in the ISO image. The replacement file can always be smaller than the original. It might be possible for the replacement file to be larger than the original, but only if there is some free space at the end of the last 2048 extent of the original file.

Of course if all you need is a minor change to a text file (not changing it size substantially), you can also just open the image in a hex editor, locate the contents of the file and modify it in place. Vanilla ISO9660 does not contain any checksums on file data so this won't break the image. But it might still be safer to just use isocp, especially if you're not too proficient with a hex editor.

Note however that some Linux distributions use a derivative of ISO9660 with a hash of the image data embedded using implantisomd5. If you modify such an image, you will need to regenerate the checksum by running implantisomd5 again, or any future hash checks will fail.

TooTea
  • 651