[mount] zfs changes from review feedback
This commit is contained in:
parent
3a90382699
commit
4778d9b2dd
@ -26,6 +26,17 @@ _ = gettext.translation("calamares-python",
|
|||||||
fallback=True).gettext
|
fallback=True).gettext
|
||||||
|
|
||||||
|
|
||||||
|
class ZfsException(Exception):
|
||||||
|
"""Exception raised when there is a problem with zfs
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
message -- explanation of the error
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, message):
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
def pretty_name():
|
def pretty_name():
|
||||||
return _("Mounting partitions.")
|
return _("Mounting partitions.")
|
||||||
|
|
||||||
@ -61,7 +72,7 @@ def get_btrfs_subvolumes(partitions):
|
|||||||
return btrfs_subvolumes
|
return btrfs_subvolumes
|
||||||
|
|
||||||
|
|
||||||
def parse_global_storage(gs_value):
|
def bool_to_zfs_command(gs_value):
|
||||||
""" Something in the chain is converting on and off to true and false. This converts it back.
|
""" Something in the chain is converting on and off to true and false. This converts it back.
|
||||||
|
|
||||||
:param gs_value: The value from global storage which needs to be fixed
|
:param gs_value: The value from global storage which needs to be fixed
|
||||||
@ -86,7 +97,7 @@ def mount_zfs(root_mount_point, partition):
|
|||||||
zfs_pool_list = libcalamares.globalstorage.value("zfsPoolInfo")
|
zfs_pool_list = libcalamares.globalstorage.value("zfsPoolInfo")
|
||||||
if not zfs_pool_list:
|
if not zfs_pool_list:
|
||||||
libcalamares.utils.warning("Failed to locate zfsPoolInfo data in global storage")
|
libcalamares.utils.warning("Failed to locate zfsPoolInfo data in global storage")
|
||||||
raise Exception("Internal error mounting zfs datasets")
|
raise ZfsException(_("Internal error mounting zfs datasets"))
|
||||||
|
|
||||||
# Find the zpool matching this partition
|
# Find the zpool matching this partition
|
||||||
for zfs_pool in zfs_pool_list:
|
for zfs_pool in zfs_pool_list:
|
||||||
@ -95,9 +106,10 @@ def mount_zfs(root_mount_point, partition):
|
|||||||
ds_name = zfs_pool["dsName"]
|
ds_name = zfs_pool["dsName"]
|
||||||
|
|
||||||
# import the zpool
|
# import the zpool
|
||||||
import_result = subprocess.run(['zpool', 'import', '-R', root_mount_point, pool_name])
|
try:
|
||||||
if import_result.returncode != 0:
|
libcalamares.utils.host_env_process_output(["zpool", "import", "-R", root_mount_point, pool_name], None)
|
||||||
raise Exception("Failed to import zpool")
|
except subprocess.CalledProcessError:
|
||||||
|
raise ZfsException(_("Failed to import zpool"))
|
||||||
|
|
||||||
# Get the encrpytion information from global storage
|
# Get the encrpytion information from global storage
|
||||||
zfs_info_list = libcalamares.globalstorage.value("zfsInfo")
|
zfs_info_list = libcalamares.globalstorage.value("zfsInfo")
|
||||||
@ -110,9 +122,11 @@ def mount_zfs(root_mount_point, partition):
|
|||||||
|
|
||||||
if encrypt is True:
|
if encrypt is True:
|
||||||
# The zpool is encrypted, we need to unlock it
|
# The zpool is encrypted, we need to unlock it
|
||||||
loadkey_result = subprocess.run(['sh', '-c', 'echo "' + passphrase + '" | zfs load-key ' + pool_name])
|
try:
|
||||||
if loadkey_result.returncode != 0:
|
libcalamares.utils.host_env_process_output(["sh", "-c",
|
||||||
raise Exception("Failed to unlock zpool")
|
"echo \"" + passphrase + "\" | zfs load-key " + pool_name], None)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
raise ZfsException(_("Failed to unlock zpool"))
|
||||||
|
|
||||||
if partition["mountPoint"] == '/':
|
if partition["mountPoint"] == '/':
|
||||||
# Get the zfs dataset list from global storage
|
# Get the zfs dataset list from global storage
|
||||||
@ -120,36 +134,39 @@ def mount_zfs(root_mount_point, partition):
|
|||||||
|
|
||||||
if not zfs:
|
if not zfs:
|
||||||
libcalamares.utils.warning("Failed to locate zfs dataset list")
|
libcalamares.utils.warning("Failed to locate zfs dataset list")
|
||||||
raise Exception("Internal error mounting zfs datasets")
|
raise ZfsException(_("Internal error mounting zfs datasets"))
|
||||||
|
|
||||||
# first we handle the / dataset if there is one
|
# first we handle the / dataset if there is one
|
||||||
for dataset in zfs:
|
for dataset in zfs:
|
||||||
if dataset['mountpoint'] == '/':
|
if dataset['mountpoint'] == '/':
|
||||||
# Properly set the canmount field from global storage
|
# Properly set the canmount field from global storage
|
||||||
can_mount = parse_global_storage(dataset['canMount'])
|
can_mount = bool_to_zfs_command(dataset['canMount'])
|
||||||
set_result = subprocess.run(['zfs', 'set', 'canmount=' + can_mount,
|
try:
|
||||||
dataset['zpool'] + '/' + dataset['dsName']])
|
libcalamares.utils.host_env_process_output(["zfs", "set", "canmount=" + can_mount,
|
||||||
if set_result.returncode != 0:
|
dataset["zpool"] + "/" + dataset["dsName"]], None)
|
||||||
raise Exception("Failed to set zfs mountpoint")
|
except subprocess.CalledProcessError:
|
||||||
if dataset['canMount'] == 'noauto':
|
raise ZfsException(_("Failed to set zfs mountpoint"))
|
||||||
mount_result = subprocess.run(['zfs', 'mount', dataset['zpool'] + '/' + dataset['dsName']])
|
if dataset["canMount"] == "noauto":
|
||||||
|
mount_result = subprocess.run(["zfs", "mount", dataset["zpool"] + '/' + dataset["dsName"]])
|
||||||
if mount_result.returncode != 0:
|
if mount_result.returncode != 0:
|
||||||
raise Exception("Failed to mount root dataset")
|
raise ZfsException(_("Failed to mount root dataset"))
|
||||||
|
|
||||||
# Set the canmount property for each dataset. This will effectively mount the dataset
|
# Set the canmount property for each dataset. This will effectively mount the dataset
|
||||||
for dataset in zfs:
|
for dataset in zfs:
|
||||||
# We already handled the / mountpoint above
|
# We already handled the / mountpoint above
|
||||||
if dataset['mountpoint'] != '/':
|
if dataset["mountpoint"] != '/':
|
||||||
can_mount = parse_global_storage(dataset['canMount'])
|
can_mount = bool_to_zfs_command(dataset["canMount"])
|
||||||
|
|
||||||
set_result = subprocess.run(['zfs', 'set', 'canmount=' + can_mount,
|
try:
|
||||||
dataset['zpool'] + '/' + dataset['dsName']])
|
libcalamares.utils.host_env_process_output(["zfs", "set", "canmount=" + can_mount,
|
||||||
if set_result.returncode != 0:
|
dataset["zpool"] + "/" + dataset["dsName"]], None)
|
||||||
raise Exception("Failed to set zfs mountpoint")
|
except subprocess.CalledProcessError:
|
||||||
|
raise ZfsException(_("Failed to set zfs mountpoint"))
|
||||||
else:
|
else:
|
||||||
set_result = subprocess.run(['zfs', 'set', 'canmount=on', pool_name + '/' + ds_name])
|
try:
|
||||||
if set_result.returncode != 0:
|
libcalamares.utils.host_env_process_output(["zfs", "set", "canmount=on", pool_name + "/" + ds_name], None)
|
||||||
raise Exception("Failed to set zfs mountpoint")
|
except subprocess.CalledProcessError:
|
||||||
|
raise ZfsException(_("Failed to set zfs mountpoint"))
|
||||||
|
|
||||||
|
|
||||||
def mount_partition(root_mount_point, partition, partitions):
|
def mount_partition(root_mount_point, partition, partitions):
|
||||||
@ -255,8 +272,11 @@ def run():
|
|||||||
# under /tmp, we make sure /tmp is mounted before the partition)
|
# under /tmp, we make sure /tmp is mounted before the partition)
|
||||||
mountable_partitions = [ p for p in partitions + extra_mounts if "mountPoint" in p and p["mountPoint"] ]
|
mountable_partitions = [ p for p in partitions + extra_mounts if "mountPoint" in p and p["mountPoint"] ]
|
||||||
mountable_partitions.sort(key=lambda x: x["mountPoint"])
|
mountable_partitions.sort(key=lambda x: x["mountPoint"])
|
||||||
|
try:
|
||||||
for partition in mountable_partitions:
|
for partition in mountable_partitions:
|
||||||
mount_partition(root_mount_point, partition, partitions)
|
mount_partition(root_mount_point, partition, partitions)
|
||||||
|
except ZfsException as ze:
|
||||||
|
return _("zfs mounting error"), ze.message
|
||||||
|
|
||||||
libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
|
libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user