Added creating and mounting of subvolume structure for BTRFS.
This commit is contained in:
parent
68b891837c
commit
76dc426a0f
|
|
@ -23,7 +23,9 @@ def mount_subvolume(installation, location :Union[pathlib.Path, str], force=Fals
|
||||||
raise DiskError(f"Cannot mount subvolume to {installation.target/location} because it contains data (non-empty folder target)")
|
raise DiskError(f"Cannot mount subvolume to {installation.target/location} because it contains data (non-empty folder target)")
|
||||||
|
|
||||||
# Mount the logical volume to the physical structure
|
# Mount the logical volume to the physical structure
|
||||||
return SysCommand(f"mount {get_mount_info(installation.target/location)['source']} {installation.target}/{str(location)} -o subvol=@/{str(location)}").exit_code == 0
|
mount_location = get_mount_info(installation.target/location)['source']
|
||||||
|
SysCommand(f"umount {mount_location}")
|
||||||
|
return SysCommand(f"mount {mount_location} {installation.target}/{str(location)} -o subvol=@/{str(location)}").exit_code == 0
|
||||||
|
|
||||||
def create_subvolume(installation, location :Union[pathlib.Path, str]) -> bool:
|
def create_subvolume(installation, location :Union[pathlib.Path, str]) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ class Filesystem:
|
||||||
def raw_parted(self, string: str):
|
def raw_parted(self, string: str):
|
||||||
if (cmd_handle := SysCommand(f'/usr/bin/parted -s {string}')).exit_code != 0:
|
if (cmd_handle := SysCommand(f'/usr/bin/parted -s {string}')).exit_code != 0:
|
||||||
log(f"Parted ended with a bad exit code: {cmd_handle}", level=logging.ERROR, fg="red")
|
log(f"Parted ended with a bad exit code: {cmd_handle}", level=logging.ERROR, fg="red")
|
||||||
|
time.sleep(0.5)
|
||||||
return cmd_handle
|
return cmd_handle
|
||||||
|
|
||||||
def parted(self, string: str):
|
def parted(self, string: str):
|
||||||
|
|
|
||||||
|
|
@ -41,18 +41,21 @@ def suggest_single_disk_layout(block_device, default_filesystem=None):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if default_filesystem == 'btrfs' and input('Would you like to use BTRFS subvolumes? (Y/n)').strip().lower() in ('', 'y', 'yes'):
|
if default_filesystem == 'btrfs' and input('Would you like to use BTRFS subvolumes? (Y/n): ').strip().lower() in ('', 'y', 'yes'):
|
||||||
# https://btrfs.wiki.kernel.org/index.php/FAQ
|
if input('Do you want to use a recommended structure? (Y/n): ').strip().lower() in ('', 'y', 'yes'):
|
||||||
# https://unix.stackexchange.com/questions/246976/btrfs-subvolume-uuid-clash
|
# https://btrfs.wiki.kernel.org/index.php/FAQ
|
||||||
# https://github.com/classy-giraffe/easy-arch/blob/main/easy-arch.sh
|
# https://unix.stackexchange.com/questions/246976/btrfs-subvolume-uuid-clash
|
||||||
layout[block_device.path]['partitions'][1]['btrfs'] = {
|
# https://github.com/classy-giraffe/easy-arch/blob/main/easy-arch.sh
|
||||||
"subvolumes" : {
|
layout[block_device.path]['partitions'][1]['btrfs'] = {
|
||||||
'@home' : '/home',
|
"subvolumes" : {
|
||||||
'@log' : '/var/log',
|
'@home' : '/home',
|
||||||
'@pkgs' : '/var/cache/pacman/pkg',
|
'@log' : '/var/log',
|
||||||
'@.snapshots' : '/.snapshots'
|
'@pkgs' : '/var/cache/pacman/pkg',
|
||||||
|
'@.snapshots' : '/.snapshots'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else:
|
||||||
|
pass #... implement a guided setup
|
||||||
|
|
||||||
elif block_device.size >= MIN_SIZE_TO_ALLOW_HOME_PART:
|
elif block_device.size >= MIN_SIZE_TO_ALLOW_HOME_PART:
|
||||||
# If we don't want to use subvolumes,
|
# If we don't want to use subvolumes,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from .mirrors import *
|
||||||
from .plugins import plugins
|
from .plugins import plugins
|
||||||
from .storage import storage
|
from .storage import storage
|
||||||
from .user_interaction import *
|
from .user_interaction import *
|
||||||
|
from .disk.btrfs import create_subvolume, mount_subvolume
|
||||||
|
|
||||||
# Any package that the Installer() is responsible for (optional and the default ones)
|
# Any package that the Installer() is responsible for (optional and the default ones)
|
||||||
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
|
__packages__ = ["base", "base-devel", "linux-firmware", "linux", "linux-lts", "linux-zen", "linux-hardened"]
|
||||||
|
|
@ -139,9 +140,15 @@ class Installer:
|
||||||
password = mountpoints[mountpoint]['password']
|
password = mountpoints[mountpoint]['password']
|
||||||
with luks2(mountpoints[mountpoint]['device_instance'], loopdev, password, auto_unmount=False) as unlocked_device:
|
with luks2(mountpoints[mountpoint]['device_instance'], loopdev, password, auto_unmount=False) as unlocked_device:
|
||||||
unlocked_device.mount(f"{self.target}{mountpoint}")
|
unlocked_device.mount(f"{self.target}{mountpoint}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
mountpoints[mountpoint]['device_instance'].mount(f"{self.target}{mountpoint}")
|
mountpoints[mountpoint]['device_instance'].mount(f"{self.target}{mountpoint}")
|
||||||
|
|
||||||
|
if (subvolumes := mountpoints[mountpoint].get('btrfs', {}).get('subvolumes', {})):
|
||||||
|
for name, location in subvolumes.items():
|
||||||
|
create_subvolume(self, location)
|
||||||
|
mount_subvolume(self, location)
|
||||||
|
|
||||||
def mount(self, partition, mountpoint, create_mountpoint=True):
|
def mount(self, partition, mountpoint, create_mountpoint=True):
|
||||||
if create_mountpoint and not os.path.isdir(f'{self.target}{mountpoint}'):
|
if create_mountpoint and not os.path.isdir(f'{self.target}{mountpoint}'):
|
||||||
os.makedirs(f'{self.target}{mountpoint}')
|
os.makedirs(f'{self.target}{mountpoint}')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue