Redhatin virtualisointi lisäsi tietoturvaa ja tehokkuutta (Enterprise-tason VDI)
Disks and HP CCISS p2v Migrating
Show all

Disks and Xen v2v Migrating

When migrating Xen virtual machines to libvirt/kvm noticed some disk images contained partition table within a partition.

The following shows how to fix this.

Disk Operation

Original disk content is in /dev/vg_data/lv_rhel3_disk2.

Setting the content as loop device:

# losetup -f /dev/vg_data/lv_rhel3_disk2

Verify loop device:

# losetup -a
/dev/loop0: [0005]:76463 (/dev/mapper/vg_data-lv_rhel3_disk2)

Check out partition table:

# fdisk -l /dev/loop0

Disk /dev/loop0: 78.4 GB, 78383153152 bytes
255 heads, 63 sectors/track, 9529 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a3ef7

Device Boot Start End Blocks Id System
/dev/loop0p1 * 1 8856 71135788+ 83 Linux

When the partition table contains entries like hdb1p1 or like this one loop0p1 there’s most likely a partition table within that partition.

Read loop0 partition table to our system (device mapper):

# kpartx -av /dev/loop0
add map loop0p1 (253:7): 0 142271577 linear /dev/loop0 63

Now setup new loop device using device mapper entry:

# losetup -f /dev/mapper/loop0p1

Verify again:

# losetup -a
/dev/loop0: [0005]:76463 (/dev/mapper/vg_data-lv_rhel3_disk2)
/dev/loop1: [0005]:94497 (/dev/mapper/loop0p1)

Now create new lv for the content we need to have:

# lvcreate --name lv_rhel3_new_disk2 --size 73G vg_data
Logical volume "lv_rhel3_new_disk2" created

Copy the content:

# dd if=/dev/loop1 of=/dev/vg_data/lv_rhel3_new_disk2 bs=1024k
69468+1 records in
69468+1 records out
72843047424 bytes (73 GB) copied, 427.714 s, 170 MB/s

Renaming the lv so that our configuration is still the same:

# lvrename /dev/vg_data/lv_rhel3_disk2 lv_rhel3_old_disk2
Renamed "lv_rhel3_disk2" to "lv_rhel3_old_disk2" in volume group "vg_data"
# lvrename /dev/vg_data/lv_rhel3_new_disk2 lv_rhel3_disk2
Renamed "lv_rhel3_new_disk2" to "lv_rhel3_disk2" in volume group "vg_data"

Garbage collection:

# losetup -d /dev/loop1
# kpartx -dv /dev/loop0
del devmap : loop0p1
# losetup -d /dev/loop0
# losetup -a