Skip to content

Commit

Permalink
install: Fix installation to loopback (and probably NVMe)
Browse files Browse the repository at this point in the history
Formatting devices by concatenation was a noob thing to do.

Closes: #115
  • Loading branch information
cgwalters committed Oct 13, 2023
1 parent c9f224c commit f99e601
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ pub(crate) fn install_create_rootfs(
anyhow::bail!("Unsupported architecture: {}", std::env::consts::ARCH);
}

let espdev = if super::ARCH_USES_EFI {
let esp_partno = if super::ARCH_USES_EFI {
sgdisk_partition(
&mut sgdisk.cmd,
EFIPN,
format!("0:+{EFIPN_SIZE_MB}M"),
"EFI-SYSTEM",
Some("C12A7328-F81F-11D2-BA4B-00A0C93EC93B"),
);
Some(format!("{device}{EFIPN}"))
Some(EFIPN)
} else {
None
};
Expand Down Expand Up @@ -278,7 +278,20 @@ pub(crate) fn install_create_rootfs(

crate::blockdev::udev_settle()?;

let base_rootdev = format!("{device}{ROOTPN}");
// Now inspect the partitioned device again so we can find the names of the child devices.
let device_partitions = crate::blockdev::list_dev(&device)?
.children
.ok_or_else(|| anyhow::anyhow!("Failed to find children after partitioning"))?;
// Given a partition number, return the path to its device.
let findpart = |idx: u32| -> Result<String> {
// checked_sub is here because our partition numbers start at 1, but the vec starts at 0
let dev = device_partitions
.get(idx.checked_sub(1).unwrap() as usize)
.ok_or_else(|| anyhow::anyhow!("Missing partition for index {idx}"))?;
Ok(format!("/dev/{}", dev.name.as_str()))
};

let base_rootdev = findpart(ROOTPN)?;
let (rootdev, root_blockdev_kargs) = match opts.block_setup {
BlockSetup::Direct => (base_rootdev, None),
BlockSetup::Tpm2Luks => {
Expand Down Expand Up @@ -318,7 +331,7 @@ pub(crate) fn install_create_rootfs(
let bootfs_type = Filesystem::Ext4;

// Initialize the /boot filesystem
let bootdev = &format!("{device}{BOOTPN}");
let bootdev = &findpart(BOOTPN)?;
let boot_uuid = mkfs(bootdev, bootfs_type, Some("boot"), []).context("Initializing /boot")?;

// Initialize rootfs
Expand Down Expand Up @@ -349,7 +362,8 @@ pub(crate) fn install_create_rootfs(
state.lsm_label(&bootfs, "/boot".into(), false)?;

// Create the EFI system partition, if applicable
if let Some(espdev) = espdev {
if let Some(esp_partno) = esp_partno {
let espdev = &findpart(esp_partno)?;
Task::new("Creating ESP filesystem", "mkfs.fat")
.args([espdev.as_str(), "-n", "EFI-SYSTEM"])
.quiet_output()
Expand Down

0 comments on commit f99e601

Please sign in to comment.