From 8ec6f87a22616d615c3657c50193287242dae710 Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Wed, 21 Aug 2019 00:26:03 -0400 Subject: [PATCH] Install bzImage files with kernel version suffix --- citadel-tool/src/boot/live.rs | 18 ++++++++++++++---- citadel-tool/src/install/installer.rs | 26 +++++++++++++++++--------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/citadel-tool/src/boot/live.rs b/citadel-tool/src/boot/live.rs index 29a26bb..daad80b 100644 --- a/citadel-tool/src/boot/live.rs +++ b/citadel-tool/src/boot/live.rs @@ -5,7 +5,7 @@ use std::fs; use std::thread::{self,JoinHandle}; use std::time::{self,Instant}; -use libcitadel::Result; +use libcitadel::{Result, UtsName}; use libcitadel::ResourceImage; use crate::boot::disks; use crate::boot::rootfs::setup_rootfs_resource; @@ -47,7 +47,7 @@ fn try_copy_artifacts() -> Result { deploy_artifacts()?; return Ok(true); } - for part in disks::DiskPartition::boot_partitions()? { + for part in disks::DiskPartition::boot_partitions(false)? { part.mount("/boot")?; if rootfs_image.exists() { @@ -60,6 +60,12 @@ fn try_copy_artifacts() -> Result { Ok(false) } +fn kernel_version() -> String { + let utsname = UtsName::uname(); + let v = utsname.release().split('-').collect::>(); + v[0].to_string() +} + fn deploy_artifacts() -> Result<()> { let run_images = Path::new(IMAGE_DIRECTORY); if !run_images.exists() { @@ -72,8 +78,12 @@ fn deploy_artifacts() -> Result<()> { println!("Copying {:?} from /boot/images to /run/citadel/images", entry.file_name()); fs::copy(entry.path(), run_images.join(entry.file_name()))?; } - println!("Copying bzImage to /run/citadel/images"); - fs::copy("/boot/bzImage", "/run/citadel/images/bzImage")?; + + let kv = kernel_version(); + println!("Copying bzImage-{} to /run/citadel/images", kv); + let from = format!("/boot/bzImage-{}", kv); + let to = format!("/run/citadel/images/bzImage-{}", kv); + fs::copy(from, to)?; println!("Copying bootx64.efi to /run/citadel/images"); fs::copy("/boot/EFI/BOOT/bootx64.efi", "/run/citadel/images/bootx64.efi")?; diff --git a/citadel-tool/src/install/installer.rs b/citadel-tool/src/install/installer.rs index a5fcb2e..d648ff5 100644 --- a/citadel-tool/src/install/installer.rs +++ b/citadel-tool/src/install/installer.rs @@ -92,8 +92,8 @@ timeout 5 "; const BOOT_CONF: &str = "\ -title Subgraph OS (Citadel) -linux /bzImage +title Subgraph OS (Citadel $KERNEL_VERSION) +linux /bzImage-$KERNEL_VERSION options root=/dev/mapper/rootfs $KERNEL_CMDLINE "; @@ -176,8 +176,9 @@ impl Installer { pub fn verify(&self) -> Result<()> { let kernel_img = self.kernel_imagename(); + let bzimage = format!("bzImage-{}", self.kernel_version()); let artifacts = vec![ - "bootx64.efi", "bzImage", + "bootx64.efi", bzimage.as_str(), kernel_img.as_str(), EXTRA_IMAGE_NAME, ]; @@ -290,11 +291,15 @@ impl Installer { self.info("Writing /boot/loader/loader.conf")?; fs::write(format!("{}/loader/loader.conf", INSTALL_MOUNT), LOADER_CONF)?; + let kernel_version = self.kernel_version(); self.info("Writing /boot/entries/boot.conf")?; - fs::write(format!("{}/loader/entries/boot.conf", INSTALL_MOUNT), - BOOT_CONF.replace("$KERNEL_CMDLINE", KERNEL_CMDLINE))?; + fs::write(format!("{}/loader/entries/boot.conf", INSTALL_MOUNT), BOOT_CONF + .replace("$KERNEL_CMDLINE", KERNEL_CMDLINE) + .replace("$KERNEL_VERSION", &kernel_version) + )?; - self.copy_artifact("bzImage", INSTALL_MOUNT)?; + let kernel_bzimage = format!("bzImage-{}", kernel_version); + self.copy_artifact(&kernel_bzimage, INSTALL_MOUNT)?; self.copy_artifact("bootx64.efi", format!("{}/EFI/BOOT", INSTALL_MOUNT))?; if self.install_syslinux { @@ -306,7 +311,6 @@ impl Installer { if self.install_syslinux { self.setup_syslinux_post_umount()?; } - Ok(()) } @@ -488,10 +492,14 @@ impl Installer { } } - fn kernel_imagename(&self) -> String { + fn kernel_version(&self) -> String { let utsname = UtsName::uname(); let v = utsname.release().split('-').collect::>(); - format!("citadel-kernel-{}.img", v[0]) + v[0].to_string() + } + + fn kernel_imagename(&self) -> String { + format!("citadel-kernel-{}.img", self.kernel_version()) } fn target_partition(&self, num: usize) -> String {