2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2020-01-06 01:40:27 +00:00
|
|
|
Copyright 2020 Oliver Smith
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
|
|
|
|
pmbootstrap 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.
|
|
|
|
|
|
|
|
pmbootstrap 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 pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import logging
|
2017-08-30 18:58:51 +00:00
|
|
|
import os
|
|
|
|
import time
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.chroot
|
|
|
|
import pmb.config
|
|
|
|
import pmb.install.losetup
|
|
|
|
|
|
|
|
|
|
|
|
def partitions_mount(args):
|
|
|
|
"""
|
|
|
|
Mount blockdevices of partitions inside native chroot
|
|
|
|
"""
|
|
|
|
prefix = args.sdcard
|
|
|
|
if not args.sdcard:
|
2017-10-12 20:08:10 +00:00
|
|
|
img_path = "/home/pmos/rootfs/" + args.device + ".img"
|
2017-05-26 20:08:45 +00:00
|
|
|
prefix = pmb.install.losetup.device_by_back_file(args, img_path)
|
2017-06-04 00:57:37 +00:00
|
|
|
|
|
|
|
partition_prefix = None
|
2017-08-30 18:58:51 +00:00
|
|
|
tries = 20
|
|
|
|
for i in range(tries):
|
|
|
|
for symbol in ["p", ""]:
|
|
|
|
if os.path.exists(prefix + symbol + "1"):
|
|
|
|
partition_prefix = symbol
|
|
|
|
if partition_prefix is not None:
|
|
|
|
break
|
|
|
|
logging.debug("NOTE: (" + str(i + 1) + "/" + str(tries) + ") failed to find"
|
|
|
|
" the install partition. Retrying...")
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
2017-06-09 22:29:48 +00:00
|
|
|
if partition_prefix is None:
|
2017-06-04 00:57:37 +00:00
|
|
|
raise RuntimeError("Unable to find the partition prefix,"
|
|
|
|
" expected the first partition of " +
|
2017-06-04 02:27:49 +00:00
|
|
|
prefix + " to be located at " + prefix +
|
|
|
|
"1 or " + prefix + "p1!")
|
2017-06-04 00:57:37 +00:00
|
|
|
|
|
|
|
for i in [1, 2]:
|
|
|
|
source = prefix + partition_prefix + str(i)
|
|
|
|
target = args.work + "/chroot_native/dev/installp" + str(i)
|
2020-01-20 12:27:40 +00:00
|
|
|
pmb.helpers.mount.bind_file(args, source, target)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
def partition(args, size_boot):
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
Partition /dev/install and create /dev/install{p1,p2}
|
|
|
|
|
2017-08-18 19:19:48 +00:00
|
|
|
size_boot: size of the boot partition in bytes.
|
|
|
|
"""
|
|
|
|
# Convert to MB and print info
|
|
|
|
mb_boot = str(round(size_boot / 1024 / 1024)) + "M"
|
|
|
|
logging.info("(native) partition /dev/install (boot: " + mb_boot +
|
2017-05-26 20:08:45 +00:00
|
|
|
", root: the rest)")
|
2017-08-18 19:19:48 +00:00
|
|
|
|
2018-05-29 19:33:40 +00:00
|
|
|
filesystem = args.deviceinfo["boot_filesystem"] or "ext2"
|
|
|
|
|
2017-08-25 17:39:52 +00:00
|
|
|
# Actual partitioning with 'parted'. Using check=False, because parted
|
|
|
|
# sometimes "fails to inform the kernel". In case it really failed with
|
|
|
|
# partitioning, the follow-up mounting/formatting will not work, so it
|
|
|
|
# will stop there (see #463).
|
2020-01-12 03:24:37 +00:00
|
|
|
boot_part_start = args.deviceinfo["boot_part_start"] or "2048"
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
commands = [
|
|
|
|
["mktable", "msdos"],
|
2020-01-12 03:24:37 +00:00
|
|
|
["mkpart", "primary", filesystem, boot_part_start + 's', mb_boot],
|
2017-08-18 19:19:48 +00:00
|
|
|
["mkpart", "primary", mb_boot, "100%"],
|
2017-05-26 20:08:45 +00:00
|
|
|
["set", "1", "boot", "on"]
|
|
|
|
]
|
|
|
|
for command in commands:
|
|
|
|
pmb.chroot.root(args, ["parted", "-s", "/dev/install"] +
|
2017-08-25 17:39:52 +00:00
|
|
|
command, check=False)
|