2014-07-22 17:38:20 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-12-20 14:39:09 +01:00
|
|
|
# === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-22 17:38:20 +02:00
|
|
|
#
|
|
|
|
# Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
2017-03-29 21:09:25 +02:00
|
|
|
# Copyright 2017, Alf Gaida <agaida@siduction.org>
|
2014-07-22 17:38:20 +02:00
|
|
|
#
|
|
|
|
# Calamares is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Calamares is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-07-24 10:17:46 +02:00
|
|
|
import tempfile
|
2016-11-10 15:58:05 +01:00
|
|
|
import subprocess
|
2014-07-22 17:38:20 +02:00
|
|
|
|
2014-07-24 10:17:46 +02:00
|
|
|
import libcalamares
|
2014-07-22 17:38:20 +02:00
|
|
|
|
2014-07-24 17:14:56 +02:00
|
|
|
|
2014-07-29 14:45:58 +02:00
|
|
|
def mount_partitions(root_mount_point, partitions):
|
2017-03-29 21:09:25 +02:00
|
|
|
"""
|
|
|
|
Pass back mount point and filesystem for each partition.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:param root_mount_point:
|
|
|
|
:param partitions:
|
|
|
|
"""
|
2014-07-22 17:38:20 +02:00
|
|
|
for partition in partitions:
|
2016-05-05 13:35:42 +02:00
|
|
|
if "mountPoint" not in partition or not partition["mountPoint"]:
|
2014-07-22 17:38:20 +02:00
|
|
|
continue
|
2014-07-24 17:14:56 +02:00
|
|
|
# Create mount point with `+` rather than `os.path.join()` because
|
2014-07-24 17:51:51 +02:00
|
|
|
# `partition["mountPoint"]` starts with a '/'.
|
2014-07-29 14:45:58 +02:00
|
|
|
mount_point = root_mount_point + partition["mountPoint"]
|
2017-07-03 17:20:02 +02:00
|
|
|
fstype = partition.get("fs", "").lower()
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2014-09-24 18:25:56 +02:00
|
|
|
if fstype == "fat16" or fstype == "fat32":
|
2014-09-24 18:13:05 +02:00
|
|
|
fstype = "vfat"
|
|
|
|
|
2016-05-05 13:54:15 +02:00
|
|
|
if "luksMapperName" in partition:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.debug(
|
|
|
|
"about to mount {!s}".format(partition["luksMapperName"]))
|
|
|
|
libcalamares.utils.mount(
|
|
|
|
"/dev/mapper/{!s}".format(partition["luksMapperName"]),
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
partition.get("options", ""),
|
|
|
|
)
|
2016-04-30 16:34:34 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
libcalamares.utils.mount(partition["device"],
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
partition.get("options", ""),
|
|
|
|
)
|
2014-07-22 17:38:20 +02:00
|
|
|
|
2016-11-10 15:58:05 +01:00
|
|
|
# If the root partition is btrfs, we create a subvolume "@"
|
|
|
|
# for the root mount point.
|
|
|
|
# If a separate /home partition isn't defined, we also create
|
|
|
|
# a subvolume "@home".
|
|
|
|
# Finally we remount all of the above on the correct paths.
|
|
|
|
if fstype == "btrfs" and partition["mountPoint"] == '/':
|
|
|
|
has_home_mount_point = False
|
|
|
|
for p in partitions:
|
|
|
|
if "mountPoint" not in p or not p["mountPoint"]:
|
|
|
|
continue
|
|
|
|
if p["mountPoint"] == "/home":
|
|
|
|
has_home_mount_point = True
|
|
|
|
break
|
|
|
|
|
|
|
|
subprocess.check_call(['btrfs', 'subvolume', 'create',
|
|
|
|
root_mount_point + '/@'])
|
|
|
|
|
|
|
|
if not has_home_mount_point:
|
|
|
|
subprocess.check_call(['btrfs', 'subvolume', 'create',
|
|
|
|
root_mount_point + '/@home'])
|
|
|
|
|
|
|
|
subprocess.check_call(["umount", "-v", root_mount_point])
|
|
|
|
|
|
|
|
if "luksMapperName" in partition:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
"/dev/mapper/{!s}".format(partition["luksMapperName"]),
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
",".join(
|
|
|
|
["subvol=@", partition.get("options", "")]),
|
|
|
|
)
|
2016-11-10 15:58:05 +01:00
|
|
|
if not has_home_mount_point:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
"/dev/mapper/{!s}".format(partition["luksMapperName"]),
|
|
|
|
root_mount_point + "/home",
|
|
|
|
fstype,
|
|
|
|
",".join(
|
|
|
|
["subvol=@home", partition.get("options", "")]),
|
|
|
|
)
|
2016-11-10 15:58:05 +01:00
|
|
|
else:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
partition["device"],
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
",".join(["subvol=@", partition.get("options", "")]),
|
|
|
|
)
|
2016-11-10 15:58:05 +01:00
|
|
|
if not has_home_mount_point:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
partition["device"],
|
|
|
|
root_mount_point + "/home",
|
|
|
|
fstype,
|
|
|
|
",".join(
|
|
|
|
["subvol=@home", partition.get("options", "")]),
|
|
|
|
)
|
2016-11-10 15:58:05 +01:00
|
|
|
|
2014-07-22 17:38:20 +02:00
|
|
|
|
2014-07-25 16:41:21 +02:00
|
|
|
def run():
|
2017-03-29 21:09:25 +02:00
|
|
|
"""
|
|
|
|
Define mountpoints.
|
2015-02-20 20:54:25 +01:00
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2014-07-29 14:45:58 +02:00
|
|
|
root_mount_point = tempfile.mkdtemp(prefix="calamares-root-")
|
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2018-11-28 13:26:40 +01:00
|
|
|
|
|
|
|
# Guard against missing keys (generally a sign that the config file is bad)
|
|
|
|
extra_mounts = libcalamares.job.configuration.get("extraMounts") or []
|
|
|
|
extra_mounts_efi = libcalamares.job.configuration.get("extraMountsEfi") or []
|
|
|
|
if not extra_mounts and not extra_mounts_efi:
|
|
|
|
libcalamares.utils.warning("No extra mounts defined. Does mount.conf exist?")
|
2014-07-24 17:14:56 +02:00
|
|
|
|
|
|
|
# Sort by mount points to ensure / is mounted before the rest
|
2014-07-29 14:45:58 +02:00
|
|
|
partitions.sort(key=lambda x: x["mountPoint"])
|
2014-07-30 15:37:11 +02:00
|
|
|
mount_partitions(root_mount_point, partitions)
|
|
|
|
mount_partitions(root_mount_point, extra_mounts)
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2018-11-28 13:26:40 +01:00
|
|
|
all_extra_mounts = extra_mounts
|
|
|
|
if libcalamares.globalstorage.value("firmwareType") == "efi":
|
2014-10-12 19:45:02 +02:00
|
|
|
mount_partitions(root_mount_point, extra_mounts_efi)
|
2018-11-28 13:26:40 +01:00
|
|
|
all_extra_mounts.extend(extra_mounts_efi)
|
2014-07-24 17:14:56 +02:00
|
|
|
|
2014-07-29 14:45:58 +02:00
|
|
|
libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
|
2015-06-14 13:04:52 +02:00
|
|
|
|
2014-12-05 00:17:33 +01:00
|
|
|
# Remember the extra mounts for the unpackfs module
|
2018-11-28 13:26:40 +01:00
|
|
|
libcalamares.globalstorage.insert("extraMounts", all_extra_mounts)
|