Search code examples
amazon-ec2linux-kernelvmwareddgunzip

using "dd" to capture and restore fails?


I used dd to capture the two local vm partitions like this...

# dd if=/dev/sda1 | gzip >mySda1.gz 
# dd if=/dev/sda2 | gzip >mySda2.gz

Then I attached two volumes of sufficient size to an already running instance and mounted them (as /mnt/one and /mnt/two), then copied the .gz files up to the instance and used these commands to restore the partitions

# gunzip –c mySda1.gz | dd of=/dev/xvdk
# gunzip –c mySda2.gz | dd of=/dev/xvdl

The gunzip commands do not show failure, but when I then go /mnt/one and issue command ls -a there is nothing there. Why is this? The .gz files are very large. Why does the mounted partition show as blank even if the gunzip command completed?


Solution

  • Before you can write directly to a partition, you must first ensure that it is unmounted.

    Linux will not notice if you write directly to the disk behind its back (and, more importantly, will assume that this will not happen---it will likely get very confused if you try modifying a mounted file system.)

    So, the correct procedure would be as follows:

    umount /dev/xvdk
    gunzip –c mySda1.gz | dd of=/dev/xvdk
    mount /dev/xvdk
    

    and again for /dev/xvdl.