Modifying a RHEL or CentOS machine image

Follow
Affected Version(s): All

 

Why modify an existing machine image?


Additional software may be required in an existing machine image.  Perhaps a cloud user wants a newer version of a software package.  It's feasible that editing the existing machine image is quicker than creating a new one.
 

Mounting the root filesystem


Locate the machine image that needs to be altered and mount the image, this contains the root filesystem:

$ mkdir <workingdir>
$ mkdir <workingdir>/proc
$ mkdir <workingdir>/dev
# mount -o loop <myimage>.img <workingdir>
# mount -o bind /proc <workingdir>/proc
# mount -o bind /dev <workingdir>/dev
 

Installing packages


With the filesystem and /proc and /dev mounted (this will enable more tools to function correctly), install the required packages when chroot'ed to the mountpoint.  The below example presumes the image is for RHEL/CentOS/Fedora/SL which uses the yum package manager:

# chroot <workingdir> /bin/bash -c "yum install -y <packagename>"

alternatively, use:

# yum --installroot=/<workingdir> install -y <packagename>

or for a single rpm, you might use:

# rpm -ivh --root /<workingdir> <package>.rpm
 

Cleaning up


With the desired packages installed, go ahead and unmount the filesystem:

# umount <workingdir>/proc
# umount <workingdir>/dev
# umount <workingdir>

Upload the Image

When finished with the image, ensure that it's uploaded and registered. 

Have more questions? Submit a request

Comments

Powered by Zendesk