diff --git a/build/lib/scripts/prune-images b/build/lib/scripts/prune-images index 1203d2377..d32c14bf5 100755 --- a/build/lib/scripts/prune-images +++ b/build/lib/scripts/prune-images @@ -29,10 +29,13 @@ if [ -z "$needed" ]; then exit 1 fi +MARGIN=${MARGIN:-1073741824} +target=$((needed + MARGIN)) + if [ -h /media/startos/config/current.rootfs ] && [ -e /media/startos/config/current.rootfs ]; then echo 'Pruning...' current="$(readlink -f /media/startos/config/current.rootfs)" - while [[ "$(df -B1 --output=avail --sync /media/startos/images | tail -n1)" -lt "$needed" ]]; do + while [[ "$(df -B1 --output=avail --sync /media/startos/images | tail -n1)" -lt "$target" ]]; do to_prune="$(ls -t1 /media/startos/images/*.rootfs /media/startos/images/*.squashfs 2> /dev/null | grep -v "$current" | tail -n1)" if [ -e "$to_prune" ]; then echo " Pruning $to_prune" diff --git a/core/src/disk/util.rs b/core/src/disk/util.rs index d832fee5d..b46f8f31a 100644 --- a/core/src/disk/util.rs +++ b/core/src/disk/util.rs @@ -259,6 +259,31 @@ pub async fn recovery_info( Ok(res) } +/// Returns the canonical path of the source device for a given mount point, +/// or None if the mount point doesn't exist or isn't mounted. +#[instrument(skip_all)] +pub async fn get_mount_source(mountpoint: impl AsRef) -> Result, Error> { + let mounts_content = tokio::fs::read_to_string("/proc/mounts") + .await + .with_ctx(|_| (crate::ErrorKind::Filesystem, "/proc/mounts"))?; + + let mountpoint = mountpoint.as_ref(); + for line in mounts_content.lines() { + let mut parts = line.split_whitespace(); + let source = parts.next(); + let mount = parts.next(); + if let (Some(source), Some(mount)) = (source, mount) { + if Path::new(mount) == mountpoint { + // Try to canonicalize the source path + if let Ok(canonical) = tokio::fs::canonicalize(source).await { + return Ok(Some(canonical)); + } + } + } + } + Ok(None) +} + #[instrument(skip_all)] pub async fn list(os: &OsPartitionInfo) -> Result, Error> { struct DiskIndex { diff --git a/core/src/os_install/gpt.rs b/core/src/os_install/gpt.rs index ff17bb620..2862f88dd 100644 --- a/core/src/os_install/gpt.rs +++ b/core/src/os_install/gpt.rs @@ -93,14 +93,14 @@ pub async fn partition( }; gpt.add_partition( "boot", - 1024 * 1024 * 1024, + 2 * 1024 * 1024 * 1024, gpt::partition_types::LINUX_FS, 0, None, )?; gpt.add_partition( "root", - 15 * 1024 * 1024 * 1024, + 14 * 1024 * 1024 * 1024, match crate::ARCH { "x86_64" => gpt::partition_types::LINUX_ROOT_X64, "aarch64" => gpt::partition_types::LINUX_ROOT_ARM_64, diff --git a/core/src/os_install/mbr.rs b/core/src/os_install/mbr.rs index ea68b4695..d643cb7ef 100644 --- a/core/src/os_install/mbr.rs +++ b/core/src/os_install/mbr.rs @@ -64,8 +64,8 @@ pub async fn partition( }; // MBR partition layout: - // Partition 1 (boot): starts at 2048, ends at 2099200 (sectors: 2097152 = 1GB) - // Partition 2 (root): starts at 2099200, ends at 33556480 (sectors: 31457280 = 15GB) + // Partition 1 (boot): starts at 2048, ends at 4196352 (sectors: 4194304 = 2GB) + // Partition 2 (root): starts at 4196352, ends at 33556480 (sectors: 29360128 = 14GB) // OS partitions end at sector 33556480 let os_partitions_end_sector: u32 = 33556480; @@ -99,15 +99,15 @@ pub async fn partition( sys: 0x0b, last_chs: CHS::empty(), starting_lba: 2048, - sectors: 2099200 - 2048, + sectors: 4196352 - 2048, }; mbr[2] = MBRPartitionEntry { boot: 0, first_chs: CHS::empty(), sys: 0x83, last_chs: CHS::empty(), - starting_lba: 2099200, - sectors: 33556480 - 2099200, + starting_lba: 4196352, + sectors: 33556480 - 4196352, }; let data_part = if let Some((starting_lba, part_sectors, path)) = protected_partition_info { diff --git a/core/src/setup.rs b/core/src/setup.rs index 5b9770df8..5317e3699 100644 --- a/core/src/setup.rs +++ b/core/src/setup.rs @@ -90,13 +90,24 @@ pub fn disk() -> ParentHandler { ) } +const LIVE_MEDIUM_PATH: &str = "/run/live/medium"; + pub async fn list_disks(ctx: SetupContext) -> Result, Error> { - crate::disk::util::list( + let mut disks = crate::disk::util::list( &ctx.config .peek(|c| c.os_partitions.clone()) .unwrap_or_default(), ) - .await + .await?; + + // Filter out the disk containing the live medium (installer USB) + if let Ok(Some(live_medium_source)) = + crate::disk::util::get_mount_source(LIVE_MEDIUM_PATH).await + { + disks.retain(|disk| disk.logicalname != live_medium_source); + } + + Ok(disks) } #[instrument(skip_all)]