Skip to content

Commit

Permalink
chore: shrink root filesystem to fit system
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Nov 29, 2023
1 parent cf45e43 commit 58b378b
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions crates/rugpi-bakery/src/tasks/bake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,50 @@ pub fn run(args: &Args, task: &BakeTask) -> Anyhow<()> {
mkfs_ext4(loop_device.partition(5), "system-a")?;
let root_dir = TempDir::new("rugpi")?;
let root_dir_path = Utf8Path::from_path(root_dir.path()).unwrap();
let mounted_root = Mounted::mount(loop_device.partition(5), root_dir_path)?;
let mut boot_dir = root_dir_path.join("boot");
let boot_firmware_dir = boot_dir.join("firmware");
if boot_firmware_dir.exists() {
boot_dir = boot_firmware_dir;
}
fs::create_dir_all(&boot_dir)?;
let mounted_boot = Mounted::mount(loop_device.partition(2), &boot_dir)?;
let config_dir = TempDir::new("rugpi")?;
let config_dir_path = Utf8Path::from_path(config_dir.path()).unwrap();
let mounted_config = Mounted::mount(loop_device.partition(1), &config_dir_path)?;
let ctx = BakeCtx {
config,
mounted_boot,
mounted_root,
mounted_config,
};

run!(["tar", "-x", "-f", &task.archive, "-C", root_dir_path])?;
println!("Patching boot configuration...");
patch_boot(ctx.mounted_boot.path(), format!("PARTUUID={disk_id}-05"))?;
println!("Patching `config.txt`...");
patch_config(boot_dir.join("config.txt"))?;

match ctx.config.boot_flow {
BootFlow::Tryboot => setup_tryboot_boot_flow(&ctx)?,
BootFlow::UBoot => setup_uboot_boot_flow(&ctx)?,
}
{
let mounted_root = Mounted::mount(loop_device.partition(5), root_dir_path)?;
let mut boot_dir = root_dir_path.join("boot");
let boot_firmware_dir = boot_dir.join("firmware");
if boot_firmware_dir.exists() {
boot_dir = boot_firmware_dir;
}
fs::create_dir_all(&boot_dir)?;
let mounted_boot = Mounted::mount(loop_device.partition(2), &boot_dir)?;
let config_dir = TempDir::new("rugpi")?;
let config_dir_path = Utf8Path::from_path(config_dir.path()).unwrap();
let mounted_config = Mounted::mount(loop_device.partition(1), &config_dir_path)?;
let ctx = BakeCtx {
config,
mounted_boot,
mounted_root,
mounted_config,
};

run!(["tar", "-x", "-f", &task.archive, "-C", root_dir_path])?;
println!("Patching boot configuration...");
patch_boot(ctx.mounted_boot.path(), format!("PARTUUID={disk_id}-05"))?;
println!("Patching `config.txt`...");
patch_config(boot_dir.join("config.txt"))?;

match ctx.config.boot_flow {
BootFlow::Tryboot => setup_tryboot_boot_flow(&ctx)?,
BootFlow::UBoot => setup_uboot_boot_flow(&ctx)?,
}

std::fs::copy(
"/usr/share/rugpi/boot/u-boot/bin/second.scr",
ctx.mounted_boot.path().join("second.scr"),
)?;
std::fs::copy(
"/usr/share/rugpi/boot/u-boot/bin/second.scr",
ctx.mounted_boot.path().join("second.scr"),
)?;

match ctx.config.include_firmware {
IncludeFirmware::None => { /* Do not include any firmware. */ }
IncludeFirmware::Pi4 => include_pi4_firmware(ctx.mounted_config.path())?,
IncludeFirmware::Pi5 => include_pi5_firmware(ctx.mounted_config.path())?,
match ctx.config.include_firmware {
IncludeFirmware::None => { /* Do not include any firmware. */ }
IncludeFirmware::Pi4 => include_pi4_firmware(ctx.mounted_config.path())?,
IncludeFirmware::Pi5 => include_pi5_firmware(ctx.mounted_config.path())?,
}
}
// Shrink root filesystem.
run!(["resize2fs", "-M", loop_device.partition(5)])?;
run!(["dumpe2fs", "-h", loop_device.partition(5)])?;
Ok(())
}

Expand Down

0 comments on commit 58b378b

Please sign in to comment.