Linux make image file

Linux make image file


Thursday, October 4, 2012

How to create, format and mount .img files

Creating & formatting img files in Ubuntu

dd if=/dev/zero of=file.img bs=1M count=50

This will create a file called «file.img» in your home directory with a size of 50 MB.

What is what?
if=/dev/zero => input file, but since we want an empty container (no input file), we use the «universal» term for «nothing» /dev/zero

(For a quick and easy way to do this, you can use my script imgKreator from GitHub.)

Mounting the img file

I have tried mounting the PirateBox img file with different software, but that didn’t work. So after some help through chat and forums here is the command to mount the img file:

sudo mkdir -p /tmp/mount_tmp/ && sudo mount -o loop,rw,sync piratebox/pbIMG_ws.img /tmp/mount_tmp

What is what?
/tmp/mount_tmp/ => Create the folder where the img will be mounted
piratebox/pbIMG_ws.img => Route to PB image file
/tmp/mount_tmp => Mount location

I personally had issues trying to edit anything in the folder so I am running a mounting script with the second line being:

Which just gives read+write permission to the folder.(Although this worked for me before, when creating a new file container use sudo chmod 777 otherwise the PB will not recognize the files and although connection to the network can be made, no website will load). After this editing is simple.

sudo unmount piratebox/pbIMG_ws.img


I’m new to linux and openWRT, but I know enough to navigate directories from the command line, copy files and so on. What exactly is an image file good for? Are you «mounting» it so that you can, for instance, download an img file and put it on a PB, and thus have an entire directory structure, web pages and so forth already preconfigured? So it’s sort of like a fake storage device or whatever that’s actually an IMG file?

By the way, I really like the look of your Pirate Box. I have another router on order and will try yours out when I get it. Right now I’m afraid of breaking the one I just built.

Hello Damon,
yes you could say that such a raw image is just like a «fake storage». DD creates an image of all the input files that can be files, folders or enitre partitions (backup function), these are then «merged» into an image that is a single file, but contains the entire file strucure of the say folder you have put in it. The contents of this image cannot be accessed directly, but you have to mount it manuall first (like you would mount an external drive or USB drive, but the OS does it automatically for you upon connecting).
After mounting the img file, the contained file strucure appears where you mounted it and you can access files and documents in it.
You can read more about dd here for example:

Читайте также:  Linux ssh send key

And yes you though right, the whole idea behind this is that you could have an unlimited number of images on your PirateBox each having different web designs etc. in them. Swapping them out is just as easy as naming them, so for exampple:
The file that the PirateBox will use is USB/piratebox/pbIMG_ws.img. If you have 1 other image file you can just call it pbIMG_ws_alternative.img and leave it next to the other file. Swap the names around and you can use instantly the contents of the other image file.

This is the next step I am going to implement in my design yo you can just download an *.img file and use that without having to touch the original one.


How create IMG file in Linux?

How do I create a .img file?

Create . IMG Image File

  1. Open your Web browser and navigate to the website (link in Resources). …
  2. Launch ImgBurn to display the main menu screen. …
  3. Click the “Folder” icon beneath the Source drop-down list box to open a new file browser window.

What is IMG file Linux?

Most IMG files are just a raw dump of the content of a disk. This means that the file contains the exact same bytes as the source disk it is based on. For LinuxLive USB keys, the . IMG file usually contains several partitions using common Linux filesystems such as ext3 or ext4.

How do I create a disk image in Linux?

How to Create a Disk Image in Linux

  1. Insert the Linux Live CD into your computer’s CD drive.
  2. Reboot the system.
  3. Choose the “Boot to CD-ROM” option when prompted.
  4. Make note of the hard drives that are shown on the desktop. …
  5. Click the “Terminal” button at the bottom of the screen.
  6. Type the command “su” to switch to the root user.

How extract IMG file in Linux?

Just type 7z x image. img and it will extract the included files.

Is IMG same as ISO?

Considerations. There is no difference in the structure of ISO and IMG formats if the IMG file is uncompressed. It is possible for an IMG format file to be renamed with the ISO file extension and then opened in software that only recognizes the ISO file format.

How do I convert IMG to USB?

Writing an Image IMG or ISO File to a USB Drive

  1. Click the folder icon, then browse to and select your . img or . iso file. …
  2. Then select your USB flash drive from the device dropdown.
  3. Finally, click the Write button to write the Image to your USB.

What does IMG stand for?

Acronym Definition
IMG Image
IMG International Medical Group
IMG Information Management Group
IMG International Medical Graduates

How do I open a IMG file?

How to open IMG files

  1. Download and save the IMG file to your computer. …
  2. Launch WinZip and open the compressed file by clicking File > Open. …
  3. Select all of the files in the compressed folder or select only the files you want to extract by holding the CTRL key and left-clicking on them.

What does NTFS mean?

NT file system (NTFS), which is also sometimes called the New Technology File System, is a process that the Windows NT operating system uses for storing, organizing, and finding files on a hard disk efficiently.

How do I create a Clonezilla image in Linux?

Save disk image

  1. Boot the machine via Clonezilla live.
  2. The boot menu of Clonezilla live.
  3. Here we choose 800×600 mode, after pressing Enter, you will see Debian Linux booting process.
  4. Choose language.
  5. Choose keyboard layout.
  6. Choose “Start Clonezilla”
  7. Choose “device-image” option.
  8. Choose “local_dev” option to assign sdb1 as the image home.

