Skip to content

Instantly share code, notes, and snippets.

@anedward01
Forked from AkdM/Edit_Repack_ISO_tutorial.md
Last active August 10, 2024 17:58
Show Gist options
  • Save anedward01/65fcdcb9a7db27b6367e932825622b10 to your computer and use it in GitHub Desktop.
Save anedward01/65fcdcb9a7db27b6367e932825622b10 to your computer and use it in GitHub Desktop.
Edit and repack .iso bootable image

On Linux

Installing mkisofs

apt-get install mkisofs

Editing ISO image

mkdir /tmp/custom_iso

cd /tmp/custom_iso/

mount -t iso9660 -o loop ~/original.iso /mnt/

cd /mnt

mnt is read-only, thus we need to copy the files in it in order to modify the files.

tar cf - . | (cd /tmp/custom_iso; tar xfp -)

You can now modify the files for making a preseed for example!

Back in .iso

If not, go back to your /tmp/custom_iso folder

cd /tmp/custom_iso

Copy this line, modify it and paste it in order to create the .iso

mkisofs -o output.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "Ubuntu Custom ISO Preseed" .

Make it bootable with isohybrid

Install isohybrid:

sudo apt install syslinux-utils

Then simply type the following to make it bootable:

sudo isohybrid output.iso

Creating UEFI-Bootable ISO

use xorriso to create an ISO from directory:

xorriso -as mkisofs -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -c isolinux/boot.cat -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -o /dest/iso /tmp/ubnt-custom/

On macOS

Install brew

Follow https://brew.sh/

Install requirements

In order to install mkisofs, you need to get the cdrtools package for macOS:

brew install cdrtools

Prepare folders

Make two folders: iso and custom.

ro_iso is going to be where the files of the iso will be mounted, read only.

custom will be where you will be able to modify the files

mkdir ro_iso && mkdir custom

Attaching, mounting and editing

hdiutil attach -nomount ubuntu.iso

List the disks and get the disk image name usually /dev/disk2:

diskutil list

We will use /dev/disk2.

Now you can mount the disk into the read-only folder:

mount -t cd9660 /dev/disk2 ro_iso

We now need to copy the files in the custom folder in order to modify the files:

tar cf - . | (cd $HOME/yourfolder/custom; tar xfp -)

You can now begin editing the files.

Back in .iso

If not yet, go back to your custom folder.

Copy this line, modify it and paste it in order to create the .iso

sudo mkisofs -o output.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "Ubuntu Custom ISO Preseed" .

Make it bootable with isohybrid

Use the isohybrid.pl file of this gist like the following:

sudo perl isohybrid.pl output.iso

umount and detach

Don't forget to do it, or you will can't be able to delete the ro_iso folder

umount /dev/disk2

hdiutil detach /dev/disk2

You now have a bootable USB iso file :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment