Implement comments
- Unencrypted /boot check moved to generate_crypttab_line_info. - has_luks in class FstabGenerator changed to luks_mapper_name.
This commit is contained in:
parent
dcbb83ebe5
commit
5d1b024237
@ -142,21 +142,13 @@ class FstabGenerator(object):
|
|||||||
with open(crypttab_path, "w") as crypttab_file:
|
with open(crypttab_path, "w") as crypttab_file:
|
||||||
print(CRYPTTAB_HEADER, file=crypttab_file)
|
print(CRYPTTAB_HEADER, file=crypttab_file)
|
||||||
|
|
||||||
# Check if /boot is unencrypted
|
|
||||||
unencrypted_separate_boot = False
|
|
||||||
for partition in self.partitions:
|
for partition in self.partitions:
|
||||||
if (partition["mountPoint"] == "/boot"
|
dct = self.generate_crypttab_line_info(partition)
|
||||||
and "luksMapperName" not in partition):
|
|
||||||
unencrypted_separate_boot = True
|
|
||||||
break
|
|
||||||
|
|
||||||
for partition in self.partitions:
|
|
||||||
dct = self.generate_crypttab_line_info(partition, unencrypted_separate_boot)
|
|
||||||
|
|
||||||
if dct:
|
if dct:
|
||||||
self.print_crypttab_line(dct, file=crypttab_file)
|
self.print_crypttab_line(dct, file=crypttab_file)
|
||||||
|
|
||||||
def generate_crypttab_line_info(self, partition, unencrypted_separate_boot):
|
def generate_crypttab_line_info(self, partition):
|
||||||
""" Generates information for each crypttab entry. """
|
""" Generates information for each crypttab entry. """
|
||||||
if "luksMapperName" not in partition or "luksUuid" not in partition:
|
if "luksMapperName" not in partition or "luksUuid" not in partition:
|
||||||
return None
|
return None
|
||||||
@ -166,13 +158,17 @@ class FstabGenerator(object):
|
|||||||
if not mapper_name or not luks_uuid:
|
if not mapper_name or not luks_uuid:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Set crypttab password for partition to none and remove crypttab options
|
|
||||||
# on root partition when /boot is unencrypted
|
|
||||||
password = "/crypto_keyfile.bin"
|
password = "/crypto_keyfile.bin"
|
||||||
crypttab_options = self.crypttab_options
|
crypttab_options = self.crypttab_options
|
||||||
if partition["mountPoint"] == "/" and unencrypted_separate_boot:
|
|
||||||
password = 'none'
|
# Set crypttab password for partition to none and remove crypttab options
|
||||||
crypttab_options = ''
|
# on root partition when /boot is unencrypted
|
||||||
|
if partition["mountPoint"] == "/":
|
||||||
|
if any([p["mountPoint"] == "/boot"
|
||||||
|
and "luksMapperName" not in p
|
||||||
|
for p in self.partitions]):
|
||||||
|
password = "none"
|
||||||
|
crypttab_options = ""
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
name=mapper_name,
|
name=mapper_name,
|
||||||
@ -236,7 +232,7 @@ class FstabGenerator(object):
|
|||||||
# Some "fs" names need special handling in /etc/fstab, so remap them.
|
# Some "fs" names need special handling in /etc/fstab, so remap them.
|
||||||
filesystem = partition["fs"].lower()
|
filesystem = partition["fs"].lower()
|
||||||
filesystem = FS_MAP.get(filesystem, filesystem)
|
filesystem = FS_MAP.get(filesystem, filesystem)
|
||||||
has_luks = "luksMapperName" in partition
|
luks_mapper_name = partition.get("luksMapperName", None)
|
||||||
mount_point = partition["mountPoint"]
|
mount_point = partition["mountPoint"]
|
||||||
disk_name = disk_name_for_partition(partition)
|
disk_name = disk_name_for_partition(partition)
|
||||||
is_ssd = disk_name in self.ssd_disks
|
is_ssd = disk_name in self.ssd_disks
|
||||||
@ -279,17 +275,19 @@ class FstabGenerator(object):
|
|||||||
if filesystem == "btrfs" and partition.get("subvol",None):
|
if filesystem == "btrfs" and partition.get("subvol",None):
|
||||||
options = "subvol={},".format(partition["subvol"]) + options
|
options = "subvol={},".format(partition["subvol"]) + options
|
||||||
|
|
||||||
if has_luks:
|
device = None
|
||||||
# Check if user mounted a previously encrypted partition
|
if luks_mapper_name:
|
||||||
if not partition["luksMapperName"]:
|
device = "/dev/mapper/" + luks_mapper_name
|
||||||
return None
|
|
||||||
|
|
||||||
device = "/dev/mapper/" + partition["luksMapperName"]
|
|
||||||
elif partition["uuid"]:
|
elif partition["uuid"]:
|
||||||
device = "UUID=" + partition["uuid"]
|
device = "UUID=" + partition["uuid"]
|
||||||
else:
|
else:
|
||||||
device = partition["device"]
|
device = partition["device"]
|
||||||
|
|
||||||
|
if not device:
|
||||||
|
# TODO: we get here when the user mounted a previously mounted partition
|
||||||
|
# This should be catched early in the process
|
||||||
|
return None
|
||||||
|
|
||||||
return dict(device=device,
|
return dict(device=device,
|
||||||
mount_point=mount_point,
|
mount_point=mount_point,
|
||||||
fs=filesystem,
|
fs=filesystem,
|
||||||
|
Loading…
Reference in New Issue
Block a user