Centos – How to create a custom CentOS 7 ISO with .img

centoscentos7iso

I'm trying to create a custom CentOS 7 .iso that has a set of scripts included, eg. installX.sh.

I've followed the instructions here, creating a product.img with the file structure: /sbin/installX.sh, /.buildstamp

I then placed that in the images folder and generated the .iso. However, when testing out the .iso, it doesn't have installX.sh anywhere on the system when running find / -name installX.sh. This suggests the product.img file was ignored.

How can I load an .img file into the file structure of the installed OS?

The contents of .buildstamp:

[Main]
Product=CentOS Linux
Version=7.7
BugURL=https://bugs.centos.org
IsFinal=True
[Compose]
Lorax=19.6.92-1

The image file was created using this command:

find . | cpio -c -o | gzip -9cv > ../product.img

And was placed in linux/images in the ISO path

To generate the .iso, I used this command:

genisoimage -U -r -v -T -J -joliet-long -V "CentOS 7 x86_64" -volset "CentOS 7 x86_64" -A "CentOS 7 x86_64" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -o ../CentOS7.iso .

Where the working directory is the file structure to become the .iso, and CentOS7.iso is the .iso I'm trying to create.

The .iso was checksummed using:

implantisomd5 ../CentOS7.iso

And was working and able to be installed as a normal CentOS 7 installation (Just without installX.sh).

Best Answer

I think the easiest way to accomplish this would be to convert the .img to cd9660 format. Then mount it, and copy what you need on to the CentOS iso image you're building. You can accomplish the conversion using iat. For example, if I were on Ubuntu. I'd do it this way:

sudo apt install iat

followed by

iat yourimge.img youriso.iso

Then simply mount the freshly converted iso image in the same way you mounted the CentOS iso. Copy the files you need to the CentOS image you're creating where you need them.

Related Topic