From c02a3ab79f97aaaea5ecdb288a0a20bb2fa464b4 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 10 May 2017 11:17:58 +0200 Subject: [PATCH] TT#15829 Wipe any possibly existing LVM/PV label from target disk Starting with lvm2 v2.02.111 it includes a udev rules file named /lib/udev/rules.d/69-dm-lvm-metad.rules (see http://sources.debian.net/src/lvm2/2.02.111-2.2%2Bdeb8u1/udev/69-dm-lvm-metad.rules.in/ wheras its "(PVSCAN_RULE)" corresponds to RUN+="/sbin/lvm pvscan --cache --activate ay --major $major --minor $minor", ENV{LVM_SCANNED}="1" in the installed /lib/udev/rules.d/69-dm-lvm-metad.rules). The udev rule gets triggered during disk changes and automatically invokes `lvm pvscan [...]`, triggering the following behavior if a LV is already present on a disk: | # dmsetup ls # it's empty | # parted -s /dev/sda mklabel msdos | # parted -s /dev/sda mkpart primary 1048576B 8589934591B | # dmsetup ls # this will list already existing LVs, like: | vg0-swap .... | vg0-root ... | # blockdev --rereadpt /dev/sda # this will fail now with "Device or resource busy" This causes deployments to fail if it's reinstalled on a system that already had any LVs on the target disks. Change-Id: I35cdd437e2c8de0ca956adce9891bb0b23f70d3b --- deployment.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/deployment.sh b/deployment.sh index 9bb2fa2..e90c577 100644 --- a/deployment.sh +++ b/deployment.sh @@ -1165,7 +1165,12 @@ ${VG_NAME}-root / -95% ext3 rw ${VG_NAME}-swap swap RAM:50% swap sw $lv_create_opts EOF - # make sure setup-storage doesn't fail if LVM is already present + # make sure setup-storage/parted doesn't fail if LVM is already present + blockdev --rereadpt "/dev/${DISK}" + for disk in "/dev/${DISK}"* ; do + logit "Removing possibly existing LVM/PV label from $disk" + pvremove "$disk" --force --force --yes || true + done dd if=/dev/zero of="/dev/${DISK}" bs=1M count=1 blockdev --rereadpt "/dev/${DISK}"