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>
|
2019-04-19 17:02:03 +02:00
|
|
|
# Copyright 2019, Adriaan de Groot <groot@kde.org>
|
2019-05-09 13:52:13 +02:00
|
|
|
# Copyright 2019, Kevin Kofler <kevin.kofler@chello.at>
|
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
|
mount: copy the SELinux context of the host directory to the mountpoint
On systems with SELinux enabled, we have to create the directories on
top of which we mount another partition or virtual file system (e.g.,
/dev) with the correct SELinux context, BEFORE we mount the other
partition. Otherwise, SELinux will get really confused when systemd
tries to recreate the mount tree for a private file system namespace for
a service. And unfortunately, even an autorelabel does not fix it
because it runs when /dev etc. are already mounted.
Without this fix, on Fedora >= 30, the system installed with Calamares
would fail to start the dbus-broker system bus, leading to several
important pieces of functionality not working (e.g., shutdown as
non-root).
On systems without SELinux enabled, chcon (which is part of coreutils)
will just print a warning and do nothing, so this should always be safe.
2019-05-09 13:50:31 +02:00
|
|
|
import os
|
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
|
|
|
|
2019-04-19 17:02:03 +02:00
|
|
|
import gettext
|
|
|
|
_ = gettext.translation("calamares-python",
|
|
|
|
localedir=libcalamares.utils.gettext_path(),
|
|
|
|
languages=libcalamares.utils.gettext_languages(),
|
|
|
|
fallback=True).gettext
|
|
|
|
|
|
|
|
|
|
|
|
def pretty_name():
|
|
|
|
return _("Mounting partitions.")
|
|
|
|
|
2019-08-14 09:58:40 +02:00
|
|
|
def mount_partition(root_mount_point, partition, partitions):
|
2019-07-17 12:15:22 +02:00
|
|
|
# Create mount point with `+` rather than `os.path.join()` because
|
|
|
|
# `partition["mountPoint"]` starts with a '/'.
|
|
|
|
raw_mount_point = partition["mountPoint"]
|
|
|
|
mount_point = root_mount_point + raw_mount_point
|
|
|
|
|
|
|
|
# Ensure that the created directory has the correct SELinux context on
|
|
|
|
# SELinux-enabled systems.
|
|
|
|
os.makedirs(mount_point, exist_ok=True)
|
|
|
|
subprocess.call(['chcon', '--reference=' + raw_mount_point,
|
|
|
|
mount_point])
|
|
|
|
|
|
|
|
fstype = partition.get("fs", "").lower()
|
|
|
|
|
|
|
|
if fstype == "fat16" or fstype == "fat32":
|
|
|
|
fstype = "vfat"
|
|
|
|
|
|
|
|
if "luksMapperName" in partition:
|
|
|
|
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", ""),
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
libcalamares.utils.mount(partition["device"],
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
partition.get("options", ""),
|
|
|
|
)
|
|
|
|
|
|
|
|
# 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'])
|
2014-07-24 17:14:56 +02:00
|
|
|
|
2019-07-17 12:15:22 +02:00
|
|
|
subprocess.check_call(["umount", "-v", root_mount_point])
|
2014-09-24 18:13:05 +02:00
|
|
|
|
2016-05-05 13:54:15 +02:00
|
|
|
if "luksMapperName" in partition:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
"/dev/mapper/{!s}".format(partition["luksMapperName"]),
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
2019-07-17 12:15:22 +02:00
|
|
|
",".join(
|
|
|
|
["subvol=@", partition.get("options", "")]),
|
2017-06-02 19:58:36 +02:00
|
|
|
)
|
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"]),
|
2019-07-17 12:15:22 +02:00
|
|
|
root_mount_point + "/home",
|
2017-06-02 19:58:36 +02:00
|
|
|
fstype,
|
|
|
|
",".join(
|
2019-07-17 12:15:22 +02:00
|
|
|
["subvol=@home", partition.get("options", "")]),
|
2017-06-02 19:58:36 +02:00
|
|
|
)
|
2019-07-17 12:15:22 +02:00
|
|
|
else:
|
|
|
|
libcalamares.utils.mount(
|
|
|
|
partition["device"],
|
|
|
|
mount_point,
|
|
|
|
fstype,
|
|
|
|
",".join(["subvol=@", partition.get("options", "")]),
|
|
|
|
)
|
|
|
|
if not has_home_mount_point:
|
2017-06-02 19:58:36 +02:00
|
|
|
libcalamares.utils.mount(
|
|
|
|
partition["device"],
|
2019-07-17 12:15:22 +02:00
|
|
|
root_mount_point + "/home",
|
2017-06-02 19:58:36 +02:00
|
|
|
fstype,
|
2019-07-17 12:15:22 +02:00
|
|
|
",".join(
|
|
|
|
["subvol=@home", partition.get("options", "")]),
|
2017-06-02 19:58:36 +02:00
|
|
|
)
|
2019-07-17 12:15:22 +02: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
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2018-11-28 13:26:40 +01:00
|
|
|
|
2019-04-28 20:32:27 +02:00
|
|
|
if not partitions:
|
|
|
|
libcalamares.utils.warning("partitions is empty, {!s}".format(partitions))
|
|
|
|
return (_("Configuration Error"),
|
|
|
|
_("No partitions are defined for <pre>{!s}</pre> to use." ).format("mount"))
|
|
|
|
|
|
|
|
root_mount_point = tempfile.mkdtemp(prefix="calamares-root-")
|
|
|
|
|
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
|
|
|
|
2018-11-28 13:26:40 +01:00
|
|
|
if libcalamares.globalstorage.value("firmwareType") == "efi":
|
2019-08-14 09:58:40 +02:00
|
|
|
extra_mounts.extend(extra_mounts_efi)
|
|
|
|
|
|
|
|
# Add extra mounts to the partitions list and sort by mount points.
|
|
|
|
# This way, we ensure / is mounted before the rest, and every mount point
|
|
|
|
# is created on the right partition (e.g. if a partition is to be mounted
|
|
|
|
# under /tmp, we make sure /tmp is mounted before the partition)
|
|
|
|
partitions.extend(extra_mounts)
|
|
|
|
partitions.sort(key=lambda x: x["mountPoint"])
|
|
|
|
for partition in partitions:
|
|
|
|
if "mountPoint" not in partition or not partition["mountPoint"]:
|
|
|
|
continue
|
|
|
|
mount_partition(root_mount_point, partition, partitions)
|
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
|
2019-08-14 09:58:40 +02:00
|
|
|
libcalamares.globalstorage.insert("extraMounts", extra_mounts)
|