2

With an intent to check how backing up files/filesystems works, I created 3 part itions sda9, sda10 and sda11.

Please see the structure below. (Please ignore sda10 for now as I have already run command to back up sda9 onto it)

ravbholua@ravbholua-Aspire-5315:~/mount$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       9.9G  6.5G  2.9G  70% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            489M   12K  489M   1% /dev
tmpfs           100M  936K   99M   1% /run
none            5.0M  4.0K  5.0M   1% /run/lock
none            497M  156K  497M   1% /run/shm
none            100M   36K  100M   1% /run/user
/dev/sda5       284M  177M   93M  66% /boot
/dev/sda8       9.5G  7.5G  1.6G  84% /home
/dev/sda11      1.2G  1.8M  1.1G   1% /home/ravbholua/mount/mount11
/dev/sda9        21M  181K   19M   1% /home/ravbholua/mount/mount9
/dev/sda10       64Z   64Z  4.6G 100% /home/ravbholua/mount/mount10

For my test, I entered the directory where sda9 was mounted. I created a few files and directory tree.

Then I ran the below command to backup sda9 on sda11

sudo dd if=/dev/sda9 of=/dev/sda11

Now please see how the structure looks:

ravbholua@ravbholua-Aspire-5315:~/mount/mount11$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       9.9G  6.5G  2.9G  70% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            489M   12K  489M   1% /dev
tmpfs           100M  948K   99M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            497M  160K  497M   1% /run/shm
none            100M   40K  100M   1% /run/user
/dev/sda5       284M  177M   93M  66% /boot
/dev/sda8       9.5G  7.5G  1.6G  84% /home
/dev/sda11       37M -1.1G  1.2G    - /home/ravbholua/mount/mount11
/dev/sda9        21M  181K   19M   1% /home/ravbholua/mount/mount9
/dev/sda10       64Z   64Z  4.6G 100% /home/ravbholua/mount/mount10
ravbholua@ravbholua-Aspire-5315:~/mount/mount11$ ls
ravbholua@ravbholua-Aspire-5315:~/mount/mount11$ 

I'm unable to get why sda11 shows as above.

Also I was expecting that when I enter the directory where sda11 is mounted (as shown in the above code, last but one line), it would reflect the contents of sda9 but it was blank. Why so !! What have I misunderstood?

The same happened when I ran the above back up command to back up sda9 on sda10 and hence sda10 shows as above /dev/sda10 64Z 64Z 4.6G 100% /home/ravbholua/mount/mount10. What's that Z!! It shows use % as 100 % but still showing 4.6G as available!! What's all these?

EDIT #1

I rebooted and found the 3 new partitions on the launcher of my Ubuntu desktop. I mounted by clicking them and I found the 2 partitions sda10 and sda11 are clones of sda9. Hence the back-up has worked fine.

Please look below the output of df -h now:

ravbholua@ravbholua-Aspire-5315:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       9.9G  6.5G  2.9G  70% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            489M  8.0K  489M   1% /dev
tmpfs           100M  952K   99M   1% /run
none            5.0M  4.0K  5.0M   1% /run/lock
none            497M  260K  497M   1% /run/shm
none            100M   44K  100M   1% /run/user
/dev/sda5       284M  177M   93M  66% /boot
/dev/sda8       9.5G  7.5G  1.6G  84% /home
/dev/sda9        21M  181K   19M   1% /media/ravbholua/c583223f-8dea-4dc0-b433-caff722eda68
/dev/sda10       21M  181K   19M   1% /media/ravbholua/c583223f-8dea-4dc0-b433-caff722eda681
/dev/sda11       21M  181K   19M   1% /media/ravbholua/c583223f-8dea-4dc0-b433-caff722eda682

Please look at the new sizes of sda10 and sda11. As per the command output, they have lost their original size and taken the size of sda9. (Repeating that sda9 was backed-up to both sda10 and sda11). All 3 have become perfectly the same.

For the exact sizes, please look at the gparted below. Here I would like to know why gparted shows differently than what df -h showed. For example, df -h shows size of sda11 as 21M but gparted shows the actual size 1.17GB, i.e. the size that was created. Why both (gparted and "df -h") differ from each other and which one to accept?

enter image description here

