Creating Customized and Bootable Disk Images of Host Systems
In this article, discover how to create a customized and bootable disk image of a host system with the tools mkisofs and SystemBack.
Join the DZone community and get the full member experience.
Join For FreeIn the realm of Linux and operating systems, disk imaging plays a vital role in various scenarios. Disk images, also known as ISOs, are essentially digital replicas of physical media such as CDs, DVDs, or hard drives. They serve as a convenient means to store and distribute entire file systems, preserving their integrity and structure. One powerful tool available in the Linux world for creating disk images is mkisofs. Developed by Eric Youngdale, mkisofs stands for "make ISO filesystem" and is commonly used to generate ISO-9660 file systems, which are the standard format for disk images.
What Is mkisofs?
Now, let's dive into how you can utilize mkisofs to create disk images on Linux. Before getting started, let us take a closer look at what mkisofs is and how to install the tool on your system.
According to Ran, mkisofs is a utility that creates an ISO 9660 image from files on disk. It is effectively a pre-mastering program to generate an ISO9660/JOLIET/HFS hybrid filesystem capable of generating the System Use Sharing Protocol records (SUSP) specified by the Rock Ridge Interchange Protocol. This is used to further describe the files in the iso9660 filesystem to a UNIX host, and provides information such as longer filenames, UID/GID, POSIX permissions, symbolic links, block, and character devices. mkisofs takes a snapshot of a directory tree and generates a binary image that corresponds to an ISO9660 or HFS filesystem when it is written to a block device. Each specified pathspec describes the path of a directory tree to be copied into the ISO9660 filesystem; if multiple paths are specified, the files in all the paths are merged to form the image.
Option | Description |
---|---|
-o output_file.iso |
Specifies the name of the output ISO file |
-b boot_image |
Specifies the location of the boot image |
-c boot_catalog |
Specifies the location of the boot catalog |
-no-emul-boot |
Indicates the boot process should not emulate a floppy disk |
-boot-load-size size |
Specifies the size of the boot loader in sectors |
-boot-info-table |
Specifies that a boot information table should be included in the ISO image |
-J |
Indicates use of Joliet extensions |
-R |
Indicates use of Rock Ridge extensions |
-V volume_id |
Specifies the volume ID for the ISO image |
-A application_id |
Specifies the application ID for the ISO image |
-p publisher_id |
Specifies the publisher ID for the ISO image |
-copyright copyright |
Specifies the copyright information for the ISO image |
-hide-rr-moved |
Specifies that Rock Ridge moved files should be hidden |
The upper table shows some options you can select. By default, mkisofs generates ISO-9660 file systems, but it also supports other formats such as Joliet and Rock Ridge extensions. These extensions provide additional features not present in the base ISO-9660 standard, such as longer filenames and POSIX file attributes. To enable Joliet extensions, you can use the "-J
" flag when invoking mkisofs. Similarly, the "-R
" flag enables Rock Ridge extensions. In addition to these extensions, mkisofs allows you to set various metadata for the disk image, such as volume names, publisher information, and even bootable attributes.
You can find mkisofs in most Linux distributions' package repositories under the same name.
- On Ubuntu:
# apt-get install mkisofs
- On CentOS:
# yum install mkisofs
There are many possibilities in order to customize an ISO. By modifying the ISO image, we can automatically partition the hard drives, install Linux, install several add-on packages, create user accounts, and set up the networking. In the following steps, we will see how to customize an existing ISO template.
What Is SystemBack?
SystemBack is a free and open-source backup and system recovery tool for Linux-based operating systems. It is designed to create system backups, which include the entire operating system, user data, and configuration settings. With SystemBack you can create bootable ISO images via a graphical user interface (GUI) that makes it user-friendly and accessible to users who may not be comfortable with command-line tools. Be aware that the development of SystemBack appeared to have slowed down in recent years, and it may not be actively maintained or updated to support the latest Linux distributions. In this article, SystemBack works without any issue with the Ubuntu version ubuntu-18.04.6-live-server-amd64.iso
.
How To Create a Disk Image of the Host System
Let us assume we have installed Ubuntu (ubuntu-18.04.6-live-server-amd64.iso
) on our machine and tailored the operating system. In this use case, the customized system boots automatically and does not have a boot menu.
Next, we want to create a bootable ISO image of the adjusted system in order to distribute the system to the client.
In the first place, create a system backup of the running system as follows:
- Create a SystemBack backup.
- Click on the "Live system create" option.
- Select the backup you created in Step 1 from the list of available backups.
- Configure system settings: You can customize various settings like the ISO file name, user accounts, hostname, and other boot options as needed.
- Click the "Create new" button to generate the live system ISO. SystemBack will compile the backup into a bootable image.
If you boot the generated ISO image, you will see the following boot menu created by SystemBack:
To fix this bug, we use mkisofs.
Therefore, we need to create a folder under /tmp
where we specify the source directory test_iso
where we save the files and folders of the generated ISO image.
mkdir /tmp/test_iso
In order to access and modify the contents of an ISO file, you can mount it as a device. Linux will treat it as a separate file system, and allow you to browse the files as you would normally browse the directory structure of your hard drive. The fastest way to mount an ISO image is via the command line. For that reason, let us jump into the source directory:
cd /tmp/test_iso/
We execute the mount command in order to mount the generated ISO image:
mount -t iso9660 -o loop template_linux.iso /mnt/
According to the main page of the mount
command: The option -t
tells the kernel to attach the filesystem iso9660
found on the loop device. If no explicit loop device is mentioned (but just an option -o loop
is given), then mount
will try to find some unused loop device and use that and will set up the loop device such as /dev/loop1 to correspond to the generated ISO image, and then mount this device on /mnt
.
We will see a warning: the generated ISO image is read-only. To modify the content of the generated ISO image, we need to copy the content into the source directory after we have switched to the folder /mnt
:
cp -r /mnt/* /tmp/test_iso
Another command for copying the content of the ISO image to the source folder:
tar cf - . | (cd /tmp/test_iso; tar xfp -)
Now, we can adjust the isolinux config file to remove the boot menu and enable the automatic boot process.
In the last step, we will create a new bootable ISO image from the source folder. First, switch to the folder /tmp/test_iso
and then execute the following command:
mkisofs -o custom_live_system.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V "Custom Live System" .
Conclusion
Creating customized and bootable disk images with SystemBack and mkisofs is a powerful way to distribute pre-configured operating systems tailored to your needs. Whether you're a system administrator or developer, mastering this process will help you streamline deployments and ensure consistency across multiple systems.
Opinions expressed by DZone contributors are their own.
Comments