1

I have several KVM raw files that are read only (about 100gb).

I am adding these raw files as loopback devices.

I then create a snap file to allow the VM to have read/write access to its disk. This allows me to insert modifications, test, wipe the snap and repeat.

Snippet of my perl script:

$base_file = "/images/vmbase.raw";
$base_stats = stat($base_file);
$base_blocks = $base_stats->size / 512;
$base_size = floor($base_stats->size / 10**6);
system("dd if=/dev/zero of=/dev/shm/vmbase.snap count=1 bs=1M seek=$base_size");
$baseloop='losetup -f --show /images/vmbase.raw --read-only';
$snaploop='losetup -f --show /dev/shm/vmbase.snap';
system("dmsetup create vmdrive --table "0  snapshot $baseloop");`

This creates a device called /dev/mapper/vmdrive that I then attach to my virtual machine. I can use parted /dev/mapper/vmdrive to see the available partitions. Now, it would great to switch to thin provisioning to see if I get a performance gain.

Here is what I tried (used the "cookbook" from https://www.kernel.org/doc/Documentation/device-mapper/thin-provisioning.txt)

First I create some block devices using loops:

meta: 2GB

snap: 24GB

dd if=/dev/zero of=/dev/shm/vmbase.meta bs=4096 count=524288
dd if=/dev/zero of=/snaps/vmbase.snap bs=4096 count=5859385
losetup -f /images/vmbase.raw --read-only
losetup -f /dev/shm/vmbase.meta
losetup -f /snaps/vmbase.snap`

Then I create the pool device: (assume loop0 for raw, loop1 for meta and loop2 for snap) I use a 1MB block size and 2GB as my low free space threshold

$ dmsetup create vmbase-pool \
      --table "0 20971520 thin-pool /dev/loop1 /dev/loop0 2048 2048

Follow that up by generating the snap of the external block device (my raw file)

$ dmsetup message /dev/mapper/vmbase-pool 0 "create_thin 0"
$ dmsnap create vmsnap \
      --table "0 20971520 thin /dev/mapper/vmbase-pool 0 /dev/loop0"

I then attach the /dev/mapper/vmsnap device to my virtual machine and it won't boot. When I use parted to print the partition table I get errors. Part of this is I need to be able to launch multiple copies of the virtual machine at once.

I'm using RHEL 6.7 with kernel 2.6.32-573.7.1

Where am I going wrong?

1

Found the issue(s).

1: The data backing volume of a thin-pool needs to be the same size or larger of the base block device. The data backing volume dd creation command should have the same block size and "$base_size" as my original snap.

2: The second number in the table definition of the dmsetup create thin_pool command should be the block device's number of blocks, which is obtained by the following code:

my $base_stats = stat($base_file);
my $base_blocks = $base_stats->size / 512;

Finally the command to create the thin pool is follows:

system("dmsetup create vm-pool\
   --table \"0 $base_blocks thin-pool $meta_lodev $snap_lodev 2048 2048\"");

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.