mirror of
https://github.com/rosalinux/image-builder.git
synced 2025-02-23 10:22:50 +00:00
add make_disk include
This commit is contained in:
parent
e27299add7
commit
898aab8942
2 changed files with 48 additions and 2 deletions
7
build.py
7
build.py
|
@ -6,7 +6,7 @@ import subprocess
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from utils.bootstrap_setup import setup_bootstrap
|
from utils.bootstrap_setup import setup_bootstrap
|
||||||
from utils.common import load_config
|
from utils.common import load_config
|
||||||
from utils.make_disk import create_disk_image
|
from utils.make_disk import create_disk_image, setup_loop_device
|
||||||
|
|
||||||
BASE_DIR = os.getcwd()
|
BASE_DIR = os.getcwd()
|
||||||
TMP_DIR = os.path.join(BASE_DIR, "tmp")
|
TMP_DIR = os.path.join(BASE_DIR, "tmp")
|
||||||
|
@ -85,7 +85,10 @@ def main():
|
||||||
else:
|
else:
|
||||||
print("Skipping rootfs bootstrap")
|
print("Skipping rootfs bootstrap")
|
||||||
|
|
||||||
create_disk_image(TMP_DIR, config, vendor, device)
|
disk_image_path = create_disk_image(TMP_DIR, config, vendor, device)
|
||||||
|
if disk_image_path:
|
||||||
|
loop_device = setup_loop_device(disk_image_path)
|
||||||
|
print(f"Loop device setup at {loop_device}")
|
||||||
print(f"Build completed for {vendor}/{device} with distro {distro}")
|
print(f"Build completed for {vendor}/{device} with distro {distro}")
|
||||||
|
|
||||||
|
|
||||||
|
|
43
utils/make_disk.py
Normal file
43
utils/make_disk.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def create_disk_image(tmp_dir, config, vendor, device):
|
||||||
|
|
||||||
|
boot_size = config.get("BOOT_SIZE").rstrip("MB")
|
||||||
|
root_size = config.get("ROOT_SIZE").rstrip("MB")
|
||||||
|
|
||||||
|
if not root_size:
|
||||||
|
print("Error: ROOT_SIZE is not defined in the configuration.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not boot_size:
|
||||||
|
boot_size = "0"
|
||||||
|
|
||||||
|
disk_image_path = os.path.join(tmp_dir, vendor, device, "disk.img")
|
||||||
|
cmd = [
|
||||||
|
"dd",
|
||||||
|
"if=/dev/zero",
|
||||||
|
f"of={disk_image_path}",
|
||||||
|
"bs=1M",
|
||||||
|
f"count={int(boot_size) + int(root_size)}"
|
||||||
|
]
|
||||||
|
|
||||||
|
print(f"Creating disk image: {disk_image_path} size {root_size} MB")
|
||||||
|
subprocess.run(cmd, check=True)
|
||||||
|
print(f"Disk image created at {disk_image_path}")
|
||||||
|
return disk_image_path
|
||||||
|
|
||||||
|
|
||||||
|
def setup_loop_device(disk_image_path):
|
||||||
|
print("Cleanup /dev/loopX leftovers")
|
||||||
|
leftovers = ["sudo", "losetup", "-d", "/dev/loop*"]
|
||||||
|
subprocess.run(leftovers, check=False)
|
||||||
|
|
||||||
|
cmd = ["sudo", "losetup", "-fP", "--show", disk_image_path]
|
||||||
|
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
||||||
|
loop_device = result.stdout.strip()
|
||||||
|
print(f"Disk image mounted to loop device {loop_device}")
|
||||||
|
return loop_device
|
Loading…
Add table
Reference in a new issue