Skip to content

Commit

Permalink
nasty GRUB generation hack
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Oct 10, 2023
1 parent 790c5b7 commit aa36fec
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,47 @@ impl Bootloader {
}
}
drop(f); // write and flush changes
let (vmlinuz, initramfs) = self.cp_vmlinuz_initramfs(chroot, &imgd)?;
let volid = manifest.get_volid();

fs::create_dir_all(imgd.join("boot/grub2"))?;
let grub_config = imgd.join("boot/grub2/grub.cfg");

let distro_name = &manifest.distro.as_ref().map_or("Linux", |s| s);
let config_template = r#"
set default="1"
function load_video {
insmod all_video
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
insmod chain
set timeout=60
"#;
let template_2 = format!(
r#"
search --no-floppy --set=root --label '{volid}'
menuentry '{distro_name}' --class ultramarine --class gnu-linux --class gnu --class os {{
linuxefi /boot/{vmlinuz} root=live:LABEL={volid} rd.live.image enforcing=0 {cmd}
initrdefi /boot/{initramfs}
}}
"#
);

let mut f = std::fs::File::create(&grub_config)?;

Check failure on line 204 in src/builder.rs

View workflow job for this annotation

GitHub Actions / Clippy

the borrowed expression implements the required traits

f.write_all(config_template.as_bytes())?;
f.write_all(template_2.as_bytes())?;

f.flush()?;


crate::chroot_run_cmd!(chroot, grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1)?;
// crate::chroot_run_cmd!(chroot, grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1)?;
cmd_lib::run_cmd!(cp -r $chroot/boot $imgd/)?; // too lazy to cp one by one
Ok(())
}
Expand Down

0 comments on commit aa36fec

Please sign in to comment.