20

I am trying to create a custom ISO image which would install the minimal required RPMS along with some custom written RPM of my app. and Also wants to perform some post install steps like configuring my App and VPN configuration etc.

I saw some of the links on google but they are pointing creating repo and ISO from mounted disk or ISO image.

Thanks Ramesh

Ramesh Kumar
  • 1,690
  • 5
  • 18
  • 29
  • you can also use redhat kickstart for this job it more easier and more flexible choice More information here https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Installation_Guide/ch-kickstart2.html – fyarci Nov 26 '15 at 16:54

1 Answers1

52
  1. Create a directory to mount your source.

    mkdir /tmp/bootiso
    
  2. Loop mount the source ISO you are modifying. (Download from Red Hat / CentOS.)

    mount -o loop /path/to/some.iso /tmp/bootiso
    
  3. Create a working directory for your customized media.

    mkdir /tmp/bootisoks
    
  4. Copy the source media to the working directory.

    cp -r /tmp/bootiso/* /tmp/bootisoks/
    
  5. Unmount the source ISO and remove the directory.

    umount /tmp/bootiso && rmdir /tmp/bootiso
    
  6. Change permissions on the working directory.

    chmod -R u+w /tmp/bootisoks
    
  7. Copy your Kickstart script which has been modified for the packages and %post to the working directory.

    cp /path/to/someks.cfg /tmp/bootisoks/isolinux/ks.cfg
    
  8. Copy any additional RPMs to the directory structure and update the metadata.

    cp /path/to/*.rpm /tmp/bootisoks/Packages/.
    cd /tmp/bootisoks/Packages && createrepo -dpo .. .
    
  9. Add kickstart to boot options.

    sed -i 's/append\ initrd\=initrd.img/append initrd=initrd.img\ ks\=cdrom:\/ks.cfg/' /tmp/bootisoks/isolinux/isolinux.cfg
    
  10. Create the new ISO file.

    cd /tmp/bootisoks && \ 
    mkisofs -o /tmp/boot.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "CentOS 7 x86_64" -R -J -v -T isolinux/. .
    
  11. (Optional) Use isohybrid if you want to dd the ISO file to a bootable USB key.

    isohybrid /tmp/boot.iso
    
  12. Add an MD5 checksum (to allow testing of media).

    implantisomd5 /tmp/boot.iso
    

If you need more help creating the Kickstart script, I suggest starting with the official Red Hat documentation.

U880D
  • 597
  • 7
  • 17
Aaron Copley
  • 12,345
  • 5
  • 46
  • 67
  • I got it working, but I have facing another issue, %post section does not executing any script to commands like wget, source, etc. But some of the commands are working fine, like cat(creating a new file),chmod etc.. Actually, I want to execute a bash script in %post section which will install couple of RPMS and will setup VPN and some other configurations. – Ramesh Kumar Jul 10 '13 at 11:37
  • You'll want to ask another question. This site works best with single questions and answers. Be sure to include your troubleshooting steps. (What errors are given during Kickstart?) Check the virtual consoles. (CTRL+ALT+F1 through CTRL+ALT+F5) – Aaron Copley Jul 10 '13 at 14:58
  • Sorry I don't get it, the boot.iso created that way does not include any of the packages. – sivann Dec 09 '14 at 11:53
  • 1
    Is it possible you missed or botched step 4, then? – Aaron Copley Dec 09 '14 at 14:40
  • 3
    @AaronCopley yes, you're probably right. I also found this: https://github.com/joyent/mi-centos-7 which helped me. – sivann Dec 11 '14 at 08:13
  • Hrmm.. To be fair, I have not tested this process for CentOS 7, yet. (It's been tested for 5 and 6 only.) – Aaron Copley Dec 11 '14 at 15:27
  • 1
    On step 9, I believe you must give last parameter . (dot) to indicate current directory. Strange default behavior but without that, mkisofs creates an iso file which contains only the files from the top directory and no subdirectories and beyond. – hshib Feb 01 '15 at 19:49
  • 2
    I also had issue with step 4. With that usage of "cp" command it does not copy the hidden files .discinfo and .treeinfo. Without those, created iso fails during the installation complaining that "CD/ROM not found". – hshib Feb 02 '15 at 02:06
  • 1
    You can copy everything with single command with - "cp -r /tmp/bootiso/. /tmp/bootisoks/" (this is a little tricky - note single . after /tmp/bootiso/) – hshib Feb 02 '15 at 02:17
  • Sorry, about that. I probably missed those periods in my notes that I copied this answer from? My media was definitely created successfully so I am sure I had `.treeinfo` and `.discinfo` in the final ISO. Apologies for the additional troubleshooting you had to do. I'll update the answer. – Aaron Copley Feb 02 '15 at 16:52
  • @Aaron Copley Thank you for your instructure. I followed it. but, the iso file which is made by the last command is not as the same size of original iso. The original one is (1.1G) but the new iso is 34MG. and it is not working? – user1603454 Nov 26 '15 at 06:08
  • @user1603454 You probably don't want to create an ISO for just the contents of ./isolinux. Modify step 9 as necessary.. – Aaron Copley Dec 02 '15 at 17:30
  • 1
    Apologies for bumping the old thread... I was having issues with the built ISO hanging at 'Starting dracut initqueue hook.' - and the solution was to add a -V flag to the mkisofs flag. – Shane Sep 06 '17 at 06:02
  • I followed the steps as mentioned here. Everything worked fine as long as I skipped step 8. If I add rpms to `Packages` directory and then run `createrepo -dpo .. .` I encounter an error during install: `noSuchGroup: core`. Do I need to create another repo and let the existing repo intact or did anyone manage to modify the existing repo without problem ? I don't know if I should open a new question. – gcharbon Aug 24 '18 at 14:29
  • @gcharbon You'll need to modify the `createrepo` command to include the groups file. That way your repository contains group metadata. If you sort it out, please feel free to update the answer above. – Aaron Copley Aug 24 '18 at 15:17
  • @gcharbon were you able to figure out how to modify createrepo to include the groups file? I am struggling trying to add my own RPMs to the kickstart file. – peachykeen Aug 07 '19 at 18:34
  • 1
    @peachykeen I stopped struggling with Kickstart files, instead I use Centos Cloud images and cloud-init. It proved to be much simpler (I also use Ansible to automate the download of images, the generation of cloud init files from templates, then the generation of cloud-init ISO seeds) – gcharbon Aug 09 '19 at 13:51