Skip to content
Merged
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
18 changes: 9 additions & 9 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def load_devices(self) -> None:
fs_type = self._determine_fs_type(partition, lsblk_info)
subvol_infos = []

if fs_type == FilesystemType.Btrfs:
if fs_type == FilesystemType.BTRFS:
subvol_infos = self.get_btrfs_info(partition.path, lsblk_info)

partition_infos.append(
Expand Down Expand Up @@ -147,8 +147,8 @@ def _determine_fs_type(
) -> FilesystemType | None:
try:
if partition.fileSystem:
if partition.fileSystem.type == FilesystemType.LinuxSwap.parted_value:
return FilesystemType.LinuxSwap
if partition.fileSystem.type == FilesystemType.LINUX_SWAP.parted_value:
return FilesystemType.LINUX_SWAP
return FilesystemType(partition.fileSystem.type)
elif lsblk_info is not None:
return FilesystemType(lsblk_info.fstype) if lsblk_info.fstype else None
Expand Down Expand Up @@ -241,20 +241,20 @@ def format(
options = []

match fs_type:
case FilesystemType.Btrfs | FilesystemType.Xfs:
case FilesystemType.BTRFS | FilesystemType.XFS:
# Force overwrite
options.append('-f')
case FilesystemType.F2fs:
case FilesystemType.F2FS:
options.append('-f')
options.extend(('-O', 'extra_attr'))
case FilesystemType.Ext2 | FilesystemType.Ext3 | FilesystemType.Ext4:
case FilesystemType.EXT2 | FilesystemType.EXT3 | FilesystemType.EXT4:
# Force create
options.append('-F')
case FilesystemType.Fat12 | FilesystemType.Fat16 | FilesystemType.Fat32:
case FilesystemType.FAT12 | FilesystemType.FAT16 | FilesystemType.FAT32:
mkfs_type = 'fat'
# Set FAT size
options.extend(('-F', fs_type.value.removeprefix(mkfs_type)))
case FilesystemType.LinuxSwap:
case FilesystemType.LINUX_SWAP:
command = 'mkswap'
case _:
raise UnknownFilesystemFormat(f'Filetype "{fs_type.value}" is not supported')
Expand Down Expand Up @@ -505,7 +505,7 @@ def umount_all_existing(self, device_path: Path) -> None:
debug(f'Unmounting: {partition.path}')

# un-mount for existing encrypted partitions
if partition.fs_type == FilesystemType.Crypto_luks:
if partition.fs_type == FilesystemType.CRYPTO_LUKS:
Luks2(partition.path).lock()
else:
umount(partition.path, recursive=True)
Expand Down
16 changes: 8 additions & 8 deletions archinstall/lib/disk/disk_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,17 +508,17 @@ def _boot_partition(sector_size: SectorSize, using_gpt: bool) -> PartitionModifi
start=start,
length=size,
mountpoint=Path('/boot'),
fs_type=FilesystemType.Fat32,
fs_type=FilesystemType.FAT32,
flags=flags,
)


async def select_main_filesystem_format() -> FilesystemType:
items = [
MenuItem('btrfs', value=FilesystemType.Btrfs),
MenuItem('ext4', value=FilesystemType.Ext4),
MenuItem('xfs', value=FilesystemType.Xfs),
MenuItem('f2fs', value=FilesystemType.F2fs),
MenuItem(FilesystemType.BTRFS.value, value=FilesystemType.BTRFS),
Copy link
Copy Markdown
Collaborator

@svartkanin svartkanin Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI there's a helper function


it was introduced after this was implemented so one day we can move it :)

MenuItem(FilesystemType.EXT4.value, value=FilesystemType.EXT4),
MenuItem(FilesystemType.XFS.value, value=FilesystemType.XFS),
MenuItem(FilesystemType.F2FS.value, value=FilesystemType.F2FS),
]

