Commit 82b73bc5 authored by rgaudin's avatar rgaudin
Browse files

Fixed #242: use disk and root sizes in bytes and prepare master writable to an 8GB card

parent f0e3abed
Pipeline #76024 passed with stage
in 323 minutes and 9 seconds
......@@ -19,8 +19,8 @@ disk: /dev/mmcblk0
root_partition: "{{ disk }}p2"
data_partition: "{{ disk }}p3"
data_path: /data
disk_size: 4
root_partition_size: 3
disk_size: 7760000000
root_partition_size: 7000000000
username: ideascube
password: $6$YcJS1HjRAv/$1bUosoPalzHEvfpx71UhnG6vCeckTGbA5U1i6UpA8X21Jrv7fYRPyNrq/YWuiBp3xQWd5kRRhrKKPHcbTkkfQ/
mirror: https://download.kiwix.org
......
......@@ -31,16 +31,18 @@ except NameError:
ONE_GB = int(1e9)
def main(root_size=7, disk_size=8):
def main(root_size, disk_size):
# sanitize input
if disk_size == "-":
disk_size = None
elif not isinstance(disk_size, int):
if not isinstance(disk_size, int):
disk_size = int(disk_size)
if disk_size < 1024:
disk_size *= ONE_GB
if not isinstance(root_size, int):
root_size = int(root_size)
if root_size < 1024:
root_size *= ONE_GB
try:
data = get_partitions_boundaries(
......@@ -56,7 +58,7 @@ def main(root_size=7, disk_size=8):
sys.exit(1)
def get_partitions_boundaries(lines, root_size, disk_size=None):
def get_partitions_boundaries(lines, root_size, disk_size):
sector_size = 512
round_bound = 128
......@@ -100,7 +102,7 @@ def get_partitions_boundaries(lines, root_size, disk_size=None):
if is_full:
pass # whether root part was already expanded
size_up_to_root_b = root_size * ONE_GB
size_up_to_root_b = root_size
nb_clusters_endofroot = size_up_to_root_b // sector_size
# align partitions (otherwise exfat-fuse gets often corrupt)
......@@ -113,7 +115,7 @@ def get_partitions_boundaries(lines, root_size, disk_size=None):
# end second partition on a predicatble cluster
# full_size - root_size (root_end) - margin
data_bytes = disk_size * ONE_GB - root_size * ONE_GB - end_margin
data_bytes = disk_size - root_size - end_margin
data_clusters = data_bytes // sector_size
data_end = data_start + data_clusters
......
......@@ -134,8 +134,8 @@ def build_extra_vars(
""" extra-vars friendly format of the ansiblecube configuration """
extra_vars = {
"root_partition_size": root_partition_size // ONE_GB,
"disk_size": disk_size // ONE_GB,
"root_partition_size": root_partition_size,
"disk_size": disk_size,
"project_name": name,
"timezone": timezone,
"language": language,
......
......@@ -230,13 +230,12 @@ else:
# parse requested size
try:
args.size = humanfriendly.parse_size(args.size)
args.output_size = get_adjusted_image_size(args.size) # adjust image size for HW
except Exception:
print("Unable to understand required size ({})".format(args.size))
sys.exit(1)
else:
args.human_size = human_readable_size(args.size, False)
# adjust image size for content
args.output_size = get_adjusted_image_size(args.size)
args.human_size = human_readable_size(args.output_size, False)
# check arguments
......@@ -351,7 +350,7 @@ try:
edupi=args.edupi == "yes",
edupi_resources=args.edupi_resources,
zim_install=args.zim_install,
size=args.size,
size=args.output_size,
logger=logger,
cancel_event=cancel_event,
sd_card=args.sdcard,
......
......@@ -17,12 +17,12 @@ import data
from util import human_readable_size
from backend import qemu
from backend.content import get_content
from util import CLILogger, CancelEvent, ONE_GB
from backend.download import download_content, unzip_file
from backend.ansiblecube import (
run_for_image,
ansiblecube_path as ansiblecube_emulation_path,
)
from util import CLILogger, CancelEvent, ONE_GB, get_adjusted_image_size
MIN_ROOT_SIZE = 7 * ONE_GB
......@@ -41,7 +41,9 @@ def run_in_qemu(image_fpath, disk_size, root_size, logger, cancel_event, qemu_ra
is_master=True,
)
logger.step("resizing QEMU image to {}GB".format(disk_size // ONE_GB))
logger.step(
"resizing QEMU image to {}GB".format(human_readable_size(disk_size, False))
)
emulator.resize_image(disk_size)
# Run emulation
......@@ -73,7 +75,7 @@ def main(logger, disk_size, root_size, build_folder, qemu_ram, image_fname=None)
# convert sizes to bytes and make sure those are usable
try:
root_size = int(root_size) * ONE_GB
disk_size = int(disk_size) * ONE_GB
disk_size = get_adjusted_image_size(int(disk_size) * ONE_GB)
if root_size < MIN_ROOT_SIZE:
raise ValueError(
......@@ -88,6 +90,12 @@ def main(logger, disk_size, root_size, build_folder, qemu_ram, image_fname=None)
logger.err("Erroneous size option: {}".format(exp))
sys.exit(1)
logger.step(
"Starting master creation: {} ({} root)".format(
human_readable_size(disk_size, False), human_readable_size(root_size, False)
)
)
# default output file name
if image_fname is None:
image_fname = "hotspot-master_{date}.img".format(
......
......@@ -509,10 +509,9 @@ def get_adjusted_image_size(size):
the larger the SD card, the larger the loss space is """
if size / ONE_GB <= 16:
rate = .98
elif size / ONE_GB <= 64:
rate = .97
else:
rate = .96
# if size is not a rounded GB multiple, assume it's OK
if not size % ONE_GB == 0:
return size
rate = .97 if size / ONE_GB <= 16 else .96
return int(size * rate)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment