LVM是一个非常有用的工具,但是它似乎仍然不支持快照已经是快照的驱动器。 我做了一个脚本来自动处理,但遇到了一些麻烦。
我正在一个干净的Xen-box上testing脚本(从现在起: testbox )。 创build完箱子后,我创build了一个新的LVM卷,并将其添加到testing箱的驱动器中。 在testing盒本身,它显示为一个正常的块设备,所以我不认为Dom0的LVM应该干扰testing过程。
在testing箱上 ,我使用以下命令创build了一个新的分区:
# Using the data in the other tables i determined # where i could begin my new device sectors dmsetup table # Create the new device without a table dmsetup create base --notable # Put the table into the device... echo '0 4194304 linear 202:2 0' | dmsetup load base dmsetup resume base mkfs.ext2 /dev/mapper/base
要明确的是,第二个目标参数“202:2”是我添加到testing箱机器的第二个设备,我仔细检查它是这样的:
ls /dev -l | grep 'xvda2'
返回:
brw-rw —- 1根磁盘202,5月3日17:01 xvda2
我写了这个函数来做一个快照:
function create_dm_snapshot { banner "0: Checking if block devices don't allready exist, original device should exist..."; device_exists $base_path$original; [ $? -eq 0 ] || error 'The source (original) device should exist'; device_exists $base_path$snapshot_origin $base_path$snapshot $base_path$cow; [ $? -eq 0 ] && error "They allready exist pls use the 'remove' function"; echo "Done checking."; banner "1: Suspending the original device."; suspend_dev $original || error "Failed suspending original device"; banner "2: Creating snapshot-origin."; create_dev $snapshot_origin || error "Failed creating snapshot-origin"; banner "3: Read original table into snapshot-origin."; dmsetup table $original | dmsetup load $snapshot_origin || error 'Failed loading original table into snapshot-origin'; echo "Done reading."; banner "4: Resume snapshot-origin."; resume_dev $snapshot_origin || error 'Could not resume snapshot-origin'; banner "5: Create snapshot device."; create_dev $snapshot || error 'Failed to create snapshot device'; banner "6: Create COW-device."; #TODO: check total sector count device create_dev $cow ; target_device=$( dmsetup table $original | awk '{print $4}' ); last_table=$( dmsetup table | grep "$target_device" | awk '{print $6}' | sort -g | tail -n 1 ); begin_sector_args=( $( dmsetup table | grep -E $target_device".*"$last_table"|"$last_table".*"$target_device | awk '{print $2 " " $3 " " $6}' ) ); begin_sector=$( expr ${begin_sector_args[1]} - ${begin_sector_args[0]} + ${begin_sector_args[2]} ); table="0 $size linear $target_device $begin_sector"; echo $table | dmsetup load $cow; resume_dev $cow; banner "7: Calculate rowcount in snapshot-origin"; snapshot_origin_size=$( blockdev --getsz $base_path$snapshot_origin ) || error 'Could not determine rowcount'; echo "Snapshot size: $snapshot_origin_size"; banner "8: Load snapshot table."; table="0 $snapshot_origin_size snapshot $base_path$snapshot_origin $base_path$cow p 64"; [ $verbose ] && echo "Table: $table"; echo $table | dmsetup load $snapshot || error 'Failed loading snapshot table'; echo "Done loading."; banner "9: Reload original device table."; table="0 $snapshot_origin_size snapshot-origin $base_path$snapshot_origin"; [ $verbose ] && echo "Table: $table"; echo $table | dmsetup load $original || error 'Failed reloading original table'; echo "Done reloading."; banner "10: Resume frozen tables."; resume_dev $snapshot $original || error 'Could not resume devices'; echo "Done resuming."; }
在第8步(横幅“8:…)脚本失败,出现以下错误:
设备映射:重新加载ioctl失败:没有这样的设备或地址
命令失败
,
dmsetup table
结果如下表数据:
dm.base.snapshot_origin:0 4194304 linear 202:2 0
基数:0 4194304线性202:2 0
dm.base.snapshot:
dm.base.cow:0 4096 linear 202:2 4194304
由于我无法确定错误的原因,我所做的最后一步是查看我的dmesg …
dmesg | tail Giving me:
PM:0.080毫秒后完成设备的冻结
暂停xenstore …
下午:0.019毫秒后,完成设备的晚期冻结
PM:设备在0.035毫秒后提前完成恢复
PM:在32.367毫秒之后完成设备的恢复
将容量设置为10485760
设置容量为104857600
设备映射器:持久性快照:无效或损坏的快照
设备映射器:表:254:2:快照:无法读取快照元数据
设备映射程序:ioctl:将目标添加到表时出错
我无法找出是什么导致快照被破坏。
在一个干净的Xen盒上testing脚本
这并不保证导出的磁盘在其未写区域只包含零。 因此,内核可能会发现一些不是真的存在的东西。 你应该覆盖COW的第一部分(我不知道需要多less钱,但是前4个MiB应该足够了,哦,你的COW的体积还不到4 MiB:
dd if=/dev/zero of=/dev/mapper/dm.base.cow bs=4K count=1024
也许COW卷的尺寸是最小的,而你的尺寸太小了?