2020-02-20 20:07:28 +00:00
|
|
|
# Copyright 2020 Oliver Smith
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-05-26 20:08:45 +00:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import pmb.chroot
|
|
|
|
|
|
|
|
|
|
|
|
def format_and_mount_boot(args):
|
|
|
|
mountpoint = "/mnt/install/boot"
|
2017-06-22 10:19:53 +00:00
|
|
|
device = "/dev/installp1"
|
2018-05-29 19:33:40 +00:00
|
|
|
filesystem = args.deviceinfo["boot_filesystem"] or "ext2"
|
|
|
|
logging.info("(native) format " + device + " (boot, " + filesystem + "), mount to " +
|
2017-05-26 20:08:45 +00:00
|
|
|
mountpoint)
|
2018-05-29 19:33:40 +00:00
|
|
|
if filesystem == "fat16":
|
|
|
|
pmb.chroot.root(args, ["mkfs.fat", "-F", "16", "-n", "pmOS_boot", device])
|
2019-10-09 18:21:43 +00:00
|
|
|
elif filesystem == "fat32":
|
|
|
|
pmb.chroot.root(args, ["mkfs.fat", "-F", "32", "-n", "pmOS_boot", device])
|
2018-05-29 19:33:40 +00:00
|
|
|
elif filesystem == "ext2":
|
|
|
|
pmb.chroot.root(args, ["mkfs.ext2", "-F", "-q", "-L", "pmOS_boot", device])
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Filesystem " + filesystem + " is not supported!")
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.root(args, ["mkdir", "-p", mountpoint])
|
2017-06-22 10:19:53 +00:00
|
|
|
pmb.chroot.root(args, ["mount", device, mountpoint])
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2020-06-06 17:05:11 +00:00
|
|
|
def format_and_mount_root(args, device):
|
|
|
|
"""
|
|
|
|
:param device: root partition on install block device (e.g. /dev/installp2)
|
|
|
|
"""
|
2017-05-26 20:08:45 +00:00
|
|
|
mountpoint = "/dev/mapper/pm_crypt"
|
2017-06-28 15:22:48 +00:00
|
|
|
if args.full_disk_encryption:
|
2017-06-22 10:19:53 +00:00
|
|
|
logging.info("(native) format " + device + " (root, luks), mount to " +
|
|
|
|
mountpoint)
|
2017-07-22 10:49:43 +00:00
|
|
|
logging.info(
|
|
|
|
" *** TYPE IN THE FULL DISK ENCRYPTION PASSWORD (TWICE!) ***")
|
2017-06-22 10:19:53 +00:00
|
|
|
pmb.chroot.root(args, ["cryptsetup", "luksFormat", "--use-urandom",
|
2017-09-19 19:46:18 +00:00
|
|
|
"--cipher", args.cipher, "-q", device,
|
2018-07-14 01:13:28 +00:00
|
|
|
"--iter-time", args.iter_time],
|
|
|
|
output="interactive")
|
2017-06-22 10:19:53 +00:00
|
|
|
pmb.chroot.root(args, ["cryptsetup", "luksOpen", device,
|
2018-07-14 01:13:28 +00:00
|
|
|
"pm_crypt"], output="interactive")
|
2017-06-22 10:19:53 +00:00
|
|
|
if not os.path.exists(args.work + "/chroot_native" + mountpoint):
|
|
|
|
raise RuntimeError("Failed to open cryptdevice!")
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2020-06-07 06:50:28 +00:00
|
|
|
def format_and_mount_pm_crypt(args, device, root_label):
|
2020-06-06 17:05:11 +00:00
|
|
|
"""
|
|
|
|
:param device: root partition on install block device (e.g. /dev/installp2)
|
2020-06-07 06:50:28 +00:00
|
|
|
:param root_label: label of the root partition (e.g. "pmOS_root")
|
2020-06-06 17:05:11 +00:00
|
|
|
"""
|
2018-01-28 23:25:21 +00:00
|
|
|
# Block device
|
2017-06-28 15:22:48 +00:00
|
|
|
if args.full_disk_encryption:
|
2017-06-22 10:19:53 +00:00
|
|
|
device = "/dev/mapper/pm_crypt"
|
2018-01-28 23:25:21 +00:00
|
|
|
|
|
|
|
# Format
|
|
|
|
if not args.rsync:
|
|
|
|
logging.info("(native) format " + device)
|
2018-03-28 18:00:18 +00:00
|
|
|
# Some downstream kernels don't support metadata_csum (#1364).
|
|
|
|
# When changing the options of mkfs.ext4, also change them in the
|
|
|
|
# recovery zip code (see 'grep -r mkfs\.ext4')!
|
2019-12-07 13:21:22 +00:00
|
|
|
mkfs_ext4_args = ["mkfs.ext4", "-O", "^metadata_csum", "-F",
|
2020-06-07 06:50:28 +00:00
|
|
|
"-q", "-L", root_label]
|
2019-12-07 13:21:22 +00:00
|
|
|
|
|
|
|
# When we don't know the file system size before hand like
|
|
|
|
# with non-block devices, we need to explicitely set a number of
|
|
|
|
# inodes. See #1717 and #1845 for details
|
|
|
|
if not args.sdcard:
|
|
|
|
mkfs_ext4_args = mkfs_ext4_args + ["-N", "100000"]
|
|
|
|
|
|
|
|
pmb.chroot.root(args, mkfs_ext4_args + [device])
|
2018-01-28 23:25:21 +00:00
|
|
|
|
|
|
|
# Mount
|
2017-05-26 20:08:45 +00:00
|
|
|
mountpoint = "/mnt/install"
|
2018-01-28 23:25:21 +00:00
|
|
|
logging.info("(native) mount " + device + " to " + mountpoint)
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.root(args, ["mkdir", "-p", mountpoint])
|
2017-06-22 10:19:53 +00:00
|
|
|
pmb.chroot.root(args, ["mount", device, mountpoint])
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2020-06-07 06:50:28 +00:00
|
|
|
def format(args, size_reserve, root_label):
|
2020-06-06 17:05:11 +00:00
|
|
|
"""
|
|
|
|
:param size_reserve: empty partition between root and boot in MiB (pma#463)
|
2020-06-07 06:50:28 +00:00
|
|
|
:param root_label: label of the root partition (e.g. "pmOS_root")
|
2020-06-06 17:05:11 +00:00
|
|
|
"""
|
|
|
|
root_dev = "/dev/installp3" if size_reserve else "/dev/installp2"
|
|
|
|
format_and_mount_root(args, root_dev)
|
2020-06-07 06:50:28 +00:00
|
|
|
format_and_mount_pm_crypt(args, root_dev, root_label)
|
2017-05-26 20:08:45 +00:00
|
|
|
format_and_mount_boot(args)
|