LinuxCommandLibrary

mkdiskimage

Create disk images from files or devices

SYNOPSIS

mkdiskimage [options] image_file size

PARAMETERS

--size size
    Specifies the size of the disk image to create. The size can be expressed in bytes or with a suffix (e.g., '10M' for 10 megabytes, '2G' for 2 gigabytes).

--sparse
    Creates a sparse image. This means that only the blocks that are actually written to the image will consume disk space.

--help
    Displays help message.

--version
    Displays version information.

image_file
    The path to the image file to be created.

size
    Size of the image.

DESCRIPTION

The mkdiskimage command is a utility primarily used for creating raw disk images, typically intended for use with loop devices.
It's a simple tool designed to efficiently allocate space for a disk image file. This is useful for setting up virtual disks for testing, system installations, or creating backups.
The image can be a fixed size or sparse, depending on the flags chosen. Sparse images only allocate physical storage for the data that is actually written to the image, saving disk space when the image contains large areas of zeros. mkdiskimage allows specifying the size of the image in bytes or using human-readable suffixes such as 'M' for megabytes or 'G' for gigabytes.
The command provides a basic method for generating a blank disk image without complex formatting or partitioning, providing a blank canvas which a filesystem can be created upon. It is useful in scripting and automation scenarios where disk images are needed as part of a larger process.

CAVEATS

mkdiskimage creates only a raw, unformatted disk image. It does not create any file system or partition tables. Additional tools such as mkfs and fdisk are required to format and partition the image after creation.

EXAMPLES

Create a 10MB sparse disk image: mkdiskimage --sparse image.img 10M
Create a 1GB disk image: mkdiskimage image.img 1G

HISTORY

mkdiskimage is part of the util-linux package, which has a long history of providing essential system utilities for Linux. Its development is tied to the need for basic disk management tools within the Linux ecosystem.

SEE ALSO

losetup(8), mkfs(8), fdisk(8)

Copied to clipboard