pmb/install: have size_boot, size_root in MiB (MR 1946)

Prepare for a future patch, that adds reserved space in MiB, by changing
size_boot and size_root from bytes to MB everywhere. This is what we need
most of the time and allows to drop some /1024**2 statements.
This commit is contained in:
Oliver Smith 2020-06-06 18:39:21 +02:00 committed by Bart Ribbers
parent 63fc2b621a
commit 2fc0794e30
No known key found for this signature in database
GPG Key ID: 699D16185DAFAE61
4 changed files with 15 additions and 15 deletions

View File

@ -135,8 +135,8 @@ def chroot(args):
# Install blockdevice # Install blockdevice
if args.install_blockdev: if args.install_blockdev:
size_boot = 128 * 1024 * 1024 # 128 MiB size_boot = 128 # 128 MiB
size_root = 4096 * 1024 * 1024 # 4 GiB size_root = 4096 # 4 GiB
pmb.install.blockdevice.create_and_mount_image(args, size_boot, pmb.install.blockdevice.create_and_mount_image(args, size_boot,
size_root) size_root)

View File

@ -34,17 +34,17 @@ def get_subpartitions_size(args):
Calculate the size of the boot and root subpartition. Calculate the size of the boot and root subpartition.
:returns: (boot, root) the size of the boot and root :returns: (boot, root) the size of the boot and root
partition as integer in bytes partition as integer in MiB
""" """
boot = int(args.boot_size) * 1024 * 1024 boot = int(args.boot_size)
# Estimate root partition size, then add some free space. The size # Estimate root partition size, then add some free space. The size
# calculation is not as trivial as one may think, and depending on the # calculation is not as trivial as one may think, and depending on the
# file system etc it seems to be just impossible to get it right. # file system etc it seems to be just impossible to get it right.
chroot = args.work + "/chroot_rootfs_" + args.device chroot = args.work + "/chroot_rootfs_" + args.device
root = pmb.helpers.other.folder_size(args, chroot) root = pmb.helpers.other.folder_size(args, chroot) / 1024 / 1024
root *= 1.20 root *= 1.20
root += 50 * 1024 * 1024 root += 50
return (boot, root) return (boot, root)

View File

@ -58,8 +58,8 @@ def create_and_mount_image(args, size_boot, size_root, split=False):
""" """
Create a new image file, and mount it as /dev/install. Create a new image file, and mount it as /dev/install.
:param size_boot: size of the boot partition in bytes :param size_boot: size of the boot partition in MiB
:param size_root: size of the root partition in bytes :param size_root: size of the root partition in MiB
:param split: create separate images for boot and root partitions :param split: create separate images for boot and root partitions
""" """
@ -79,7 +79,7 @@ def create_and_mount_image(args, size_boot, size_root, split=False):
pmb.chroot.root(args, ["rm", img_path]) pmb.chroot.root(args, ["rm", img_path])
# Make sure there is enough free space # Make sure there is enough free space
size_mb = round((size_boot + size_root) / (1024**2)) size_mb = round(size_boot + size_root)
disk_data = os.statvfs(args.work) disk_data = os.statvfs(args.work)
free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2)) free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2))
if size_mb > free: if size_mb > free:
@ -88,8 +88,8 @@ def create_and_mount_image(args, size_boot, size_root, split=False):
# Create empty image files # Create empty image files
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"]) pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"])
size_mb_full = str(size_mb) + "M" size_mb_full = str(size_mb) + "M"
size_mb_boot = str(round(size_boot / (1024**2))) + "M" size_mb_boot = str(round(size_boot)) + "M"
size_mb_root = str(round(size_root / (1024**2))) + "M" size_mb_root = str(round(size_root)) + "M"
images = {img_path_full: size_mb_full} images = {img_path_full: size_mb_full}
if split: if split:
images = {img_path_boot: size_mb_boot, images = {img_path_boot: size_mb_boot,
@ -117,8 +117,8 @@ def create(args, size_boot, size_root):
""" """
Create /dev/install (the "install blockdevice"). Create /dev/install (the "install blockdevice").
:param size_boot: size of the boot partition in bytes :param size_boot: size of the boot partition in MiB
:param size_root: size of the root partition in bytes :param size_root: size of the root partition in MiB
""" """
pmb.helpers.mount.umount_all( pmb.helpers.mount.umount_all(
args, args.work + "/chroot_native/dev/install") args, args.work + "/chroot_native/dev/install")

View File

@ -45,10 +45,10 @@ def partition(args, size_boot):
""" """
Partition /dev/install and create /dev/install{p1,p2} Partition /dev/install and create /dev/install{p1,p2}
size_boot: size of the boot partition in bytes. size_boot: size of the boot partition in MB
""" """
# Convert to MB and print info # Convert to MB and print info
mb_boot = str(round(size_boot / 1024 / 1024)) + "M" mb_boot = str(round(size_boot)) + "M"
logging.info("(native) partition /dev/install (boot: " + mb_boot + logging.info("(native) partition /dev/install (boot: " + mb_boot +
", root: the rest)") ", root: the rest)")