Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Btrfs root default with @root and @home subvolumes #286

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
657 changes: 342 additions & 315 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pbr = "1.0.2"

[dependencies]
cascade = "1.0"
concat-in-place = "1.1.0"
const_format = "0.2.22"
dirs = "3.0"
disk-types = { path = "crates/disk-types"}
distinst-bootloader = { path = "crates/bootloader" }
Expand All @@ -55,7 +57,7 @@ os-release = "0.1.0"
partition-identity = "0.2.8"
proc-mounts = "0.2.4"
rayon = "1.3.0"
sys-mount = "1.2.1"
sys-mount = "1.5.1"
tempdir = "0.3.7"
bitflags = "1.2.1"
err-derive = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion cli/src/configure/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn decrypt(disks: &mut Disks, decrypt: Option<Values>) -> Result<(),
parse_key(&values[2], &mut pass, &mut keydata)?;

disks
.decrypt_partition(device, &LvmEncryption::new(pv, pass, keydata))
.decrypt_partition(device, &mut LuksEncryption::new(pv, pass, keydata, FileSystem::Btrfs))
.map_err(|why| DistinstError::DecryptFailed { why })?;
}
}
Expand Down
11 changes: 9 additions & 2 deletions cli/src/configure/lvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ pub(crate) fn lvm(
if let Some(fs) = fs {
let fs = match fs {
PartType::Fs(fs) => fs,
PartType::Luks(encryption) => {
partition.set_encryption(encryption);
Some(FileSystem::Luks)
}
PartType::Lvm(volume_group, encryption) => {
partition.set_volume_group(volume_group, encryption);
partition.set_volume_group(volume_group);
if let Some(params) = encryption {
partition.set_encryption(params);
}
Some(FileSystem::Lvm)
}
};
Expand Down Expand Up @@ -162,7 +169,7 @@ fn parse_logical<F: FnMut(LogicalArgs) -> Result<(), DistinstError>>(
size: parse_sector(values[2])?,
fs: match parse_fs(values[3])? {
PartType::Fs(fs) => fs,
PartType::Lvm(..) => {
_ => {
unimplemented!("LUKS on LVM is unsupported");
}
},
Expand Down
15 changes: 13 additions & 2 deletions cli/src/configure/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ pub(crate) fn new(disks: &mut Disks, parts: Option<Values>) -> Result<(), Distin
let start = disk.get_sector(start);
let end = disk.get_sector(end);
let mut builder = match fs {
PartType::Luks(encryption) => {
PartitionBuilder::new(start, end, FileSystem::Luks)
.partition_type(kind)
.encryption(encryption)
}
PartType::Lvm(volume_group, encryption) => {
PartitionBuilder::new(start, end, FileSystem::Lvm)
let mut builder = PartitionBuilder::new(start, end, FileSystem::Lvm)
.partition_type(kind)
.logical_volume(volume_group, encryption)
.logical_volume(volume_group);

if let Some(params) = encryption {
builder = builder.encryption(params);
}

builder
}
PartType::Fs(fs) => PartitionBuilder::new(start, end, fs).partition_type(kind),
};
Expand Down
9 changes: 8 additions & 1 deletion cli/src/configure/reuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ pub(crate) fn reused(disks: &mut Disks, parts: Option<Values>) -> Result<(), Dis
if let Some(fs) = fs {
let fs = match fs {
PartType::Fs(fs) => fs,
PartType::Luks(encryption) => {
partition.set_encryption(encryption);
Some(FileSystem::Luks)
}
PartType::Lvm(volume_group, encryption) => {
partition.set_volume_group(volume_group, encryption);
partition.set_volume_group(volume_group);
if let Some(encryption) = encryption {
partition.set_encryption(encryption);
}
Some(FileSystem::Lvm)
}
};
Expand Down
21 changes: 17 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ enum PartType {
/// A normal partition with a standard file system
Fs(Option<FileSystem>),
/// A partition that is formatted with LVM, optionally with encryption.
Lvm(String, Option<LvmEncryption>),
Lvm(String, Option<LuksEncryption>),
Luks(LuksEncryption)
}

fn parse_key(
Expand Down Expand Up @@ -480,10 +481,22 @@ fn parse_key(
}

fn parse_fs(fs: &str) -> Result<PartType, DistinstError> {
if fs.starts_with("enc=") {
if let Some(fs) = fs.strip_prefix("luks=") {
let (mut pass, mut keydata) = (None, None);

let mut fields = fs[4..].split(',');
let mut fields = fs.split(',');
let physical_volume =
fields.next().map(|pv| pv.into()).ok_or(DistinstError::NoPhysicalVolume)?;

for field in fields {
parse_key(field, &mut pass, &mut keydata)?;
}

Ok(PartType::Luks(LuksEncryption::new(physical_volume, pass, keydata, FileSystem::Btrfs)))
} else if let Some(fs) = fs.strip_prefix("enc=") {
let (mut pass, mut keydata) = (None, None);

let mut fields = fs.split(',');
let physical_volume =
fields.next().map(|pv| pv.into()).ok_or(DistinstError::NoPhysicalVolume)?;

Expand All @@ -498,7 +511,7 @@ fn parse_fs(fs: &str) -> Result<PartType, DistinstError> {
if pass.is_none() && keydata.is_none() {
None
} else {
Some(LvmEncryption::new(physical_volume, pass, keydata))
Some(LuksEncryption::new(physical_volume, pass, keydata, FileSystem::Btrfs))
},
))
} else if fs.starts_with("lvm=") {
Expand Down
2 changes: 1 addition & 1 deletion crates/chroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = ["os", "os::unix-apis"]
edition = "2018"

[dependencies]
sys-mount = "1.2.1"
sys-mount = "1.5.1"
cascade = "1.0"
log = "0.4.8"
libc = "0.2.68"
Expand Down
2 changes: 1 addition & 1 deletion crates/disk-ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ disk-types = { path = "../disk-types" }
distinst-external-commands = { path = "../external" }
log = "0.4.8"
tempdir = "0.3.7"
sys-mount = "1.2.1"
sys-mount = "1.5.1"
libparted = "0.1.4"
rayon = "1.3.0"
smart-default = "0.6.0"
2 changes: 1 addition & 1 deletion crates/disk-ops/src/mkpart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct PartitionCreate {
impl BlockDeviceExt for PartitionCreate {
fn get_device_path(&self) -> &Path { &self.path }

fn get_mount_point(&self) -> Option<&Path> { None }
fn get_mount_point(&self) -> &[PathBuf] { &[] }
}

impl PartitionExt for PartitionCreate {
Expand Down
3 changes: 1 addition & 2 deletions crates/disk-ops/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl FormatPartitions {
info!("executing format operations");
self.0
.par_iter()
.map(|&(ref part, fs)| {
.try_for_each(|&(ref part, fs)| {
info!("formatting {} with {:?}", part.display(), fs);
mkfs(part, fs).map_err(|why| {
io::Error::new(
Expand All @@ -301,6 +301,5 @@ impl FormatPartitions {
)
})
})
.collect::<io::Result<()>>()
}
}
16 changes: 0 additions & 16 deletions crates/disk-ops/src/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,3 @@ fn ntfs_dry_run(path: &Path, size: &str) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::Other, format!("ntfsresize exited with {:?}", status)))
}
}

fn ntfs_consistency_check(path: &Path) -> io::Result<()> {
let mut consistency_check = Command::new("ntfsresize");
consistency_check.args(&["-i", "-f"]).arg(path);

info!("executing {:?}", consistency_check);
let mut child = consistency_check.stdin(Stdio::piped()).spawn()?;
child.stdin.as_mut().expect("failed to get stdin").write_all(b"y\n")?;

let status = child.wait()?;
if status.success() {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other, format!("ntfsresize exited with {:?}", status)))
}
}
2 changes: 1 addition & 1 deletion crates/disk-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = ["filesystem", "os"]
edition = "2018"

[dependencies]
sys-mount = "1.2.1"
sys-mount = "1.5.1"
tempdir = "0.3.7"
os-detect = { path = "../os-detect" }
sysfs-class = "0.1.2"
Expand Down
4 changes: 1 addition & 3 deletions crates/disk-types/src/device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::{io, fs, fmt::Debug};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use sysfs_class::{Block, SysClass};

/// Methods that all block devices share, whether they are partitions or disks.
Expand Down Expand Up @@ -48,7 +46,7 @@ pub trait BlockDeviceExt {
fn get_device_path(&self) -> &Path;

/// The mount point of this block device, if it is mounted.
fn get_mount_point(&self) -> Option<&Path> { None }
fn get_mount_point(&self) -> &[PathBuf] { &[] }

/// The name of the device, such as `sda1`.
fn get_device_name(&self) -> String {
Expand Down
16 changes: 14 additions & 2 deletions crates/disk-types/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub trait PartitionExt: BlockDeviceExt + SectorExt {
/// The sector where this partition begins on the parent block device..
fn get_sector_start(&self) -> u64;

fn encrypted_info(&self) -> Option<(std::path::PathBuf, FileSystem)> {
None
}

/// True if the partition is an ESP partition.
fn is_esp_partition(&self) -> bool {
self.get_file_system().map_or(false, |fs| {
Expand Down Expand Up @@ -80,8 +84,16 @@ pub trait PartitionExt: BlockDeviceExt + SectorExt {

/// Detects if an OS is installed to this partition, and if so, what the OS
/// is named.
fn probe_os(&self) -> Option<OS> {
self.get_file_system().and_then(|fs| detect_os_from_device(self.get_device_path(), fs))
fn probe_os(&self, subvol: Option<&str>) -> Option<OS> {
let (device_path, fs) = match self.encrypted_info() {
Some((p, f)) => (p, f),
None => (
self.get_device_path().to_path_buf(),
self.get_file_system()?
)
};

detect_os_from_device(&device_path, subvol, fs)
}

/// True if the sectors in the compared partition differs from the source.
Expand Down
4 changes: 2 additions & 2 deletions crates/disks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
license = "MIT"
keywords = ["distinst", "disk", "management", "partition"]
categories = ["filesystem", "os"]
edition = "2018"
edition = "2021"

[dependencies]
bitflags = "1.2.1"
Expand All @@ -31,6 +31,6 @@ partition-identity = "0.2.8"
proc-mounts = "0.2.4"
rand = "0.7"
rayon = "1.3.0"
sys-mount = "1.2.1"
sys-mount = "1.5.1"
sysfs-class = "0.1.2"
tempdir = "0.3.7"
Loading