Skip to content

Commit 747385a

Browse files
authored
Lvm2/LUKS fixes/Mirror Logic (#4047)
* Lvm hotfix attempt * Use --force and --yes flags * Changed mirror behavior and more lvm testing * Handle properly LvmOnLuks to only export in one fo the scenarios * Idek * Remove dead block * Use -f flag and wipefs to remove any existing headers avoid "has signatures" * oops * Revert mirror change
1 parent ac984b7 commit 747385a

3 files changed

Lines changed: 39 additions & 33 deletions

File tree

archinstall/lib/disk/device_handler.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,22 @@ def lvm_export_vg(self, vg: LvmVolumeGroup) -> None:
464464
SysCommand(cmd)
465465

466466
def lvm_import_vg(self, vg: LvmVolumeGroup) -> None:
467-
cmd = f'vgimport {vg.name}'
467+
# Check if the VG is actually exported before trying to import it
468+
check_cmd = f'vgs --noheadings -o vg_exported {vg.name}'
469+
470+
try:
471+
result = SysCommand(check_cmd)
472+
is_exported = result.decode().strip() == 'exported'
473+
except SysCallError:
474+
# VG might not exist yet, skip import
475+
debug(f'Volume group {vg.name} not found, skipping import')
476+
return
477+
478+
if not is_exported:
479+
debug(f'Volume group {vg.name} is already active (not exported), skipping import')
480+
return
468481

482+
cmd = f'vgimport {vg.name}'
469483
debug(f'vgimport: {cmd}')
470484
SysCommand(cmd)
471485

@@ -477,33 +491,22 @@ def lvm_vol_reduce(self, vol_path: Path, amount: Size) -> None:
477491
SysCommand(cmd)
478492

479493
def lvm_pv_create(self, pvs: Iterable[Path]) -> None:
480-
cmd = 'pvcreate ' + ' '.join([str(pv) for pv in pvs])
494+
pvs_str = ' '.join([str(pv) for pv in pvs])
495+
# Signatures are already wiped by wipefs, -f is just for safety
496+
cmd = f'pvcreate -f --yes {pvs_str}'
497+
# note flags used in scripting
481498
debug(f'Creating LVM PVS: {cmd}')
482-
483-
worker = SysCommandWorker(cmd)
484-
worker.poll()
485-
worker.write(b'y\n', line_ending=False)
486-
487-
# Wait for the command to complete
488-
while worker.is_alive():
489-
worker.poll()
499+
SysCommand(cmd)
490500

491501
# Sync with udev to ensure the PVs are visible
492502
self.udev_sync()
493503

494504
def lvm_vg_create(self, pvs: Iterable[Path], vg_name: str) -> None:
495505
pvs_str = ' '.join([str(pv) for pv in pvs])
496-
cmd = f'vgcreate --yes {vg_name} {pvs_str}'
506+
cmd = f'vgcreate --yes --force {vg_name} {pvs_str}'
497507

498508
debug(f'Creating LVM group: {cmd}')
499-
500-
worker = SysCommandWorker(cmd)
501-
worker.poll()
502-
worker.write(b'y\n', line_ending=False)
503-
504-
# Wait for the command to complete
505-
while worker.is_alive():
506-
worker.poll()
509+
SysCommand(cmd)
507510

508511
# Sync with udev to ensure the VG is visible
509512
self.udev_sync()
@@ -750,6 +753,17 @@ def partition(
750753

751754
disk.commit()
752755

756+
# Wipe filesystem/LVM signatures from newly created partitions
757+
# to prevent "signature detected" errors
758+
for part_mod in filtered_part:
759+
if part_mod.dev_path:
760+
debug(f'Wiping signatures from: {part_mod.dev_path}')
761+
SysCommand(f'wipefs --all {part_mod.dev_path}')
762+
763+
# Sync with udev after wiping signatures
764+
if filtered_part:
765+
self.udev_sync()
766+
753767
@staticmethod
754768
def swapon(path: Path) -> None:
755769
try:

archinstall/lib/disk/filesystem.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,19 @@ def _setup_lvm_encrypted(self, lvm_config: LvmConfiguration, enc_config: DiskEnc
145145
self._setup_lvm(lvm_config, enc_mods)
146146
self._format_lvm_vols(lvm_config)
147147

148-
# export the lvm group safely otherwise the Luks cannot be closed
149-
self._safely_close_lvm(lvm_config)
150-
151-
for luks in enc_mods.values():
152-
luks.lock()
148+
# Don't close LVM or LUKS during setup - keep everything active
149+
# The installation phase will handle unlocking and mounting
150+
# Closing causes "parent leaked" and lvchange errors
153151
elif enc_config.encryption_type == EncryptionType.LuksOnLvm:
154152
self._setup_lvm(lvm_config)
155153
enc_vols = self._encrypt_lvm_vols(lvm_config, enc_config, False)
156154
self._format_lvm_vols(lvm_config, enc_vols)
157155

156+
# Lock LUKS devices but keep LVM active
157+
# LVM volumes must remain active for later re-unlock during installation
158158
for luks in enc_vols.values():
159159
luks.lock()
160160

161-
self._safely_close_lvm(lvm_config)
162-
163-
def _safely_close_lvm(self, lvm_config: LvmConfiguration) -> None:
164-
for vg in lvm_config.vol_groups:
165-
for vol in vg.volumes:
166-
device_handler.lvm_vol_change(vol, False)
167-
168-
device_handler.lvm_export_vg(vg)
169-
170161
def _setup_lvm(
171162
self,
172163
lvm_config: LvmConfiguration,

archinstall/lib/installer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def mount_ordered_layout(self) -> None:
248248

249249
match self._disk_encryption.encryption_type:
250250
case EncryptionType.NoEncryption:
251+
self._import_lvm()
251252
self._mount_lvm_layout()
252253
case EncryptionType.Luks:
253254
luks_handlers = self._prepare_luks_partitions(self._disk_encryption.partitions)

0 commit comments

Comments
 (0)