I have a vmware ubuntu image on my machine which I want to overwrite my current partition.

When I run:

sudo qemu-img convert my-image.vmdk -O raw /dev/sda1 

I end up with below error:

qemu-img: /dev/sda1: error while converting raw: No space left on device

Is there anyway I can overwrite my existing HD partition without the error above?

link|improve this question

@fossfreedom I thought your answer was very useful - well not to me only but anyone googling the same queries as me. Anyway you have your discretion. – Bitmap Jun 27 '11 at 11:14
2  
one more try since no other answers yet... – fossfreedom Jun 28 '11 at 20:34
@fossfreedom thanks – Bitmap Jun 29 '11 at 8:24
feedback

1 Answer

up vote 2 down vote accepted

A VMDK file is basically an image of a hard-drive wrapped up in a format that VMWare virtual solutions & now VirtualBox can recognise.

VMWare ESX virtual hard-disks with a name format "somefilename-flat.vmdk" are basically direct byte-for-byte representation of a normal hard-disk. As such solution 2 below could be used to read and mount such a disk.

For VMDK files though, I think you were on the correct way of thinking using qemu, but I believe you need to go one stage further as demonstrated in solution 1.

solution 1

Create a raw image version of your vmdk and display the partitions in the vmdk using kpartx

qemu-img convert -O raw somefilename.vmdk rawimagefilename.raw
sudo apt-get install kpartx
sudo kpartx -av rawimagefilename.raw

This will produce loop mappings (/dev/mapper/loopXpY) per partition in the vmdk e.g.

loop0p1 : 0 15952482 /dev/loop0 63
loop0p2 : 0 819315 /dev/loop0 15952545
loop0p5 : 0 819252 loop0p1 63

Next create a folder in /media where we will mount one of the partitions represented by the loop mapping shown

sudo mkdir /media/partitionimage

Mount the partition that needs to be eventually restored in /dev/sda1

sudo mount /dev/mapper/loop0p2 /media/partitionimage -o loop,ro

You should be able now to browse the partition /media/partitionimage using nautilus

Backup the loop partition using tar:

cd /media/partitionimage
sudo tar cvpzf /home/somewhere/backup.tgz

You should really boot from a live CD to ensure /dev/sda1 is not in use.

You would restore the backup with something like

sudo mount /dev/sda1 /media/backup
sudo tar xvpfz /home/somewhere/backup.tgz -C /media/backup/

solution 2

Since xxx-flat.vmdk is really just a hard-disk in disguise you can mount and check the contents as follows:

sudo losetup /dev/loop0 <full path to the xxx-flat.vmdk file>
sudo losetup -o 32256 /dev/loop1 /dev/loop0
sudo mkdir /media/diskimage
sudo mount /dev/loop1 /media/diskimage
fdisk -l /dev/loop0

where 32256 is the offset calculated by multiplying the sector size (most often 63 [see here for more details]) with the VMDK sector size (assumed to be 512bytes)

If fdisk completes successfully then you can continue. You should be able to browse your vmdk file using Nautilus and browsing to /media/diskimage.

copying the contents of the vmdk to the hard-drive

First boot from a live disk

then copy the contents of the VMDK straight to your partition

sudo dd if=<path to vmdk file> of=/dev/sda1 bs=512 skip=63

where bs is the number of bytes per sector (found in the first step) and skip is the number of sectors (used in the first step)

source

link|improve this answer
when I run mount /dev/loop1 /mnt/diskimage I get the error mount: you must specify the filesystem type – Bitmap Jun 26 '11 at 21:03
I and did ls -l /dev/loop0 and this was the output i got brw-rw---- 1 root disk 7, 1 2011-06-26 22:02 /dev/loop0 – Bitmap Jun 26 '11 at 21:11
You are a star - this is priceless. – Bitmap Jun 29 '11 at 22:13
@Bitmap how did you resolve the "mount: you must specify the filesystem type" error? – realgt May 1 at 16:05
Do you know what I should've documented the solution step by step. What I did in the end was to use cronezilla to install the image onto my drive. I had another spare drive and so used that drive as slave to hold the image since the size was quiet huge, wiped the primary/master disk and then - using cronezilla install the image onto the primary drive. I worked like a charm. – Bitmap May 2 at 9:26
feedback

Your Answer

 
or
required, but never shown

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