Make linux disk image

Introduction

This article is dedicated to documenting methods of performing drive imaging (also called bare metal backups, or disk cloning). Drive imaging is a complete copy of all information on a drive, necessary to restore all of the data or entire operating system on a drive to the same state it was when the image was created. This is different from imaging a partition, where one is making a copy of an individual partition that resides on a drive, or backing up individual files and folders.

Please ensure you are comfortable with the information discussed before proceeding. Improperly executing a command may result in partial or complete data loss. Please double- or even triple-check your target device to avoid such catastrophic loss.

Preparations

  • Exclusive access to the drive being imaged (i.e. the drive being imaged shouldn’t be mounted). Live operating system imaging methods, for example, physical-to-virtual (P2V), virtual-to-virtual (V2V), etc. are not covered here.
  • The location (remote file share, external USB drive, internal drive, etc.) where the drive image is being backed up to should have the same or more free space then that of the drive being imaging. For example, if you are imaging a 160GB drive, you should have 160GB or more free space to back up to.
  • The filesystem of the backup location needs to support the filesize necessary to backup the image as one file.
  • An environment to perform the drive imaging. This can be a live environment where one images the data of the computers internal drive.

dd is a universal command line program used for low level copying of data. It will copy the entire drive, even if the used data is only consuming 10% of the beginning of the drive. For example, dd’ing a 100GB drive, where all the data is at the beginning, and is only 10GB is being consumed, the resulting file will be 100GB in size.

In order to find out which drive to clone, open a terminal and execute:

The output of the command will list each hard drive (ex. /dev/sda).

Backup with dd

The following example will create a drive image of /dev/sda, the image will be backed up to an external drive, and compressed. For example, one may use bzip2 for maximum compression:

sudo dd if=/dev/sda | bzip2 > /media/usb/image.bz2

However, one may use this same concept to change the compression type (gzip, zip, etc.) to one that best suites your needs (higher compression speed, preferred compression format, etc.).

Restoring a drive image

To restore a drive image, one will want to boot into a live environment. Restoration is quite simple, and really just involves reversing the if and of values. This will tell dd to overwrite the drive with the data that is stored in the file. Ensure the image file isn’t stored on the drive you’re restoring to. If you do this, eventually during the operation dd will overwrite the image file, corrupting it and your drive.

Читайте также:  Linux путь до исполняемого файла

To restore the drive above:

bzcat /media/usb/image.bz2 | dd of=/dev/sda

When restoring the whole drive, the system will not automatically create the devices (/dev/sda1, /dev/sda2, etc.). Reboot to ensure automatic detection.

If you restored Ubuntu to a new drive, and the UUIDs (see UsingUUID for more) changed, then you must change the bootloader and the mount points. One will want to edit the following via a terminal:

sudo nano /boot/grub/menu.lst sudo nano /etc/fstab

To know what the new UUIDs for your drives are, use the following command:

From this list, you can cross-reference the information with that of fdisk to know which drive is which. Then simply update the UUIDs in both GRUB and fstab files.

Clone Drive

Clone the contents of a whole hard drive onto another completely different drive

Clonezilla

https://launchpad.net/ubuntu/+source/clonezilla is another modern imaging solution. For more on it, please see the Clonezilla homepage.

DriveImaging (последним исправлял пользователь qiii 2015-09-28 17:55:23)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

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.

Читайте также:  Astra linux apache2 отключить аутентификацию

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.

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.

Читайте также:  Кали линукс для хакеров

Conclusion

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.

Источник

How to make disk image with dd on Linux

Recently I had to send my notebook to service (by the way — it’s fifth time when it’s in service). When I sent my notebook first time, I made a full backup because service after repair usually delete all data on disk and install clean Windows to check if everything is OK. But when I sent my notebook third time I said ENOUGH! Every few months I had to install Linux Mint, configure it, install my apps and so on, and so on. Then I started to create images. So how to make disk image with dd on Linux and what is the disk image?

What is disk image?

Disk image is a one big file which contains every byte of some disk. Notice that it’s not a copy if files. DIsk image is created by special applications from low level disk reading. It means these applications read disk sectors byte by byte and write them to another disk creating one big file. It’s very useful when you want to change disk to another for instance HDD to SSD.

How to create whole disk image?

dd if=/dev/ORIGIN_DISK of=/dev/PLACE-TO-WRITE bs=64K conv=noerror,sync 
dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync 

How to create a partition image?

dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync 

Let’s stop here for a moment and see what we have here: if — input device/file of — output device/file bs=64K — The block size. Usually peope use 64K or 128K, but you can use other values if know what you do conv=noerror — dd will continue operation and ignore all read errors sync — add input blocks with zeros if there were any read errors (it means data offsets stay in sync)

How to create disk image using live CD or USB flash drive?

fdisk

You should see similar to this:
Sometimes you can see different names of disk, eg. nvme for SSD M.2. To create disk image run this:

dd if=/dev/sda conv=sync,noerror bs=128K | gzip -c > SSD_image.gz 

DD will create compressed image of whole sda disk. The image will be in current directory. If you want to save it in another directory, tell dd where to save the image:

dd if=/dev/sda conv=sync,noerror bs=128K | gzip -c > /media/disk2/images/SSD_image.gz 

Above commands clone the entire hard disk, including the MBR, bootloader, all partitions, UUIDs, and data.

How to restore disk image?

gunzip -c SSD_image.gz | dd of=/dev/sda 

Bonus tip

dd if=/dev/sda conv=sync,noerror bs=128K status=progress | gzip -c > /media/disk2/images/SSD_image.gz 

Chris Texe Twitter

It would be great if you will comment or follow me on social media: Also you can visit my websites:

  • Linux blog
  • Web Agency website

Источник

Оцените статью
Adblock
detector