How to Create Empty Disk Image in Linux

How to Create Empty Disk Image in Linux

Sometimes Linux developers and system administrators need to create an empty disk image from an image file. There are several ways to do this in Linux. In this article, we will learn how to create empty disk image in Linux. There are several third party tools that allow you to do this. For our purpose, we will use hfsutils package.

How to Create Empty Disk Image in Linux

Here are the following steps to create empty disk image in Linux.

1. Create hfsutils

The first step is to install hfsutils on your system. Open terminal and run the following command to install hfsutils.

$ sudo apt-get install hfsutils

2. Create Image File

Let us say your image file is located at /home/data/file.img. We will run the following command to create a disk image using this image file.

$ sudo dd if=/dev/zero of=/home/file.img bs=1 count=0 seek=1G

In the above command, replace /home/data/file.img file with the path to your image file. We have created disk space for 1Gb file. You can change these values by changing values for bs, count and seek attributes. Here are more details about their functionality.

3. Format Image

The above image is unformatted. Run the following command to format image to a proper file system.

$ sudo hformat -l File /home/file.img

4. Mount Image

Mount the image using the following commands. Hereafter, you will be able to access the disk just as a directory.

$ sudo mkdir /mnt/file 
$ sudo mount -t hfs -o loop /home/file.img /mnt/file

5. Copy Files

You can copy files to this directory as per your requirement and unmount it as per your requirement, when you are done.

$ sudo umount /mnt/file

In this article, we have learnt how to generate empty disk image in Linux. You can use these steps on almost all Linux distributions.

Also read:

How to Unrar Files with Password in Linux
How to Extract Multipart RAR File
How to Unrar Multiple Files
How to Find Recently Modified Files in Linux
How to Install VNS Server in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *