Write Btrfs subvolume lines to fstab.

This commit is contained in:
Teo Mrnjavac 2016-11-10 15:58:48 +01:00 committed by Philip
parent 84b96b4f18
commit e0c5e81b5b

View File

@ -21,6 +21,7 @@
import os
import re
import subprocess
import libcalamares
@ -180,10 +181,33 @@ class FstabGenerator(object):
print(FSTAB_HEADER, file=fstab_file)
for partition in self.partitions:
dct = self.generate_fstab_line_info(partition)
# Special treatment for a btrfs root with @ and @home subvolumes
if partition["fs"] == "btrfs" and partition["mountPoint"] == "/":
output = subprocess.check_output(['btrfs',
'subvolume',
'list',
self.root_mount_point])
output_lines = output.splitlines()
for line in output_lines:
if line.endswith(b'path @'):
root_entry = partition
root_entry["subvol"] = "@"
dct = self.generate_fstab_line_info(root_entry)
if dct:
self.print_fstab_line(dct, file=fstab_file)
elif line.endswith(b'path @home'):
home_entry = partition
home_entry["mountPoint"] = "/home"
home_entry["subvol"] = "@home"
dct = self.generate_fstab_line_info(home_entry)
if dct:
self.print_fstab_line(dct, file=fstab_file)
if dct:
self.print_fstab_line(dct, file=fstab_file)
else:
dct = self.generate_fstab_line_info(partition)
if dct:
self.print_fstab_line(dct, file=fstab_file)
if self.root_is_ssd:
# Mount /tmp on a tmpfs
@ -224,12 +248,21 @@ class FstabGenerator(object):
if mount_point == "/":
self.root_is_ssd = is_ssd
if filesystem == "btrfs" and "subvol" in partition:
return dict(device="UUID=" + partition["uuid"],
mount_point=mount_point,
fs=filesystem,
options=",".join(["subvol={}".format(partition["subvol"]),
options]),
check=check,
)
return dict(device="UUID=" + partition["uuid"],
mount_point=mount_point or "swap",
fs=filesystem,
options=options,
check=check,
)
)
def print_fstab_line(self, dct, file=None):
""" Prints line to '/etc/fstab' file. """