mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
allow setup of disk previously used with lvm
This commit is contained in:
committed by
Aiden McClelland
parent
e4a40ac32d
commit
44324b7127
@@ -1,4 +1,5 @@
|
|||||||
use std::path::Path;
|
use std::collections::BTreeMap;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
@@ -17,6 +18,7 @@ pub const SWAP_SIZE: FsSize = FsSize::Gigabytes(8);
|
|||||||
#[instrument(skip(disks, datadir, password))]
|
#[instrument(skip(disks, datadir, password))]
|
||||||
pub async fn create<I, P>(
|
pub async fn create<I, P>(
|
||||||
disks: &I,
|
disks: &I,
|
||||||
|
pvscan: &BTreeMap<PathBuf, Option<String>>,
|
||||||
datadir: impl AsRef<Path>,
|
datadir: impl AsRef<Path>,
|
||||||
password: &str,
|
password: &str,
|
||||||
) -> Result<String, Error>
|
) -> Result<String, Error>
|
||||||
@@ -24,20 +26,34 @@ where
|
|||||||
for<'a> &'a I: IntoIterator<Item = &'a P>,
|
for<'a> &'a I: IntoIterator<Item = &'a P>,
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
let guid = create_pool(disks).await?;
|
let guid = create_pool(disks, pvscan).await?;
|
||||||
create_all_fs(&guid, &datadir, password).await?;
|
create_all_fs(&guid, &datadir, password).await?;
|
||||||
export(&guid, datadir).await?;
|
export(&guid, datadir).await?;
|
||||||
Ok(guid)
|
Ok(guid)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(disks))]
|
#[instrument(skip(disks))]
|
||||||
pub async fn create_pool<I, P>(disks: &I) -> Result<String, Error>
|
pub async fn create_pool<I, P>(
|
||||||
|
disks: &I,
|
||||||
|
pvscan: &BTreeMap<PathBuf, Option<String>>,
|
||||||
|
) -> Result<String, Error>
|
||||||
where
|
where
|
||||||
for<'a> &'a I: IntoIterator<Item = &'a P>,
|
for<'a> &'a I: IntoIterator<Item = &'a P>,
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
|
Command::new("dmsetup")
|
||||||
|
.arg("remove_all") // TODO: find a higher finesse way to do this for portability reasons
|
||||||
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
|
.await?;
|
||||||
for disk in disks {
|
for disk in disks {
|
||||||
tokio::fs::write(disk.as_ref(), &[0; 2048]).await?; // wipe partition table and lvm2 metadata
|
if pvscan.contains_key(disk.as_ref()) {
|
||||||
|
Command::new("pvremove")
|
||||||
|
.arg("-yff")
|
||||||
|
.arg(disk.as_ref())
|
||||||
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
tokio::fs::write(disk.as_ref(), &[0; 2048]).await?; // wipe partition table
|
||||||
Command::new("pvcreate")
|
Command::new("pvcreate")
|
||||||
.arg("-yff")
|
.arg("-yff")
|
||||||
.arg(disk.as_ref())
|
.arg(disk.as_ref())
|
||||||
|
|||||||
@@ -153,13 +153,17 @@ pub async fn get_used<P: AsRef<Path>>(path: P) -> Result<usize, Error> {
|
|||||||
.parse()?)
|
.parse()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
pub async fn pvscan() -> Result<BTreeMap<PathBuf, Option<String>>, Error> {
|
||||||
pub async fn list() -> Result<Vec<DiskInfo>, Error> {
|
|
||||||
let pvscan_out = Command::new("pvscan")
|
let pvscan_out = Command::new("pvscan")
|
||||||
.invoke(crate::ErrorKind::DiskManagement)
|
.invoke(crate::ErrorKind::DiskManagement)
|
||||||
.await?;
|
.await?;
|
||||||
let pvscan_out_str = std::str::from_utf8(&pvscan_out)?;
|
let pvscan_out_str = std::str::from_utf8(&pvscan_out)?;
|
||||||
let disk_guids = parse_pvscan_output(pvscan_out_str);
|
Ok(parse_pvscan_output(pvscan_out_str))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
pub async fn list() -> Result<Vec<DiskInfo>, Error> {
|
||||||
|
let disk_guids = pvscan().await?;
|
||||||
let disks = tokio_stream::wrappers::ReadDirStream::new(
|
let disks = tokio_stream::wrappers::ReadDirStream::new(
|
||||||
tokio::fs::read_dir(DISK_PATH)
|
tokio::fs::read_dir(DISK_PATH)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use tracing::instrument;
|
|||||||
use crate::context::SetupContext;
|
use crate::context::SetupContext;
|
||||||
use crate::db::model::RecoveredPackageInfo;
|
use crate::db::model::RecoveredPackageInfo;
|
||||||
use crate::disk::main::DEFAULT_PASSWORD;
|
use crate::disk::main::DEFAULT_PASSWORD;
|
||||||
use crate::disk::util::{DiskInfo, PartitionInfo, TmpMountGuard};
|
use crate::disk::util::{pvscan, DiskInfo, PartitionInfo, TmpMountGuard};
|
||||||
use crate::id::Id;
|
use crate::id::Id;
|
||||||
use crate::install::PKG_PUBLIC_DIR;
|
use crate::install::PKG_PUBLIC_DIR;
|
||||||
use crate::net::ssl::SslManager;
|
use crate::net::ssl::SslManager;
|
||||||
@@ -144,8 +144,13 @@ pub async fn execute_inner(
|
|||||||
crate::ErrorKind::InvalidRequest,
|
crate::ErrorKind::InvalidRequest,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let guid =
|
let guid = crate::disk::main::create(
|
||||||
crate::disk::main::create(&[embassy_logicalname], &ctx.datadir, DEFAULT_PASSWORD).await?;
|
&[embassy_logicalname],
|
||||||
|
&pvscan().await?,
|
||||||
|
&ctx.datadir,
|
||||||
|
DEFAULT_PASSWORD,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
crate::disk::main::import(&guid, &ctx.datadir, DEFAULT_PASSWORD).await?;
|
crate::disk::main::import(&guid, &ctx.datadir, DEFAULT_PASSWORD).await?;
|
||||||
let password = argon2::hash_encoded(
|
let password = argon2::hash_encoded(
|
||||||
embassy_password.as_bytes(),
|
embassy_password.as_bytes(),
|
||||||
|
|||||||
Reference in New Issue
Block a user