mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
purge all swap logic
This commit is contained in:
committed by
Aiden McClelland
parent
bb51512f52
commit
6478ecf270
@@ -12,7 +12,6 @@ use crate::{Error, ResultExt};
|
|||||||
pub const PASSWORD_PATH: &'static str = "/etc/embassy/password";
|
pub const PASSWORD_PATH: &'static str = "/etc/embassy/password";
|
||||||
pub const DEFAULT_PASSWORD: &'static str = "password";
|
pub const DEFAULT_PASSWORD: &'static str = "password";
|
||||||
pub const MAIN_FS_SIZE: FsSize = FsSize::Gigabytes(8);
|
pub const MAIN_FS_SIZE: FsSize = FsSize::Gigabytes(8);
|
||||||
pub const SWAP_SIZE: FsSize = FsSize::Gigabytes(8);
|
|
||||||
|
|
||||||
// TODO: use IncorrectDisk / DiskNotAvailable / DiskCorrupted
|
// TODO: use IncorrectDisk / DiskNotAvailable / DiskCorrupted
|
||||||
|
|
||||||
@@ -89,7 +88,6 @@ pub async fn create_fs<P: AsRef<Path>>(
|
|||||||
datadir: P,
|
datadir: P,
|
||||||
name: &str,
|
name: &str,
|
||||||
size: FsSize,
|
size: FsSize,
|
||||||
swap: bool,
|
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
tokio::fs::write(PASSWORD_PATH, password)
|
tokio::fs::write(PASSWORD_PATH, password)
|
||||||
@@ -123,27 +121,15 @@ pub async fn create_fs<P: AsRef<Path>>(
|
|||||||
.arg(format!("{}_{}", guid, name))
|
.arg(format!("{}_{}", guid, name))
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
.await?;
|
.await?;
|
||||||
if swap {
|
Command::new("mkfs.ext4")
|
||||||
Command::new("mkswap")
|
.arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
||||||
.arg("-f")
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
.arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
|
||||||
.await?;
|
|
||||||
// Command::new("swapon")
|
|
||||||
// .arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
|
||||||
// .invoke(crate::ErrorKind::DiskManagement)
|
|
||||||
// .await?;
|
|
||||||
} else {
|
|
||||||
Command::new("mkfs.ext4")
|
|
||||||
.arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
|
||||||
.await?;
|
|
||||||
mount(
|
|
||||||
Path::new("/dev/mapper").join(format!("{}_{}", guid, name)),
|
|
||||||
datadir.as_ref().join(name),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
mount(
|
||||||
|
Path::new("/dev/mapper").join(format!("{}_{}", guid, name)),
|
||||||
|
datadir.as_ref().join(name),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
tokio::fs::remove_file(PASSWORD_PATH)
|
tokio::fs::remove_file(PASSWORD_PATH)
|
||||||
.await
|
.await
|
||||||
.with_ctx(|_| (crate::ErrorKind::Filesystem, PASSWORD_PATH))?;
|
.with_ctx(|_| (crate::ErrorKind::Filesystem, PASSWORD_PATH))?;
|
||||||
@@ -156,14 +142,12 @@ pub async fn create_all_fs<P: AsRef<Path>>(
|
|||||||
datadir: P,
|
datadir: P,
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
create_fs(guid, &datadir, "main", MAIN_FS_SIZE, false, password).await?;
|
create_fs(guid, &datadir, "main", MAIN_FS_SIZE, password).await?;
|
||||||
create_fs(guid, &datadir, "swap", SWAP_SIZE, true, password).await?;
|
|
||||||
create_fs(
|
create_fs(
|
||||||
guid,
|
guid,
|
||||||
&datadir,
|
&datadir,
|
||||||
"package-data",
|
"package-data",
|
||||||
FsSize::FreePercentage(100),
|
FsSize::FreePercentage(100),
|
||||||
false,
|
|
||||||
password,
|
password,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -171,20 +155,8 @@ pub async fn create_all_fs<P: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(datadir))]
|
#[instrument(skip(datadir))]
|
||||||
pub async fn unmount_fs<P: AsRef<Path>>(
|
pub async fn unmount_fs<P: AsRef<Path>>(guid: &str, datadir: P, name: &str) -> Result<(), Error> {
|
||||||
guid: &str,
|
unmount(datadir.as_ref().join(name)).await?;
|
||||||
datadir: P,
|
|
||||||
name: &str,
|
|
||||||
swap: bool,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
if swap {
|
|
||||||
// Command::new("swapoff")
|
|
||||||
// .arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
|
||||||
// .invoke(crate::ErrorKind::DiskManagement)
|
|
||||||
// .await?;
|
|
||||||
} else {
|
|
||||||
unmount(datadir.as_ref().join(name)).await?;
|
|
||||||
}
|
|
||||||
Command::new("cryptsetup")
|
Command::new("cryptsetup")
|
||||||
.arg("-q")
|
.arg("-q")
|
||||||
.arg("luksClose")
|
.arg("luksClose")
|
||||||
@@ -197,9 +169,8 @@ pub async fn unmount_fs<P: AsRef<Path>>(
|
|||||||
|
|
||||||
#[instrument(skip(datadir))]
|
#[instrument(skip(datadir))]
|
||||||
pub async fn unmount_all_fs<P: AsRef<Path>>(guid: &str, datadir: P) -> Result<(), Error> {
|
pub async fn unmount_all_fs<P: AsRef<Path>>(guid: &str, datadir: P) -> Result<(), Error> {
|
||||||
unmount_fs(guid, &datadir, "main", false).await?;
|
unmount_fs(guid, &datadir, "main").await?;
|
||||||
unmount_fs(guid, &datadir, "swap", true).await?;
|
unmount_fs(guid, &datadir, "package-data").await?;
|
||||||
unmount_fs(guid, &datadir, "package-data", false).await?;
|
|
||||||
Command::new("dmsetup")
|
Command::new("dmsetup")
|
||||||
.arg("remove_all") // TODO: find a higher finesse way to do this for portability reasons
|
.arg("remove_all") // TODO: find a higher finesse way to do this for portability reasons
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
@@ -253,7 +224,6 @@ pub async fn mount_fs<P: AsRef<Path>>(
|
|||||||
guid: &str,
|
guid: &str,
|
||||||
datadir: P,
|
datadir: P,
|
||||||
name: &str,
|
name: &str,
|
||||||
swap: bool,
|
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
tokio::fs::write(PASSWORD_PATH, password)
|
tokio::fs::write(PASSWORD_PATH, password)
|
||||||
@@ -268,18 +238,11 @@ pub async fn mount_fs<P: AsRef<Path>>(
|
|||||||
.arg(format!("{}_{}", guid, name))
|
.arg(format!("{}_{}", guid, name))
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
.await?;
|
.await?;
|
||||||
if swap {
|
mount(
|
||||||
// Command::new("swapon")
|
Path::new("/dev/mapper").join(format!("{}_{}", guid, name)),
|
||||||
// .arg(Path::new("/dev/mapper").join(format!("{}_{}", guid, name)))
|
datadir.as_ref().join(name),
|
||||||
// .invoke(crate::ErrorKind::DiskManagement)
|
)
|
||||||
// .await?;
|
.await?;
|
||||||
} else {
|
|
||||||
mount(
|
|
||||||
Path::new("/dev/mapper").join(format!("{}_{}", guid, name)),
|
|
||||||
datadir.as_ref().join(name),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
tokio::fs::remove_file(PASSWORD_PATH)
|
tokio::fs::remove_file(PASSWORD_PATH)
|
||||||
.await
|
.await
|
||||||
@@ -294,8 +257,7 @@ pub async fn mount_all_fs<P: AsRef<Path>>(
|
|||||||
datadir: P,
|
datadir: P,
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
mount_fs(guid, &datadir, "main", false, password).await?;
|
mount_fs(guid, &datadir, "main", password).await?;
|
||||||
mount_fs(guid, &datadir, "swap", true, password).await?;
|
mount_fs(guid, &datadir, "package-data", password).await?;
|
||||||
mount_fs(guid, &datadir, "package-data", false, password).await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user