Skip to content

Commit

Permalink
Update LVM
Browse files Browse the repository at this point in the history
  • Loading branch information
svartkanin committed Nov 19, 2023
1 parent 5088f54 commit 6bc0e25
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 125 deletions.
16 changes: 7 additions & 9 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,7 @@ def lvm_pv_create(self, pvs: List[PartitionModification]):
cmd = 'pvcreate ' + ' '.join([str(pv.safe_dev_path) for pv in pvs])
debug(f'Creating LVM PVS: {cmd}')

# SysCommand(cmd, peek_output=True)

worker = SysCommandWorker(cmd)
worker.poll()
info(worker)
worker.write(b'y\n', line_ending=False)
SysCommand(cmd)

def lvm_group_create(self, vg: LvmVolumeGroup):
pvs_str = ' '.join([str(pv.safe_dev_path) for pv in vg.pvs])
Expand All @@ -302,11 +297,14 @@ def lvm_group_create(self, vg: LvmVolumeGroup):

def lvm_vol_create(self, vg_name: str, volume: LvmVolume, offset: Size):
length = volume.length - offset
length = length.format_size(Unit.B, include_unit=False)
cmd = f'lvcreate -L {length}B {vg_name} -n {volume.name} --wipesignatures y --zero y --yes'
length_str = length.format_size(Unit.B, include_unit=False)
cmd = f'lvcreate -L {length_str}B {vg_name} -n {volume.name} --wipesignatures y --zero y'

debug(f'Creating volume: {cmd}')
SysCommand(cmd)

worker = SysCommandWorker(cmd)
worker.poll()
worker.write(b'y\n', line_ending=False)

volume.dev_path = f'/dev/{vg_name}/{volume.name}'

Expand Down
31 changes: 31 additions & 0 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ class LvmVolume:
mount_options: List[str] = field(default_factory=list)
btrfs_subvols: List[SubvolumeModification] = field(default_factory=list)

# mapper device path /dev/<vg>/<vol>
dev_path: Optional[Path] = None

@property
Expand All @@ -926,6 +927,12 @@ def safe_dev_path(self) -> Path:
return self.dev_path
raise ValueError('No device path for volume defined')

@property
def safe_fs_type(self) -> FilesystemType:
if self.fs_type is None:
raise ValueError('File system type is not set')
return self.fs_type

@property
def relative_mountpoint(self) -> Path:
"""
Expand Down Expand Up @@ -981,6 +988,16 @@ def exists(self) -> bool:
def is_exists_or_modify(self) -> bool:
return self.status in [LvmVolumeStatus.Exist, LvmVolumeStatus.Modify]

def is_root(self) -> bool:
if self.mountpoint is not None:
return Path('/') == self.mountpoint
else:
for subvol in self.btrfs_subvols:
if subvol.is_root():
return True

return False


@dataclass
class LvmGroupInfo:
Expand Down Expand Up @@ -1022,6 +1039,20 @@ def parse_arg(arg: Dict[str, Any], disk_config: DiskLayoutConfiguration) -> LvmC
vol_groups=[LvmVolumeGroup.parse_arg(vol_group, disk_config) for vol_group in arg['vol_groups']],
)

def get_all_pvs(self) -> List[PartitionModification]:
pvs = []
for vg in self.vol_groups:
pvs += vg.pvs

return pvs

def get_root_volume(self) -> Optional[LvmVolume]:
for vg in self.vol_groups:
filtered = next(filter(lambda x: x.is_root(), vg.volumes), None)
if filtered:
return filtered

return None

@dataclass
class DeviceModification:
Expand Down
4 changes: 3 additions & 1 deletion archinstall/lib/disk/disk_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ def _prev_lvm_config(self) -> Optional[str]:
pv_table = FormattedOutput.as_table(vol_gp.pvs)
output += '{}:\n{}'.format(str(_('Physical volumes')), pv_table)

output += f'\nVolume Group: {vol_gp.name}'

lvm_volumes = FormattedOutput.as_table(vol_gp.volumes)
output += '\n{}:\n{}'.format(str(_('Volumes')), lvm_volumes)
output += '\n\n{}:\n{}'.format(str(_('Volumes')), lvm_volumes)

return output

Expand Down
10 changes: 7 additions & 3 deletions archinstall/lib/disk/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def perform_filesystem_operations(self, show_countdown: bool = True):
for mod in device_mods:
if boot_part := mod.get_boot_partition():
info(f'Formatting boot partition: {boot_part.dev_path}')
device_handler.format_partitions(
self.format_partitions(
[boot_part],
mod.device_path
)

self.setup_lvm(self._disk_config.lvm_config)
else:
for mod in device_mods:
device_handler.format_partitions(
self.format_partitions(
mod.partitions,
mod.device_path,
enc_conf=self._enc_config
Expand Down Expand Up @@ -162,10 +162,14 @@ def setup_lvm(

for volume in vol_gp.volumes:
device_handler.lvm_vol_create(vol_gp.name, volume, offset)
device_handler.format(volume.fs_type, volume.safe_dev_path)

self._lvm_vol_handle_e2scrub(vol_gp)

for volume in vol_gp.volumes:
# wait a bit otherwise the mkfs will fail as it can't
# find the mapper device yet
device_handler.format(volume.fs_type, volume.safe_dev_path)

def _lvm_vol_handle_e2scrub(self, vol_gp: LvmVolumeGroup):
# from arch wiki:
# If a logical volume will be formatted with ext4, leave at least 256 MiB
Expand Down
Loading

0 comments on commit 6bc0e25

Please sign in to comment.