0

I am booting a live disk Ubuntu and I want to back up my entire SSD (sdb) with all 3 partitions (sdb1, sdb2, sdb3) to an image file on an external hard disk.


This guide suggests this command:

dd if=/dev/sdX conv=sync,noerror bs=64K | gzip -c  > /path/to/backup.img.gz
  1. I want to use the image to later on convert it with qemu to VHD or VMDK and boot the Ubuntu system on a virtual machine so I'm not sure about the .gz compression there.

  2. What is the format of the .img file that the command is creating? Is it .iso?

  3. Why does the command have conv? I don't want any conversion, I want raw clone to image.

  4. I also noticed the dd command doesn't even have an of= part.

  5. Does bs=128k improve speed than bs=64k?


So from what I know I think the correct command for my needs is:

dd if=/dev/sdb bs=64k of=/dev/sdd1/image.img

note: sdd1 is the only partition of my external hard disk.

Shayan
  • 1,621

2 Answers2

1
  1. I want to use the image to later on convert it with qemu to VHD or VMDK and boot the Ubuntu system on a virtual machine so I'm not sure about the .gz compression there.

If you want it for a virtual machine, you do not want it compressed. And you probably don't really want a raw image either, but rather p2v (physical to virtual) conversion. For VirtualBox, you may for instance do

cat /dev/sda | VBoxManage convertfromraw stdin OutPutFile.vdi NUMBEROFBYTES

Which will create a valid vboximage of the drive for you.

  1. What is the format of the .img file that the command is creating? Is it .iso?

Iso refers to ISO9660 file system. If you image your entire hard drive, it will be a hard drive image, including boot sector and partition table. If you image a single partition, the format will essentially be whatever format that partition had.

  1. Why does the command have conv? I don't want any conversion, I want raw clone to image.

conv specifies arguments, which may do some conversion. In this case it tells dd to use synchronous I/O, and not abort on errors. Enter man dd and /syncEnter to search for sync in the manual page

  1. I also noticed the dd command doesn't even have an of= part.

dd outputs to stdout unless redirected. In this case stdout is piped to gzip, which will compress the file and write to /path/to/backup.img.gz.

  1. Does bs=128k improve speed than bs=64k?

Probably. The definitive answer would be to test it, for instance with time dd if=/dev/sda of=/dev/zero bs=64k count=10000, and repeat with different sizes.

vidarlo
  • 23,497
1

The man page of dd isn't vague. You just don't understand all of the concepts.

You shouldn't use any conversion options for your purpose. Just leave them out.

You don't need compression for your purpose. You'd just have to extract the image right afterwards anyway.

The first command doesn't have an of argument because the data is piped to a different command. So dd generates some data which is then pushed over to gzip which performs compression and then writes the result to the specified location. To learn more about pipes, just google "Linux pipes". They are really useful. However, you don't need any for your purpose.

There is no specific format to the output of dd. dd just copies data. It takes whatever it finds at its input location and copies it to its output location. Typically, the file extension ".img" is used. However, because what dd copies can be anything, using something more specific like ".iso" is useful in some situations.

The block size (which is specified via bs) may even be much greater on modern computers. If you're on any computer that's been made in the last for years, go straight for bs=4M or something like this. If it's in about the right range, fiddling with it doesn't change much.

To back your disk up, you may use this command:

sudo dd if=/dev/sda bs=4M of=/path/to/your/storage/location/filename.img

Note that you need root privileges to read directly from your hard drive's device file.

But make sure your of doesn't start with /dev unless you know exactly what you're doing! Doing so may erase an entire disk! It should not lead to the location of the device you want the image to be on but to where it's mounted. These paths typically start with /media or /mnt.

UTF-8
  • 5,910
  • 10
  • 34
  • 68