Fix reinstall of controller nodes

At shutdown, systemd will try to remount everything read-only
before attempting to unmount it. In the wipedisk script we
are deleting the partitions without unmounting
their corresponding filesystems. This leads to errors because
systemd will try to remount filesystems
whose partitions were deleted.

To fix this we have to unmount the filesystems that are linked to the
removed partitions.

Closes-Bug: 1919153
Signed-off-by: Mihnea Saracin <Mihnea.Saracin@windriver.com>
Change-Id: I49a3c06ae6bce1324dd06f4fc63fb3e5cd4d28c1
This commit is contained in:
Mihnea Saracin 2021-03-16 13:45:18 +02:00
parent 6cf5e84825
commit 497a6f93f4
1 changed files with 24 additions and 0 deletions

View File

@ -18,6 +18,28 @@ usage ()
exit 1
}
# Systemd automatically remounts all the mounted filesystems at shutdown
# When we are deleting a partition, we have to unmount its corresponding filesystem
# because remounting deleted filesystems at shutdown will throw errors
unmount_fs()
{
local fs=$1
local ret_code=0
echo "Trying to unmount $fs"
if findmnt $fs > /dev/null 2>&1 ; then
if umount -f $fs ; then
echo "$fs has been successfully unmounted"
else
echo "Error! Failed to unmount $fs"
ret_code=1
fi
else
echo "Warning! $fs is not mounted"
ret_code=2
fi
return $ret_code
}
OPTS=`getopt -o h -l force -- "$@"`
if [ $? != 0 ]
then
@ -131,6 +153,7 @@ do
# Skip / or we will lose access to the tools on the system.
if [[ $part != $rootfs_part ]]
then
unmount_fs $part
dd if=/dev/zero of=$part bs=512 count=34
dd if=/dev/zero of=$part bs=512 count=34 seek=$((`blockdev --getsz $part` - 34))
fi
@ -144,6 +167,7 @@ do
else
echo "Wiping $dev..."
wipefs -f -a $dev
unmount_fs $dev
# Clearing previous GPT tables or LVM data
# Delete the first few bytes at the start and end of the partition. This is required with