omit live medium from disk list and better space management

This commit is contained in:
Aiden McClelland
2026-01-21 13:33:52 -07:00
parent 50540e4847
commit 3333416331
5 changed files with 49 additions and 10 deletions

View File

@@ -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"

View File

@@ -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<Path>) -> Result<Option<PathBuf>, 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<Vec<DiskInfo>, Error> {
struct DiskIndex {

View File

@@ -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,

View File

@@ -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 {

View File

@@ -90,13 +90,24 @@ pub fn disk<C: Context>() -> ParentHandler<C> {
)
}
const LIVE_MEDIUM_PATH: &str = "/run/live/medium";
pub async fn list_disks(ctx: SetupContext) -> Result<Vec<DiskInfo>, 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)]