From 839afff896000c3b54c51256eff8fa00b0dedb17 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 2 Jun 2021 13:13:26 +0200 Subject: [PATCH] disks: wipe blockdev: pass all child partitions to wipefs Signed-off-by: Thomas Lamprecht --- PVE/Diskmanage.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index e81692d..6db5279 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -909,9 +909,20 @@ sub wipe_blockdev { my $size = ($dev_size * 512 / 1024 / 1024); my $count = ($size < 200) ? $size : 200; - print "wiping disk/partition: ${devpath}\n"; + my $to_wipe = []; + dir_glob_foreach("/sys/class/block/${devname}", "${devname}.+", sub { + my ($part) = @_; + push $to_wipe->@*, "/dev/${part}" if -b "/dev/${part}"; + }); + + if (scalar($to_wipe->$#*) > 0) { + print "found child partitions to wipe: ". join($to_wipe->@*, ',') ."\n"; + } + push $to_wipe->@*, $devpath; # put actual device last + + print "wiping block device ${devpath}\n"; - run_command(['wipefs', '--all', $devpath], errmsg => "error wiping '${devpath}'"); + run_command(['wipefs', '--all', $to_wipe->@*], errmsg => "error wiping '${devpath}'"); run_command( ['dd', 'if=/dev/zero', "of=${devpath}", 'bs=1M', 'conv=fdatasync', "count=${count}"], -- 2.39.2