As there are already so many pre-built VMware images, we don't need rebuild
them for other VMMs (Virtual Machine Monitor) such as Xen, QEMU, etc. We can
just convert the disk from vmdk to raw.
There are several ways to get it done. The following tutorial use
an VMware guest OS which has 40G disk image and the image is divided into 2G
files:
Convert VMDK to RAW using qemu-img is a unofficial method, but has been proven
reliable and efficient. You should download and install QEMU first. The
following script "vmdk2raw.sh" can do this job:
#!/bin/sh
for i in `ls *[0-9].vmdk`; do
qemu-img convert -f vmdk $i -O raw ${i/vmdk/raw}
done
cat *.raw >> system.img
Using Xen Blktap driver
We can also make use of the xen blktap driver. Attach the disk image to a
running domain (dom0 also works) and dd it out:
Using VMware tools to mount the VMDK image and copy the contents
to a RAW disk.
First we should mount the filesystem within the disk.
Use vmware-mount.pl:
# make mount point
# mkdir -p /tmp/vmdk_mount_point
## print the partition table
# vmware-mount.pl -p /RHEL4U4/RHEL4U4.vmdk
Nr Start Size Type Id Sytem
-- ---------- ---------- ---- -- ------------------------
1 63 82815012 BIOS 83 Linux
2 82815075 1044225 BIOS 82 Linux swap
## mount the first partition
# vmware-mount.pl /RHEL4U4/RHEL4U4.vmdk 1 /tmp/vmdk_mount_point/
In fact, vmware-mount.pl is a wrapper of vmware-loop. When vmware-mount.pl
don't work properly, you can use vmware-loop directly:
## make Network Block Device (NBD) file node
# mknod /tmp/vmdk.nbd b 43 0
## print the partition table
# vmware-loop -p /RHEL4U4/RHEL4U4.vmdk
Nr Start Size Type Id Sytem
-- ---------- ---------- ---- -- ------------------------
1 63 82815012 BIOS 83 Linux
2 82815075 1044225 BIOS 82 Linux swap
## mount the first partition
# vmware-loop /RHEL4U4/RHEL4U4.vmdk 1 /tmp/vmdk.nbd
## open another terminal and mount the device
# mount /tmp/vmdk.nbd /tmp/vmdk_mount_point
Then you can make a 40G raw disk image and copy the contents using the
following scripts:
#!/bin/sh
# Create 40G sparse file
dd if=/dev/zero of=/tmp/disk.img bs=1M seek=40960 count=0
# Loop back it
losetup /dev/loop0 system.img
# Do partitioning, using here documents. Change it to fit your schema.
fdisk /dev/loop0 <<EOF
n
p
1
w
EOF
# Create device maps for the partitions
kpartx -a /dev/loop0
# Make filesystem
mkfs.ext3 /dev/mapper/loop0p1
# Make mount point
mkdir -p /tmp/raw_mount_point
# Do mount
mount /dev/mapper/loop0p1 /tmp/raw_mount_point
# Copy contents
cd /tmp/vmdk_mount_point; find . | cpio -pdumv /tmp/raw_mount_point
Convet VMDK Disk Image to RAW
As there are already so many pre-built VMware images, we don't need rebuild them for other VMMs (Virtual Machine Monitor) such as Xen, QEMU, etc. We can just convert the disk from vmdk to raw.
There are several ways to get it done. The following tutorial use an VMware guest OS which has 40G disk image and the image is divided into 2G files:
Using qemu-img
Convert VMDK to RAW using qemu-img is a unofficial method, but has been proven reliable and efficient. You should download and install QEMU first. The following script "vmdk2raw.sh" can do this job:
#!/bin/sh for i in `ls *[0-9].vmdk`; do qemu-img convert -f vmdk $i -O raw ${i/vmdk/raw} done cat *.raw >> system.imgUsing Xen Blktap driver
We can also make use of the xen blktap driver. Attach the disk image to a running domain (dom0 also works) and dd it out:
Using VMware tools to mount the VMDK image and copy the contents to a RAW disk.
First we should mount the filesystem within the disk.
Use vmware-mount.pl:
In fact, vmware-mount.pl is a wrapper of vmware-loop. When vmware-mount.pl don't work properly, you can use vmware-loop directly:
Then you can make a 40G raw disk image and copy the contents using the following scripts:
Reference
Categories
Feeds
Tags
Copyright © 2012 Zhigang Wang. Some right reserved.
The views expressed on this web site are my own and do not necessarily reflect the views of Oracle.