Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions aii-ks/src/main/perl/ks.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#${PMpre} NCM::Component::ks${PMpost}

use EDG::WP4::CCM::Path qw (escape unescape);
use NCM::Filesystem 18.12.0;
use NCM::Filesystem 19.12.1;
use NCM::Partition qw (partition_sort);
use NCM::BlockdevFactory 18.12.0 qw (build);
use NCM::BlockdevFactory 19.12.1 qw (build);

use LC::Exception qw (throw_error);
use CAF::FileWriter;
Expand Down Expand Up @@ -732,6 +732,9 @@ sub pre_install_script
my $logfile = '/tmp/pre-log.log';
my $logaction = log_action($config, $logfile);

my $kstree = $config->getElement(KS)->getTree;
my $version = get_anaconda_version($kstree);

print <<EOF;
%pre

Expand All @@ -750,22 +753,57 @@ set -x

EOF

print <<'EOF';
if ($version < ANACONDA_VERSION_EL_6_0) {
print <<'EOF';
wipe_metadata () {
local path clear SIZE ENDSEEK ENDSEEK_OFFSET
path="$1"

# Hack for RHEL 6: force re-reading the partition table
#
# fdisk often fails to re-read the partition table on RHEL 6, so we have to do
# it explicitely. We also have to make sure that udev had enough time to create
# the device nodes.
rereadpt () {
[ -x /sbin/udevadm ] && udevadm settle
# hdparm can still fail with EBUSY without the wait...
sleep 2
hdparm -q -z "$1"
[ -x /sbin/udevadm ] && udevadm settle
# Just in case...
sleep 2
# default to 1
clearmb="${2:-1}"

# wipe at least 4 MiB at begin and end
ENDSEEK_OFFSET=4
if [ "$clearmb" -gt $ENDSEEK_OFFSET ]; then
ENDSEEK_OFFSET=$clearmb
fi

# try to get the size with fdisk
SIZE=`disksize_MiB "$path"`

# if empty, assume we failed and try with parted
if [ $SIZE -eq 0 ]; then
# the SIZE has not been determined,
# set it equal to ENDSEEK_OFFSET, the entire disk gets wiped.
SIZE=$ENDSEEK_OFFSET
echo "[WARN] Could not determine the size of device $path with both fdisk and parted. Wiping whole drive instead"
fi

let ENDSEEK=$SIZE-$ENDSEEK_OFFSET
if [ $ENDSEEK -lt 0 ]; then
ENDSEEK=0
fi
echo "[INFO] wipe path $path with SIZE $SIZE and ENDSEEK $ENDSEEK"
# dd with 1 MiB blocksize (unit used by disksize_MiB and faster then e.g. bs=512)
dd if=/dev/zero of="$path" bs=1048576 count=$ENDSEEK_OFFSET
dd if=/dev/zero of="$path" bs=1048576 seek=$ENDSEEK
sync
}
EOF
} else {
my $force = $version >= ANACONDA_VERSION_EL_7_0 ? " --force" : "";
print <<"EOF";
wipe_metadata () {
local path
path="\$1"

wipefs --all$force "\$path"
dmsetup remove --retry "\$path" 2>/dev/null
}
EOF
}

print <<'EOF';

disksize_MiB () {
local path BYTES MB RET
Expand Down Expand Up @@ -809,41 +847,6 @@ valid_disksize_MiB () {
return $RET
}

wipe_metadata () {
local path clear SIZE ENDSEEK ENDSEEK_OFFSET
path="$1"

# default to 1
clearmb="${2:-1}"

# wipe at least 4 MiB at begin and end
ENDSEEK_OFFSET=4
if [ "$clearmb" -gt $ENDSEEK_OFFSET ]; then
ENDSEEK_OFFSET=$clearmb
fi

# try to get the size with fdisk
SIZE=`disksize_MiB "$path"`

# if empty, assume we failed and try with parted
if [ $SIZE -eq 0 ]; then
# the SIZE has not been determined,
# set it equal to ENDSEEK_OFFSET, the entire disk gets wiped.
SIZE=$ENDSEEK_OFFSET
echo "[WARN] Could not determine the size of device $path with both fdisk and parted. Wiping whole drive instead"
fi

let ENDSEEK=$SIZE-$ENDSEEK_OFFSET
if [ $ENDSEEK -lt 0 ]; then
ENDSEEK=0
fi
echo "[INFO] wipe path $path with SIZE $SIZE and ENDSEEK $ENDSEEK"
# dd with 1 MiB blocksize (unit used by disksize_MiB and faster then e.g. bs=512)
dd if=/dev/zero of="$path" bs=1048576 count=$ENDSEEK_OFFSET
dd if=/dev/zero of="$path" bs=1048576 seek=$ENDSEEK
sync
}

EOF

# Hook handling should come here, to allow NIKHEF to override
Expand All @@ -856,9 +859,6 @@ EOF

ksuserhooks ($config, PREENDHOOK);

my $kstree = $config->getElement(KS)->getTree;
my $version = get_anaconda_version($kstree);

print <<EOF;

# De-activate logical volumes. Needed on RHEL6, see:
Expand Down
4 changes: 0 additions & 4 deletions aii-ks/src/test/resources/regexps/pre_blocksize_blockdevices
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Test the blockdevice generation in the pre section with disk with valid size def
^\s{4}fi$
^\s{4}end=\$\(\(begin \+ 100 \* \(1024 \* 1024 / sectsize\) - 1\)\)
^\s{4}parted /dev/sdb -s -- u s mkpart primary \$begin \$end$
^\s{4}wipe_metadata /dev/sdb1$
^\s{4}echo /dev/sdb1 >> /tmp/created_partitions$
^fi$
^valid_disksize_MiB /dev/sdb 3996 400[34]$
Expand Down Expand Up @@ -61,7 +60,6 @@ Test the blockdevice generation in the pre section with disk with valid size def
^\s{4}fi$
^\s{4}end=\$\(\(begin \+ 100 \* \(1024 \* 1024 / sectsize\) - 1\)\)
^\s{4}parted /dev/sdb -s -- u s mkpart primary \$begin \$end$
^\s{4}wipe_metadata /dev/sdb2$
^\s{4}echo /dev/sdb2 >> /tmp/created_partitions$
^fi$
^valid_disksize_MiB /dev/sdb 3996 400[34]$
Expand Down Expand Up @@ -92,7 +90,6 @@ Test the blockdevice generation in the pre section with disk with valid size def
^\s{4}fi$
^\s{4}end=\$\(\(begin \+ 2500 \* \(1024 \* 1024 / sectsize\) - 1\)\)
^\s{4}parted /dev/sdb -s -- u s mkpart extended \$begin \$end$
^\s{4}wipe_metadata /dev/sdb3$
^\s{4}echo /dev/sdb3 >> /tmp/created_partitions$
^fi$
^valid_disksize_MiB /dev/sdb 3996 400[34]$
Expand Down Expand Up @@ -123,7 +120,6 @@ Test the blockdevice generation in the pre section with disk with valid size def
^\s{4}fi$
^\s{4}end=\$\(\(begin \+ 1024 \* \(1024 \* 1024 / sectsize\) - 1\)\)
^\s{4}parted /dev/sdb -s -- u s mkpart logical \$begin \$end$
^\s{4}wipe_metadata /dev/sdb4$
^\s{4}echo /dev/sdb4 >> /tmp/created_partitions$
^fi$
^lvm vgscan --mknodes$
Expand Down
78 changes: 31 additions & 47 deletions aii-ks/src/test/resources/regexps/pre_noblock_functions
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,38 @@ Test the functions in the pre section
^echo 'Begin of pre section'$
^set -x$
^$
^wipe_metadata \(\) \{$
^\s{4}local path clear SIZE ENDSEEK ENDSEEK_OFFSET$
^\s{4}path="\$1"$
^$
^\# Hack for RHEL 6: force re-reading the partition table$
^\#$
^\# fdisk often fails to re-read the partition table on RHEL 6, so we have to do$
^\# it explicitely. We also have to make sure that udev had enough time to create$
^\# the device nodes.$
^rereadpt \(\) \{$
^\s{4}\[ -x /sbin/udevadm \] && udevadm settle$
^\s{4}\# hdparm can still fail with EBUSY without the wait...$
^\s{4}sleep 2$
^\s{4}hdparm -q -z "\$1"$
^\s{4}\[ -x /sbin/udevadm \] && udevadm settle$
^\s{4}\# Just in case...$
^\s{4}sleep 2$
^\s{4}# default to 1$
^\s{4}clearmb="\$\{2:-1\}"$
^$
^\s{4}# wipe at least 4 MiB at begin and end$
^\s{4}ENDSEEK_OFFSET=4$
^\s{4}if \[ "\$clearmb" -gt \$ENDSEEK_OFFSET \]; then$
^\s{8}ENDSEEK_OFFSET=\$clearmb$
^\s{4}fi$
^\s{4}\# try to get the size with fdisk$
^\s{4}SIZE=`disksize_MiB "\$path"`$
^$
^\s{4}\# if empty, assume we failed and try with parted$
^\s{4}if \[ \$SIZE -eq 0 \]; then$
^\s{8}\# the SIZE has not been determined,$
^\s{8}\# set it equal to ENDSEEK_OFFSET, the entire disk gets wiped.$
^\s{8}SIZE=\$ENDSEEK_OFFSET$
^\s{8}echo "\[WARN\] Could not determine the size of device \$path with both fdisk and parted. Wiping whole drive instead"$
^\s{4}fi$
^$
^\s{4}let ENDSEEK=\$SIZE-\$ENDSEEK_OFFSET$
^\s{4}if \[ \$ENDSEEK -lt 0 \]; then$
^\s{8}ENDSEEK=0$
^\s{4}fi$
^\s{4}echo "\[INFO\] wipe path \$path with SIZE \$SIZE and ENDSEEK \$ENDSEEK"$
^\s{4}\# dd with 1 MiB blocksize \(unit used by disksize_MiB and faster then e.g. bs=512\)$
^\s{4}dd if=/dev/zero of="\$path" bs=1048576 count=\$ENDSEEK_OFFSET$
^\s{4}dd if=/dev/zero of="\$path" bs=1048576 seek=\$ENDSEEK$
^\s{4}sync$
^\}$
^$
^disksize_MiB \(\) \{$
Expand Down Expand Up @@ -61,37 +79,3 @@ Test the functions in the pre section
^\s{4}echo "\[\$msg\] Found path \$path size \$SIZE min \$min max \$max"$
^\s{4}return \$RET$
^\}$
^$
^wipe_metadata \(\) \{$
^\s{4}local path clear SIZE ENDSEEK ENDSEEK_OFFSET$
^\s{4}path="\$1"$
^$
^\s{4}# default to 1$
^\s{4}clearmb="\$\{2:-1\}"$
^$
^\s{4}# wipe at least 4 MiB at begin and end$
^\s{4}ENDSEEK_OFFSET=4$
^\s{4}if \[ "\$clearmb" -gt \$ENDSEEK_OFFSET \]; then$
^\s{8}ENDSEEK_OFFSET=\$clearmb$
^\s{4}fi$
^\s{4}\# try to get the size with fdisk$
^\s{4}SIZE=`disksize_MiB "\$path"`$
^$
^\s{4}\# if empty, assume we failed and try with parted$
^\s{4}if \[ \$SIZE -eq 0 \]; then$
^\s{8}\# the SIZE has not been determined,$
^\s{8}\# set it equal to ENDSEEK_OFFSET, the entire disk gets wiped.$
^\s{8}SIZE=\$ENDSEEK_OFFSET$
^\s{8}echo "\[WARN\] Could not determine the size of device \$path with both fdisk and parted. Wiping whole drive instead"$
^\s{4}fi$
^$
^\s{4}let ENDSEEK=\$SIZE-\$ENDSEEK_OFFSET$
^\s{4}if \[ \$ENDSEEK -lt 0 \]; then$
^\s{8}ENDSEEK=0$
^\s{4}fi$
^\s{4}echo "\[INFO\] wipe path \$path with SIZE \$SIZE and ENDSEEK \$ENDSEEK"$
^\s{4}\# dd with 1 MiB blocksize \(unit used by disksize_MiB and faster then e.g. bs=512\)$
^\s{4}dd if=/dev/zero of="\$path" bs=1048576 count=\$ENDSEEK_OFFSET$
^\s{4}dd if=/dev/zero of="\$path" bs=1048576 seek=\$ENDSEEK$
^\s{4}sync$
^\}$