fix kernel encryption
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-01-05 04:57:26 +01:00
parent 40a1498c6f
commit c689ee87d4
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 35 additions and 7 deletions

View file

@ -15,9 +15,16 @@ pub fn setup_mkinitcpio(conf: &DriveConfig) {
);
// Set kernel cmdline
// TODO : Encryption support
std::fs::create_dir_all("/mnt/etc/kernel").unwrap();
if conf.encryption.is_some() {
let block_uuid = find_uuid_by_dev(&conf.root).unwrap();
std::fs::write("/mnt/etc/kernel/cmdline",
format!("rd.luks.options=timeout=30s rd.luks.name={block_uuid}=root root=/dev/mapper/root rw")
).unwrap();
} else {
std::fs::write("/mnt/etc/kernel/cmdline", format!("root={}", conf.root)).unwrap();
}
// TODO : more configs
print_status("Writing /etc/mkinitcpio.conf");
@ -29,3 +36,29 @@ pub fn setup_mkinitcpio(conf: &DriveConfig) {
arch_chroot(&["mkinitcpio", "--allpresets"], None, true);
}
fn find_uuid_by_dev(dev: &str) -> Option<String> {
let dir_path = "/dev/disk/by-uuid";
if let Ok(entries) = std::fs::read_dir(dir_path) {
for entry in entries.flatten() {
let path = entry.path();
if let Ok(target) = std::fs::read_link(&path) {
let resolved_path = path.parent().unwrap().join(&target);
if resolved_path
.to_string_lossy()
.ends_with(dev.split("/").last().unwrap())
{
// Match -> Return found Block Device UUID
if let Some(filename) = path.file_name() {
return Some(filename.to_string_lossy().to_string());
}
}
}
}
}
None
}

View file

@ -1,6 +1,3 @@
// TODO : Setup ssh (config + authorized_keys)
// TODO : Setup virtualization
// TODO : Setup docker
// TODO : Autojoin docker swarm
// TODO : Autojoin teleport
@ -101,8 +98,6 @@ pub fn install(conf: InstallConfig) {
install_pkgs(&pkg::DESKTOP_PKG);
print_status("Enable SDDM");
// TODO : Setup KDE Keyboard Layout
std::os::unix::fs::symlink(
"/usr/lib/systemd/system/sddm.service",
"/mnt/etc/systemd/system/display-manager.service",