source: calamares/trunk/fuentes/src/modules/mount/main.py @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.5 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# === This file is part of Calamares - <https://github.com/calamares> ===
5#
6#   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
7#   Copyright 2017, Alf Gaida <agaida@siduction.org>
8#
9#   Calamares is free software: you can redistribute it and/or modify
10#   it under the terms of the GNU General Public License as published by
11#   the Free Software Foundation, either version 3 of the License, or
12#   (at your option) any later version.
13#
14#   Calamares is distributed in the hope that it will be useful,
15#   but WITHOUT ANY WARRANTY; without even the implied warranty of
16#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17#   GNU General Public License for more details.
18#
19#   You should have received a copy of the GNU General Public License
20#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
21
22import tempfile
23import subprocess
24
25import libcalamares
26
27
28def mount_partitions(root_mount_point, partitions):
29    """
30    Pass back mount point and filesystem for each partition.
31
32    :param root_mount_point:
33    :param partitions:
34    """
35    for partition in partitions:
36        if "mountPoint" not in partition or not partition["mountPoint"]:
37            continue
38        # Create mount point with `+` rather than `os.path.join()` because
39        # `partition["mountPoint"]` starts with a '/'.
40        mount_point = root_mount_point + partition["mountPoint"]
41        fstype = partition.get("fs", "").lower()
42
43        if fstype == "fat16" or fstype == "fat32":
44            fstype = "vfat"
45
46        if "luksMapperName" in partition:
47            libcalamares.utils.debug(
48                "about to mount {!s}".format(partition["luksMapperName"]))
49            libcalamares.utils.mount(
50                "/dev/mapper/{!s}".format(partition["luksMapperName"]),
51                mount_point,
52                fstype,
53                partition.get("options", ""),
54                )
55
56        else:
57            libcalamares.utils.mount(partition["device"],
58                                     mount_point,
59                                     fstype,
60                                     partition.get("options", ""),
61                                     )
62
63        # If the root partition is btrfs, we create a subvolume "@"
64        # for the root mount point.
65        # If a separate /home partition isn't defined, we also create
66        # a subvolume "@home".
67        # Finally we remount all of the above on the correct paths.
68        if fstype == "btrfs" and partition["mountPoint"] == '/':
69            has_home_mount_point = False
70            for p in partitions:
71                if "mountPoint" not in p or not p["mountPoint"]:
72                    continue
73                if p["mountPoint"] == "/home":
74                    has_home_mount_point = True
75                    break
76
77            subprocess.check_call(['btrfs', 'subvolume', 'create',
78                                   root_mount_point + '/@'])
79
80            if not has_home_mount_point:
81                subprocess.check_call(['btrfs', 'subvolume', 'create',
82                                       root_mount_point + '/@home'])
83
84            subprocess.check_call(["umount", "-v", root_mount_point])
85
86            if "luksMapperName" in partition:
87                libcalamares.utils.mount(
88                    "/dev/mapper/{!s}".format(partition["luksMapperName"]),
89                    mount_point,
90                    fstype,
91                    ",".join(
92                        ["subvol=@", partition.get("options", "")]),
93                    )
94                if not has_home_mount_point:
95                    libcalamares.utils.mount(
96                        "/dev/mapper/{!s}".format(partition["luksMapperName"]),
97                        root_mount_point + "/home",
98                        fstype,
99                        ",".join(
100                            ["subvol=@home", partition.get("options", "")]),
101                        )
102            else:
103                libcalamares.utils.mount(
104                    partition["device"],
105                    mount_point,
106                    fstype,
107                    ",".join(["subvol=@", partition.get("options", "")]),
108                    )
109                if not has_home_mount_point:
110                    libcalamares.utils.mount(
111                        partition["device"],
112                        root_mount_point + "/home",
113                        fstype,
114                        ",".join(
115                            ["subvol=@home", partition.get("options", "")]),
116                        )
117
118
119def run():
120    """
121    Define mountpoints.
122
123    :return:
124    """
125    root_mount_point = tempfile.mkdtemp(prefix="calamares-root-")
126    partitions = libcalamares.globalstorage.value("partitions")
127    extra_mounts = libcalamares.job.configuration["extraMounts"]
128    extra_mounts_efi = libcalamares.job.configuration["extraMountsEfi"]
129
130    # Sort by mount points to ensure / is mounted before the rest
131    partitions.sort(key=lambda x: x["mountPoint"])
132    mount_partitions(root_mount_point, partitions)
133    mount_partitions(root_mount_point, extra_mounts)
134    fw_type = libcalamares.globalstorage.value("firmwareType")
135
136    if fw_type == 'efi':
137        mount_partitions(root_mount_point, extra_mounts_efi)
138
139    libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
140
141    # Remember the extra mounts for the unpackfs module
142    if fw_type == 'efi':
143        libcalamares.globalstorage.insert(
144            "extraMounts", extra_mounts + extra_mounts_efi)
145    else:
146        libcalamares.globalstorage.insert("extraMounts", extra_mounts)
147
148    return None
Note: See TracBrowser for help on using the repository browser.