From 2fc0794e3036ec01d41f520abd09bf8d159c39b2 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sat, 6 Jun 2020 18:39:21 +0200 Subject: [PATCH] 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. --- pmb/helpers/frontend.py | 4 ++-- pmb/install/_install.py | 8 ++++---- pmb/install/blockdevice.py | 14 +++++++------- pmb/install/partition.py | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 28b340f7..26114eaa 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -135,8 +135,8 @@ def chroot(args): # Install blockdevice if args.install_blockdev: - size_boot = 128 * 1024 * 1024 # 128 MiB - size_root = 4096 * 1024 * 1024 # 4 GiB + size_boot = 128 # 128 MiB + size_root = 4096 # 4 GiB pmb.install.blockdevice.create_and_mount_image(args, size_boot, size_root) diff --git a/pmb/install/_install.py b/pmb/install/_install.py index ddfbdad2..68935b49 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -34,17 +34,17 @@ def get_subpartitions_size(args): Calculate the size of the boot and root subpartition. :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 # 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. 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 += 50 * 1024 * 1024 + root += 50 return (boot, root) diff --git a/pmb/install/blockdevice.py b/pmb/install/blockdevice.py index cdc98961..a9b0887b 100644 --- a/pmb/install/blockdevice.py +++ b/pmb/install/blockdevice.py @@ -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. - :param size_boot: size of the boot partition in bytes - :param size_root: size of the root partition in bytes + :param size_boot: size of the boot partition in MiB + :param size_root: size of the root partition in MiB :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]) # 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) free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2)) if size_mb > free: @@ -88,8 +88,8 @@ def create_and_mount_image(args, size_boot, size_root, split=False): # Create empty image files pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"]) size_mb_full = str(size_mb) + "M" - size_mb_boot = str(round(size_boot / (1024**2))) + "M" - size_mb_root = str(round(size_root / (1024**2))) + "M" + size_mb_boot = str(round(size_boot)) + "M" + size_mb_root = str(round(size_root)) + "M" images = {img_path_full: size_mb_full} if split: images = {img_path_boot: size_mb_boot, @@ -117,8 +117,8 @@ def create(args, size_boot, size_root): """ Create /dev/install (the "install blockdevice"). - :param size_boot: size of the boot partition in bytes - :param size_root: size of the root partition in bytes + :param size_boot: size of the boot partition in MiB + :param size_root: size of the root partition in MiB """ pmb.helpers.mount.umount_all( args, args.work + "/chroot_native/dev/install") diff --git a/pmb/install/partition.py b/pmb/install/partition.py index a4e0f011..07aa2379 100644 --- a/pmb/install/partition.py +++ b/pmb/install/partition.py @@ -45,10 +45,10 @@ def partition(args, size_boot): """ 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 - 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 + ", root: the rest)")