Skip to content
Snippets Groups Projects
Commit e6806048 authored by Teo Mrnjavac's avatar Teo Mrnjavac
Browse files

Add support for generating crypttab.

This relies on the luksbootkeyfile module, which should create a keyfile
at / and add it to all interested partitions.
parent 73e4cee8
Branches
Tags
No related merge requests found
...@@ -25,7 +25,7 @@ import re ...@@ -25,7 +25,7 @@ import re
import libcalamares import libcalamares
HEADER = """# /etc/fstab: static file system information. FSTAB_HEADER = """# /etc/fstab: static file system information.
# #
# Use 'blkid' to print the universally unique identifier for a device; this may # Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if # be used with UUID= as a more robust way to name devices that works even if
...@@ -33,6 +33,20 @@ HEADER = """# /etc/fstab: static file system information. ...@@ -33,6 +33,20 @@ HEADER = """# /etc/fstab: static file system information.
# #
# <file system> <mount point> <type> <options> <dump> <pass>""" # <file system> <mount point> <type> <options> <dump> <pass>"""
CRYPTTAB_HEADER = """# /etc/crypttab: mappings for encrypted partitions.
#
# Each mapped device will be created in /dev/mapper, so your /etc/fstab
# should use the /dev/mapper/<name> paths for encrypted devices.
#
# See crypttab(5) for the supported syntax.
#
# NOTE: Do not list your root (/) partition here, it must be set up
# beforehand by the initramfs (/etc/mkinitcpio.conf). The same applies
# to encrypted swap, which should be set up with mkinitcpio-openswap
# for resume support.
#
# <name> <device> <password> <options>"""
# Turn Parted filesystem names into fstab names # Turn Parted filesystem names into fstab names
FS_MAP = { FS_MAP = {
"fat16": "vfat", "fat16": "vfat",
...@@ -103,6 +117,7 @@ class FstabGenerator(object): ...@@ -103,6 +117,7 @@ class FstabGenerator(object):
""" """
self.find_ssd_disks() self.find_ssd_disks()
self.generate_fstab() self.generate_fstab()
self.generate_crypttab()
self.create_mount_points() self.create_mount_points()
return None return None
...@@ -112,13 +127,53 @@ class FstabGenerator(object): ...@@ -112,13 +127,53 @@ class FstabGenerator(object):
disks = {disk_name_for_partition(x) for x in self.partitions} disks = {disk_name_for_partition(x) for x in self.partitions}
self.ssd_disks = {x for x in disks if is_ssd_disk(x)} self.ssd_disks = {x for x in disks if is_ssd_disk(x)}
def generate_crypttab(self):
""" Create crypttab. """
mkdir_p(os.path.join(self.root_mount_point, "etc"))
crypttab_path = os.path.join(self.root_mount_point, "etc", "crypttab")
with open(crypttab_path, "w") as fl:
print(CRYPTTAB_HEADER, file=fl)
for partition in self.partitions:
dct = self.generate_crypttab_line_info(partition)
if dct:
self.print_crypttab_line(dct, file=fl)
def generate_crypttab_line_info(self, partition):
""" Generates information for each crypttab entry. """
mapper_name = partition["luksMapperName"]
mount_point = partition["mountPoint"]
luks_uuid = partition["luksUuid"]
if not mapper_name or not luks_uuid:
return None
if mount_point == "/":
return None
return dict(
name=mapper_name,
device="UUID=" + luks_uuid,
password="/crypto_keyfile.bin",
)
def print_crypttab_line(self, dct, file=None):
""" Prints line to '/etc/crypttab' file. """
line = "{:21} {:<45} {}".format(dct["name"],
dct["device"],
dct["password"],
)
print(line, file=file)
def generate_fstab(self): def generate_fstab(self):
""" Create fstab. """ """ Create fstab. """
mkdir_p(os.path.join(self.root_mount_point, "etc")) mkdir_p(os.path.join(self.root_mount_point, "etc"))
fstab_path = os.path.join(self.root_mount_point, "etc", "fstab") fstab_path = os.path.join(self.root_mount_point, "etc", "fstab")
with open(fstab_path, "w") as fl: with open(fstab_path, "w") as fl:
print(HEADER, file=fl) print(FSTAB_HEADER, file=fl)
for partition in self.partitions: for partition in self.partitions:
dct = self.generate_fstab_line_info(partition) dct = self.generate_fstab_line_info(partition)
...@@ -137,11 +192,7 @@ class FstabGenerator(object): ...@@ -137,11 +192,7 @@ class FstabGenerator(object):
self.print_fstab_line(dct, file=fl) self.print_fstab_line(dct, file=fl)
def generate_fstab_line_info(self, partition): def generate_fstab_line_info(self, partition):
""" Generates information for each fstab entry. """ Generates information for each fstab entry. """
:param partition:
:return:
"""
fs = partition["fs"] fs = partition["fs"]
mount_point = partition["mountPoint"] mount_point = partition["mountPoint"]
disk_name = disk_name_for_partition(partition) disk_name = disk_name_for_partition(partition)
...@@ -176,11 +227,7 @@ class FstabGenerator(object): ...@@ -176,11 +227,7 @@ class FstabGenerator(object):
) )
def print_fstab_line(self, dct, file=None): def print_fstab_line(self, dct, file=None):
""" Prints line to '/etc/fstab' file. """ Prints line to '/etc/fstab' file. """
:param dct:
:param file:
"""
line = "{:41} {:<14} {:<7} {:<10} 0 {}".format(dct["device"], line = "{:41} {:<14} {:<7} {:<10} 0 {}".format(dct["device"],
dct["mount_point"], dct["mount_point"],
dct["fs"], dct["fs"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment