calamares/src/modules/mount/main.py

87 lines
3.2 KiB
Python
Raw Normal View History

2014-07-22 17:38:20 +02:00
#!/usr/bin/env python3
2015-02-18 15:06:10 +01:00
# -*- coding: utf-8 -*-
#
2014-07-22 17:38:20 +02:00
# === This file is part of Calamares - <http://github.com/calamares> ===
#
# Copyright 2014, Aurélien Gâteau <agateau@kde.org>
#
# 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/>.
import tempfile
2014-07-22 17:38:20 +02:00
import libcalamares
2014-07-22 17:38:20 +02:00
2014-07-29 14:45:58 +02:00
def mount_partitions(root_mount_point, partitions):
2015-02-21 10:37:56 +01: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:
if "mountPoint" not in partition or not partition["mountPoint"]:
2014-07-22 17:38:20 +02:00
continue
# 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"]
2014-09-24 18:13:05 +02:00
fstype = partition.get("fs", "")
2015-06-14 13:04:52 +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:
2016-05-05 12:49:58 +02:00
libcalamares.utils.debug("about to mount {!s}".format(partition["luksMapperName"]))
2016-05-05 16:36:47 +02:00
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", ""),
)
2014-07-22 17:38:20 +02:00
def run():
2015-02-21 10:37:56 +01: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")
extra_mounts = libcalamares.job.configuration["extraMounts"]
extra_mounts_efi = libcalamares.job.configuration["extraMountsEfi"]
# 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"])
mount_partitions(root_mount_point, partitions)
mount_partitions(root_mount_point, extra_mounts)
fw_type = libcalamares.globalstorage.value("firmwareType")
2015-06-14 13:04:52 +02:00
if fw_type == 'efi':
mount_partitions(root_mount_point, extra_mounts_efi)
2014-07-29 14:45:58 +02:00
libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
2015-06-14 13:04:52 +02:00
# Remember the extra mounts for the unpackfs module
if fw_type == 'efi':
libcalamares.globalstorage.insert("extraMounts", extra_mounts + extra_mounts_efi)
else:
libcalamares.globalstorage.insert("extraMounts", extra_mounts)
return None