group = MenuItemGroup(items, sort_items=False)
Expand Down Expand Up @@ -601,7 +601,7 @@ async def suggest_single_disk_layout(
available_space = total_size
min_size_to_allow_home_part = Size(64, Unit.GiB, sector_size)

if filesystem_type == FilesystemType.Btrfs:
if filesystem_type == FilesystemType.BTRFS:
prompt = tr('Would you like to use BTRFS subvolumes with a default structure?') + '\n'

result = await Confirmation(
Expand Down Expand Up @@ -734,7 +734,7 @@ async def suggest_multi_disk_layout(
_ = await Notify(text).show()
return []

if filesystem_type == FilesystemType.Btrfs:
if filesystem_type == FilesystemType.BTRFS:
mount_options = await select_mount_options()

device_paths = ', '.join(str(d.device_info.path) for d in devices)
Expand Down Expand Up @@ -817,7 +817,7 @@ async def suggest_lvm_layout(
if not filesystem_type:
filesystem_type = await select_main_filesystem_format()

if filesystem_type == FilesystemType.Btrfs:
if filesystem_type == FilesystemType.BTRFS:
prompt = tr('Would you like to use BTRFS subvolumes with a default structure?') + '\n'
result = await Confirmation(header=prompt, allow_skip=False, preset=True).show()

Expand Down
8 changes: 4 additions & 4 deletions archinstall/lib/disk/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def perform_filesystem_operations(self) -> None:
self._format_partitions(mod.partitions)

for part_mod in mod.partitions:
if part_mod.fs_type == FilesystemType.Btrfs and part_mod.is_create_or_modify():
if part_mod.fs_type == FilesystemType.BTRFS and part_mod.is_create_or_modify():
device_handler.create_btrfs_volumes(part_mod, enc_conf=self._enc_config)

def _format_partitions(
Expand Down Expand Up @@ -113,7 +113,7 @@ def _validate_partitions(self, partitions: list[PartitionModification]) -> None:
# verify that all partitions have a path set (which implies that they have been created)
lambda x: x.dev_path is None: ValueError('When formatting, all partitions must have a path set'),
# crypto luks is not a valid file system type
lambda x: x.fs_type is FilesystemType.Crypto_luks: ValueError('Crypto luks cannot be set as a filesystem type'),
lambda x: x.fs_type is FilesystemType.CRYPTO_LUKS: ValueError('Crypto luks cannot be set as a filesystem type'),
# file system type must be set
lambda x: x.fs_type is None: ValueError('File system type must be set for modification'),
}
Expand Down Expand Up @@ -230,7 +230,7 @@ def _format_lvm_vols(
# find the mapper device yet
device_handler.format(vol.fs_type, path)

if vol.fs_type == FilesystemType.Btrfs:
if vol.fs_type == FilesystemType.BTRFS:
device_handler.create_lvm_btrfs_subvolumes(path, vol.btrfs_subvols, vol.mount_options)

def _lvm_create_pvs(
Expand Down Expand Up @@ -318,7 +318,7 @@ def _lvm_vol_handle_e2scrub(self, vol_gp: LvmVolumeGroup) -> None:
# from arch wiki:
# If a logical volume will be formatted with ext4, leave at least 256 MiB
# free space in the volume group to allow using e2scrub
if any([vol.fs_type == FilesystemType.Ext4 for vol in vol_gp.volumes]):
if any([vol.fs_type == FilesystemType.EXT4 for vol in vol_gp.volumes]):
largest_vol = max(vol_gp.volumes, key=lambda x: x.length)

lvm_vol_reduce(
Expand Down
12 changes: 6 additions & 6 deletions archinstall/lib/disk/partitioning_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def filter_options(self, selection: DiskSegment, options: list[str]) -> list[str
]

# non btrfs partitions shouldn't get btrfs options
if selection.segment.fs_type != FilesystemType.Btrfs:
if selection.segment.fs_type != FilesystemType.BTRFS:
not_filter += [
self._actions['btrfs_mark_compressed'],
self._actions['btrfs_mark_nodatacow'],
Expand Down Expand Up @@ -332,7 +332,7 @@ async def handle_action(
partition.flags = []
partition.set_flag(PartitionFlag.SWAP)
# btrfs subvolumes will define mountpoints
if fs_type == FilesystemType.Btrfs:
if fs_type == FilesystemType.BTRFS:
partition.mountpoint = None
case 'btrfs_mark_compressed':
self._toggle_mount_option(partition, BtrfsMountOption.compress)
Expand Down Expand Up @@ -399,12 +399,12 @@ async def _prompt_formatting(self, partition: PartitionModification) -> None:
# If we mark a partition for formatting, but the format is CRYPTO LUKS, there's no point in formatting it really
# without asking the user which inner-filesystem they want to use. Since the flag 'encrypted' = True is already set,
# it's safe to change the filesystem for this partition.
if partition.fs_type == FilesystemType.Crypto_luks:
if partition.fs_type == FilesystemType.CRYPTO_LUKS:
prompt = tr('This partition is currently encrypted, to format it a filesystem has to be specified') + '\n'
fs_type = await self._prompt_partition_fs_type(prompt)
partition.fs_type = fs_type

if fs_type == FilesystemType.Btrfs:
if fs_type == FilesystemType.BTRFS:
partition.mountpoint = None

async def _prompt_mountpoint(self) -> Path:
Expand All @@ -417,7 +417,7 @@ async def _prompt_mountpoint(self) -> Path:
return mountpoint

async def _prompt_partition_fs_type(self, prompt: str | None = None) -> FilesystemType:
fs_types = filter(lambda fs: fs != FilesystemType.Crypto_luks, FilesystemType)
fs_types = filter(lambda fs: fs != FilesystemType.CRYPTO_LUKS, FilesystemType)
items = [MenuItem(fs.value, value=fs) for fs in fs_types]
group = MenuItemGroup(items, sort_items=False)

Expand Down Expand Up @@ -522,7 +522,7 @@ async def _create_new_partition(self, free_space: FreeSpace) -> PartitionModific
fs_type = await self._prompt_partition_fs_type()

mountpoint = None
if fs_type not in (FilesystemType.Btrfs, FilesystemType.LinuxSwap):
if fs_type not in (FilesystemType.BTRFS, FilesystemType.LINUX_SWAP):
mountpoint = await self._prompt_mountpoint()

partition = PartitionModification(
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/global_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,11 @@ def _validate_bootloader(self) -> str | None:
if efi_partition is None:
return 'EFI system partition (ESP) not found'

if efi_partition.fs_type not in [FilesystemType.Fat12, FilesystemType.Fat16, FilesystemType.Fat32]:
if efi_partition.fs_type not in [FilesystemType.FAT12, FilesystemType.FAT16, FilesystemType.FAT32]:
return 'ESP must be formatted as a FAT filesystem'

if bootloader == Bootloader.Limine:
if boot_partition.fs_type not in [FilesystemType.Fat12, FilesystemType.Fat16, FilesystemType.Fat32]:
if boot_partition.fs_type not in [FilesystemType.FAT12, FilesystemType.FAT16, FilesystemType.FAT32]:
return 'Limine does not support booting with a non-FAT boot partition'

elif bootloader == Bootloader.Refind:
Expand Down
14 changes: 7 additions & 7 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _mount_partition(self, part_mod: PartitionModification) -> None:
if part_mod.mountpoint:
target = self.target / part_mod.relative_mountpoint
mount(part_mod.dev_path, target, options=part_mod.mount_options)
elif part_mod.fs_type == FilesystemType.Btrfs:
elif part_mod.fs_type == FilesystemType.BTRFS:
# Only mount BTRFS subvolumes that have mountpoints specified
subvols_with_mountpoints = [sv for sv in part_mod.btrfs_subvols if sv.mountpoint is not None]
if subvols_with_mountpoints:
Expand All @@ -381,12 +381,12 @@ def _mount_partition(self, part_mod: PartitionModification) -> None:
swapon(part_mod.dev_path)

def _mount_lvm_vol(self, volume: LvmVolume) -> None:
if volume.fs_type != FilesystemType.Btrfs:
if volume.fs_type != FilesystemType.BTRFS:
if volume.mountpoint and volume.dev_path:
target = self.target / volume.relative_mountpoint
mount(volume.dev_path, target, options=volume.mount_options)

if volume.fs_type == FilesystemType.Btrfs and volume.dev_path:
if volume.fs_type == FilesystemType.BTRFS and volume.dev_path:
# Only mount BTRFS subvolumes that have mountpoints specified
subvols_with_mountpoints = [sv for sv in volume.btrfs_subvols if sv.mountpoint is not None]
if subvols_with_mountpoints:
Expand All @@ -396,7 +396,7 @@ def _mount_luks_partition(self, part_mod: PartitionModification, luks_handler: L
if not luks_handler.mapper_dev:
return None

if part_mod.fs_type == FilesystemType.Btrfs and part_mod.btrfs_subvols:
if part_mod.fs_type == FilesystemType.BTRFS and part_mod.btrfs_subvols:
# Only mount BTRFS subvolumes that have mountpoints specified
subvols_with_mountpoints = [sv for sv in part_mod.btrfs_subvols if sv.mountpoint is not None]
if subvols_with_mountpoints:
Expand All @@ -406,12 +406,12 @@ def _mount_luks_partition(self, part_mod: PartitionModification, luks_handler: L
mount(luks_handler.mapper_dev, target, options=part_mod.mount_options)

def _mount_luks_volume(self, volume: LvmVolume, luks_handler: Luks2) -> None:
if volume.fs_type != FilesystemType.Btrfs:
if volume.fs_type != FilesystemType.BTRFS:
if volume.mountpoint and luks_handler.mapper_dev:
target = self.target / volume.relative_mountpoint
mount(luks_handler.mapper_dev, target, options=volume.mount_options)

if volume.fs_type == FilesystemType.Btrfs and luks_handler.mapper_dev:
if volume.fs_type == FilesystemType.BTRFS and luks_handler.mapper_dev:
# Only mount BTRFS subvolumes that have mountpoints specified
subvols_with_mountpoints = [sv for sv in volume.btrfs_subvols if sv.mountpoint is not None]
if subvols_with_mountpoints:
Expand Down Expand Up @@ -866,7 +866,7 @@ def _prepare_fs_type(
self._base_packages.append(pkg)

# https://github.com/archlinux/archinstall/issues/1837
if fs_type == FilesystemType.Btrfs:
if fs_type == FilesystemType.BTRFS:
self._disable_fstrim = True

def _prepare_encrypt(self, before: str = 'filesystems') -> None:
Expand Down
49 changes: 27 additions & 22 deletions archinstall/lib/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import math
import uuid
from dataclasses import dataclass, field
from enum import Enum
from enum import Enum, StrEnum, auto
from pathlib import Path
from typing import NotRequired, Self, TypedDict, override
from uuid import UUID
Expand Down Expand Up @@ -131,9 +131,14 @@ def parse_arg(
for partition in entry.get('partitions', []):
flags = [flag for f in partition.get('flags', []) if (flag := PartitionFlag.from_string(f))]

if fs_type := partition.get('fs_type'):
fs_type = FilesystemType(fs_type)
else:
fs_type = None

device_partition = PartitionModification(
status=ModificationStatus(partition['status']),
fs_type=FilesystemType(partition['fs_type']) if partition.get('fs_type') else None,
fs_type=fs_type,
Comment on lines +134 to +141
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change mypy produces this error:

archinstall/lib/models/device.py:136: error: Argument 1 to "FilesystemType" has incompatible type "str | None"; expected "str"  [arg-type]

start=Size.parse_args(partition['start']),
length=Size.parse_args(partition['size']),
mount_options=partition['mount_options'],
Expand Down Expand Up @@ -200,7 +205,7 @@ def parse_arg(
def has_default_btrfs_vols(self) -> bool:
for mod in self.device_modifications:
for part in mod.partitions:
if not (part.is_create_or_modify() and part.fs_type == FilesystemType.Btrfs):
if not (part.is_create_or_modify() and part.fs_type == FilesystemType.BTRFS):
continue

if any(subvol.is_default_root() for subvol in part.btrfs_subvols):
Expand Down Expand Up @@ -777,38 +782,38 @@ def bytes(self) -> builtins.bytes:
return uuid.UUID(self.value).bytes


class FilesystemType(Enum):
Btrfs = 'btrfs'
Ext2 = 'ext2'
Ext3 = 'ext3'
Ext4 = 'ext4'
F2fs = 'f2fs'
Fat12 = 'fat12'
Fat16 = 'fat16'
Fat32 = 'fat32'
Ntfs = 'ntfs'
Xfs = 'xfs'
LinuxSwap = 'linux-swap'
class FilesystemType(StrEnum):
BTRFS = auto()
EXT2 = auto()
EXT3 = auto()
EXT4 = auto()
F2FS = auto()
FAT12 = auto()
FAT16 = auto()
FAT32 = auto()
NTFS = auto()
XFS = auto()
LINUX_SWAP = 'linux-swap'

# this is not a FS known to parted, so be careful
# with the usage from this enum
Crypto_luks = 'crypto_LUKS'
CRYPTO_LUKS = 'crypto_LUKS'

def is_crypto(self) -> bool:
return self == FilesystemType.Crypto_luks
return self == FilesystemType.CRYPTO_LUKS

@property
def parted_value(self) -> str:
return self.value + '(v1)' if self == FilesystemType.LinuxSwap else self.value
return self.value + '(v1)' if self == FilesystemType.LINUX_SWAP else self.value

@property
def installation_pkg(self) -> str | None:
match self:
case FilesystemType.Btrfs:
case FilesystemType.BTRFS:
return 'btrfs-progs'
case FilesystemType.Xfs:
case FilesystemType.XFS:
return 'xfsprogs'
case FilesystemType.F2fs:
case FilesystemType.F2FS:
return 'f2fs-tools'
case _:
return None
Expand Down Expand Up @@ -953,7 +958,7 @@ def is_home(self) -> bool:
return False

def is_swap(self) -> bool:
return self.fs_type == FilesystemType.LinuxSwap
return self.fs_type == FilesystemType.LINUX_SWAP

def is_modify(self) -> bool:
return self.status == ModificationStatus.Modify
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ After running ``python -m archinstall test_installer`` it should print something
partition=<parted.partition.Partition object at 0x7fbe166c4a90>,
name='primary',
type=<PartitionType.Primary: 'primary'>,
fs_type=<FilesystemType.Fat32: 'fat32'>,
fs_type=<FilesystemType.FAT32: 'fat32'>,
path='/dev/nvme0n1p1',
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
length=Size(value=535822336, unit=<Unit.B: 1>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
Expand Down
2 changes: 1 addition & 1 deletion examples/full_automated_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
start=Size(1, Unit.MiB, device.device_info.sector_size),
length=Size(512, Unit.MiB, device.device_info.sector_size),
mountpoint=Path('/boot'),
fs_type=FilesystemType.Fat32,
fs_type=FilesystemType.FAT32,
flags=[PartitionFlag.BOOT],
)
device_modification.add_partition(boot_partition)
Expand Down
Loading