Skip to content

Commit

Permalink
Merge pull request #2621 from jestabro/clear-raid-on-install
Browse files Browse the repository at this point in the history
image-tools: T5806: clear previous raid configs on install
  • Loading branch information
jestabro committed Dec 14, 2023
2 parents 671d012 + e3cd779 commit 0d6b2d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions python/vyos/system/disk.py
Expand Up @@ -31,12 +31,17 @@ class DiskDetails:

def disk_cleanup(drive_path: str) -> None:
"""Clean up disk partition table (MBR and GPT)
Remove partition and device signatures.
Zeroize primary and secondary headers - first and last 17408 bytes
(512 bytes * 34 LBA) on a drive
Args:
drive_path (str): path to a drive that needs to be cleaned
"""
partitions: list[str] = partition_list(drive_path)
for partition in partitions:
run(f'wipefs -af {partition}')
run(f'wipefs -af {drive_path}')
run(f'sgdisk -Z {drive_path}')


Expand Down
31 changes: 19 additions & 12 deletions python/vyos/system/raid.py
Expand Up @@ -19,7 +19,7 @@
from shutil import copy
from dataclasses import dataclass

from vyos.utils.process import cmd
from vyos.utils.process import cmd, run
from vyos.system import disk


Expand All @@ -44,18 +44,11 @@ def raid_create(raid_members: list[str],
"""
raid_devices_num: int = len(raid_members)
raid_members_str: str = ' '.join(raid_members)
if Path('/sys/firmware/efi').exists():
for part in raid_members:
drive: str = disk.partition_parent(part)
command: str = f'sgdisk --typecode=3:A19D880F-05FC-4D3B-A006-743F0F84911E {drive}'
cmd(command)
else:
for part in raid_members:
drive: str = disk.partition_parent(part)
command: str = f'sgdisk --typecode=3:A19D880F-05FC-4D3B-A006-743F0F84911E {drive}'
cmd(command)
for part in raid_members:
command: str = f'mdadm --zero-superblock {part}'
drive: str = disk.partition_parent(part)
# set partition type GUID for raid member; cf.
# https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
command: str = f'sgdisk --typecode=3:A19D880F-05FC-4D3B-A006-743F0F84911E {drive}'
cmd(command)
command: str = f'mdadm --create /dev/{raid_name} -R --metadata=1.0 \
--raid-devices={raid_devices_num} --level={raid_level} \
Expand All @@ -72,6 +65,20 @@ def raid_create(raid_members: list[str],

return raid

def clear():
"""Deactivate all RAID arrays"""
command: str = 'mdadm --examine --scan'
raid_config = cmd(command)
if not raid_config:
return
command: str = 'mdadm --run /dev/md?*'
run(command)
command: str = 'mdadm --assemble --scan --auto=yes --symlink=no'
run(command)
command: str = 'mdadm --stop --scan'
run(command)


def update_initramfs() -> None:
"""Update initramfs"""
mdadm_script = '/etc/initramfs-tools/scripts/local-top/mdadm'
Expand Down
1 change: 1 addition & 0 deletions src/op_mode/image_installer.py
Expand Up @@ -179,6 +179,7 @@ def create_partitions(target_disk: str, target_size: int,
rootfs_size: int = available_size

print(MSG_INFO_INSTALL_PARTITONING)
raid.clear()
disk.disk_cleanup(target_disk)
disk_details: disk.DiskDetails = disk.parttable_create(target_disk,
rootfs_size)
Expand Down

0 comments on commit 0d6b2d8

Please sign in to comment.