Generating rootfs image is now 110% less scary (#758)

This adds a check to make sure there is enough disk space for creating the device image.
One of the two proposed improvements of #708.
This commit is contained in:
clayton craft 2017-10-13 18:52:43 +00:00 committed by Oliver Smith
parent a13623bbfb
commit 9f0c884188
1 changed files with 8 additions and 8 deletions

View File

@ -66,16 +66,16 @@ def create_and_mount_image(args, size):
raise RuntimeError("Failed to remove old image file: " +
img_path_outside)
# Convert to MB and ask for confirmation
mb = str(round(size / 1024 / 1024)) + "M"
logging.info("(native) create " + args.device + ".img (" + mb + ")")
logging.info("WARNING: Make sure, that your target device's partition"
" table has allocated at least " + mb + " as system"
" partition!")
if not pmb.helpers.cli.confirm(args, default=True):
raise RuntimeError("Aborted.")
# Make sure there is enough free space
size_mb = round(size / (1024**2))
disk_data = os.statvfs(args.work)
free = round((disk_data.f_bsize * disk_data.f_bavail) / (1024**2))
if size_mb > free:
raise RuntimeError("Not enough free space to create rootfs image! (free: " + str(free) + "M, required: " + str(size_mb) + "M)")
mb = str(size_mb) + "M"
# Create empty image file
logging.info("(native) create " + args.device + ".img (" + mb + ")")
pmb.chroot.user(args, ["mkdir", "-p", "/home/pmos/rootfs"])
pmb.chroot.root(args, ["truncate", "-s", mb, img_path])