3
  • 2
    Did you umount both partitions before running dd? It won't work while things are mounted. Dec 7 '13 at 9:18
  • @frostschutz yes I didn't unmount either. That may be the reason why df -h is showing that way. But yes back-up has worked and that too perfectly. I rebooted and found the 3 new partitions on the launcher of my Ubuntu desktop. I mounted by clicking them and I found the 2 partitions sda10 and sda11 are clones of sda9. It worked !!
    – Ravi
    Dec 7 '13 at 14:44
  • While it might look like it worked after you re-mount, there will likely be some corruption somewhere. Making copies with dd is fine, but only as long as it's unmounted (or at least, frozen by snapshot). Dec 7 '13 at 15:17
2

sudo dd if=/dev/sda9 of=/dev/sda11

Absolutely terrible idea for a number of reasons, such as the fact that you've duplicated the UUID's, and that you copied 21 MB to back up 141 KB of data.

If you did this while /dev/sda11 was mounted, you're going to have to at least umount and re-mount it. You destroyed the partition that was there, so of course it is unusable otherwise.

Do not use dd to back up one partition to another. Use cp -a or rsync or something, anything, just not dd.


Another issue in this case is the very different size of the partitions. Filesystem partitions are not physical devices -- they are more like normal files, which is why you can transcribe them literally with dd. Like a file, they are organized internally; if something wants to know something about them, it must look inside.1 By analogy, if you want to know the dimensions of a jpeg image, you (or, your software) would look inside the header at the beginning of the .jpg file. You could also make an educated guess based on the file size, but that could be very misleading.

A partition does not simply occupy all the space between it and the next partition -- that's related to the physical device, and again, a partition is not a physical device. It doesn't know anything about what's outside of it. If it is created to be a certain size, that's what size it is. If you copy it somewhere else, it is still the same size, just like a file.

When you copy a partition raw with dd, the place where you copy it to will be exactly the same. The same size, etc. You can't copy a partition into another partition (except as a file image). You can copy a partition over another partition, but the original partition is then completely erased, including the information about how big it is, etc.

There are some good reasons to copy a partition image with dd, but backing up data is not really one of them. If you want to back up data in a partition, copy that data, not the whole partition.

1 If the partition is on a device with other partitions, there will be some meta-data in the device's partition table, most significantly where the partition begins. This is used to find the partition.

2
  • Thank you for giving the insight. I need some more information. (please have a look at the comment of mine in my Q) You showed a good point by mentioning that I copied 19MB extra. But one more revelation I got on running df -h. The sizes of the two partitions sda10 and sda11 where sda9 was copied are now reduced to the size of sda9. I'm editing my Q for more information.
    – Ravi
    Dec 7 '13 at 14:58
  • Okay, I added a few paragraphs above to explain further.
    – goldilocks
    Dec 7 '13 at 15:41
2

If you're trying to backup/clone partitions then I would just use Clonezilla to do this or Partclone. They're included in live distro GParted Live as well as in most distros' repositories.

excerpt from clonezilla website

Clonezilla is a partition and disk imaging/cloning program similar to True Image® or Norton Ghost®. It helps you to do system deployment, bare metal backup and recovery.

  • Filesystem supported: (1) ext2, ext3, ext4, reiserfs, reiser4, xfs, jfs, btrfs of GNU/Linux, (2) FAT12, FAT16, FAT32, NTFS of MS Windows, (3) HFS+ of Mac OS, (4) UFS of FreeBSD, NetBSD, and OpenBSD, (5) minix of Minix, and (6) VMFS3 and VMFS5 of VMWare ESX. Therefore you can clone GNU/Linux, MS windows, Intel-based Mac OS, FreeBSD, NetBSD, OpenBSD, Minix and VMWare ESX, no matter it's 32-bit (x86) or 64-bit (x86-64) OS. For these file systems, only used blocks in partition are saved and restored. For unsupported file system, sector-to-sector copy is done by dd in Clonezilla.
  • LVM2 (LVM version 1 is not) under GNU/Linux is supported.

excerpt from partclone website

Partclone is a program similar to the well-known backup utility "Partition Image" a.k.a partimage. Partclone provides utilities to save and restore used blocks on a partition and is designed for higher compatibility of the file system by using existing libraries, e.g. e2fslibs is used to read and write the ext2 partition.

Partclone now supports ext2, ext3, ext4, hfs+, reiserfs, reiser4, btrfs, vmfs3, vmfs5, xfs, jfs, ufs, ntfs, fat(12/16/32), exfat.

You can take a look at the partclone usage here:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.