Can clonezilla create an ISO?

Here we choose iso: Clonezilla will list the command to create such a iso file: … If you want to create a recovery USB flash drive, choose to create zip file, then follow the same method as creating USB flash drive version of Clonezilla live to put the created zip file on USB flash drive and make it bootable.

Читайте также:  Linux make archive from directory

How do I create a partition image?

The Disk to Image Wizard steps you through the process of creating a disk image for a whole disk or a number of partitions. To open the Disk to Image Wizard, do one of the following: In the main program window, double-click Disk to Image. From the Tools menu, choose Disk to Image.

How do I run an iso file in Linux?

How to Mount ISO File on Linux

  1. Create the mount point directory on Linux: sudo mkdir /mnt/iso.
  2. Mount the ISO file on Linux: sudo mount -o loop /path/to/my-iso-image.iso /mnt/iso.
  3. Verify it, run: mount OR df -H OR ls -l /mnt/iso/
  4. Unmount the ISO file using: sudo umount /mnt/iso/

How do I open a .img file without burning it?

1. Download a third-party image management tool such as PowerISO, UltraISO or MagicISO (links in Resources). These tools allow you to open an IMG file and explore its contents without burning it to disc.

How do I extract an ISO file?

Click 1-click Unzip and choose Unzip to PC or Cloud in the WinZip toolbar under the Unzip/Share tab. Select a destination folder to place the extracted ISO files in and click the “Unzip” button. Find your extracted files in your chosen destination folder.


How to Make Disk Images in Linux with DD Command

Whenever it comes to wiping, backing up, or restoring Linux files, you have few tools. Although there is one alternative that still works, regardless of the Linux distribution you’re using, and that is the DD command. Creating an image of a partition or cloning a complete hard disk drive are simply the acts of making a copy of the whole disk or partition, and it is very simple with the dd command. The DD command is good for cloning disks, backups, and restoration, among other things. In this guide, we will see how to make a disk image using the DD command. Make sure you have the Ubuntu Linux system installed.

DD circumvents this by making an identical replica of the whole hard drive or partitions. So if you recover this backup, your machine will be restored to its original state. You’ll regain access to your folders, games, browser history, and sometimes even device settings. We’ll want another drive with more capacity than the one we’re cloning to replicate your drive. There would most probably be a big hard drive for this purpose.

Install LSSCSI Utility

Open the command-line terminal of the Ubuntu 20.04 Linux system. Make sure to have the “lsscsi” utility installed on your system. If it is not installed, try to install it using the below “apt” command followed by the keyword “install” and “lsscsi”. It will take not more than 5 minutes to get installed, and you are good to go.

After installing the “lsscsi” utility, now it’s time to use it for listing all the storage devices of our Linux system. To list the storage drives and DVD’s execute the below command. You can see we have one disk drive and one cd/DVD device in our system.

Check Disk Information

Firstly, we have to find out some information regarding the disk drive “/dev/sda”. And for this reason, we have to use the “fdisk” instruction in our command-shell with sudo privileges as below.

It will navigate to its command theme. Type “p” to check the information of disks as below. You can see it shows the total memory of the “/dev/sda” drive, its sectors, and bytes. It is showing the disk type as DOS. On the other hand, the last three lines of the snapshot show the partitions of the /dev/sda drive and their further information.

Читайте также:  Wordpress как редактировать свой шаблон

Create a Clone Disk Image

Now you have almost every piece of information regarding the “/dev/sda” drive. Press “q” to exit the commanding theme. Now, you are ready to make a disk image using the DD command. So, make yourself clear that the DD command always needs “sudo” privileges to execute. As we already know from the above image, the “/dev/sda” has three partitions, and we will make an image of one of them. So, we choose “sda1” for making its clone. You have to execute the below “DD” command followed by the “if” path and “of” path. The “if” path is of the input disk drive, which is meant to be cloned and the “of” path is for the output device disk, where it would be copied as an image. So, from this, you can understand that “sda1.img” is the cloned file for disk and sda1 is the actual drive. We have specified the bytes per second to be copied from one location to another. We assigned it a value of 1000. The command is as follows:

The output shows the number of records inputted and outputted from two locations, e.g., source and destination. It also shows the number of bytes with time seconds, copied into a destination in MB’s. This means that the clone has been effectively done.

Let’s check the destination image file to see if all the data from the source drive has been cloned into it properly or not. Use the below list command along with the path of an image file of the drive as:

The output shows the rights assigned to this image file, its size, and location. You can say that it has similar rights and size as the original disk drive have.

To see some more information regarding the disk image file, you have to try the below “fdisk” command followed by the flag “-l” as below.

The output shows the exact same information regarding this image file as we have seen for the original disk drive before creating this image file. It shows the size of the image drive, its total number of bytes, and total sectors.

Restore the Drive from Clone Image

Now, if you want to restore your original disk drive along with all the data it has, you have to use the DD command again to do so. While using the DD command, there is a little change in it. You have to swipe the input and output paths this time. This means you have to place the image disk file path into the “if” path, and in the “of” output path, you have to mention the location where you want to restore the image file data. Here is the command to restore the drive data from the image file:

The output shows the transfer of backup files into their actual destination. You can see the input and output number of total records and some further information regarding the numbers of bytes transferred, the total size of the disk image, and the time taken to transfer it.


Indeed, The method discussed before is the easiest and simplest way to clone a disk into an image file and restore the backup to get all the files and folders back.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.


Поделиться с друзьями