Skip to content

Commit 78c10ef

Browse files
authored
Merge pull request #607 from cgwalters/drop-separate-dev
install/baseline: Drop separate /dev mount
2 parents 508f8c4 + 93974fc commit 78c10ef

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

lib/src/blockdev.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub(crate) struct Device {
2828
pub(crate) label: Option<String>,
2929
pub(crate) fstype: Option<String>,
3030
pub(crate) children: Option<Vec<Device>>,
31+
pub(crate) size: Option<String>,
3132
}
3233

3334
impl Device {
@@ -53,7 +54,7 @@ pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
5354

5455
fn list_impl(dev: Option<&Utf8Path>) -> Result<Vec<Device>> {
5556
let o = Command::new("lsblk")
56-
.args(["-J", "-o", "NAME,SERIAL,MODEL,LABEL,FSTYPE"])
57+
.args(["-J", "-o", "NAME,SERIAL,MODEL,LABEL,FSTYPE,SIZE"])
5758
.args(dev)
5859
.output()?;
5960
if !o.status.success() {

lib/src/install/baseline.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ fn mkfs<'a>(
126126
label: &str,
127127
opts: impl IntoIterator<Item = &'a str>,
128128
) -> Result<uuid::Uuid> {
129+
let devinfo = crate::blockdev::list_dev(dev.into())?;
130+
let size = devinfo.size.as_deref().unwrap_or("(unknown)");
129131
let u = uuid::Uuid::new_v4();
130132
let mut t = Task::new(
131-
&format!("Creating {label} filesystem ({fs})"),
133+
&format!("Creating {label} filesystem ({fs}) on device {dev} (size={size})"),
132134
format!("mkfs.{fs}"),
133135
);
134136
match fs {
@@ -170,6 +172,8 @@ pub(crate) fn install_create_rootfs(
170172
// Verify that the target is empty (if not already wiped in particular, but it's
171173
// also good to verify that the wipe worked)
172174
let device = crate::blockdev::list_dev(&opts.device)?;
175+
// Canonicalize devpath
176+
let devpath: Utf8PathBuf = device.path().into();
173177

174178
// Handle wiping any existing data
175179
if opts.wipe {
@@ -193,20 +197,6 @@ pub(crate) fn install_create_rootfs(
193197
if mntdir.exists() {
194198
std::fs::remove_dir_all(&mntdir)?;
195199
}
196-
let devdir = mntdir.join("dev");
197-
std::fs::create_dir_all(&devdir)?;
198-
Task::new("Mounting devtmpfs", "mount")
199-
.args(["devtmpfs", "-t", "devtmpfs", devdir.as_str()])
200-
.quiet()
201-
.run()?;
202-
203-
// Now at this point, our /dev is a stale snapshot because we don't have udev running.
204-
// So from hereon after, we prefix devices with our temporary devtmpfs mount.
205-
let reldevice = opts
206-
.device
207-
.strip_prefix("/dev/")
208-
.context("Absolute device path in /dev/ required")?;
209-
let device = devdir.join(reldevice);
210200

211201
// Use the install configuration to find the block setup, if we have one
212202
let block_setup = if let Some(config) = state.install_config.as_ref() {
@@ -245,7 +235,7 @@ pub(crate) fn install_create_rootfs(
245235
// sgdisk is too verbose
246236
sgdisk.cmd.stdout(Stdio::null());
247237
sgdisk.cmd.arg("-Z");
248-
sgdisk.cmd.arg(&device);
238+
sgdisk.cmd.arg(device.path());
249239
sgdisk.cmd.args(["-U", "R"]);
250240
#[allow(unused_assignments)]
251241
if cfg!(target_arch = "x86_64") {
@@ -316,27 +306,28 @@ pub(crate) fn install_create_rootfs(
316306
{
317307
let mut f = std::fs::OpenOptions::new()
318308
.write(true)
319-
.open(&device)
320-
.with_context(|| format!("opening {device}"))?;
309+
.open(&devpath)
310+
.with_context(|| format!("opening {devpath}"))?;
321311
crate::blockdev::reread_partition_table(&mut f, true)
322312
.context("Rereading partition table")?;
323313
}
324314

315+
// Full udev sync; it'd obviously be better to await just the devices
316+
// we're targeting, but this is a simple coarse hammer.
325317
crate::blockdev::udev_settle()?;
326318

327319
// Now inspect the partitioned device again so we can find the names of the child devices.
328-
let device_partitions = crate::blockdev::list_dev(&device)?
320+
let device_partitions = crate::blockdev::list_dev(&devpath)?
329321
.children
330322
.ok_or_else(|| anyhow::anyhow!("Failed to find children after partitioning"))?;
331323
// Given a partition number, return the path to its device.
332324
let findpart = |idx: u32| -> Result<String> {
333325
// checked_sub is here because our partition numbers start at 1, but the vec starts at 0
334-
let devname = device_partitions
326+
let devpath = device_partitions
335327
.get(idx.checked_sub(1).unwrap() as usize)
336328
.ok_or_else(|| anyhow::anyhow!("Missing partition for index {idx}"))?
337-
.name
338-
.as_str();
339-
Ok(devdir.join(devname).to_string())
329+
.path();
330+
Ok(devpath)
340331
};
341332

342333
let base_rootdev = findpart(rootpn)?;
@@ -440,7 +431,7 @@ pub(crate) fn install_create_rootfs(
440431
};
441432
Ok(RootSetup {
442433
luks_device,
443-
device,
434+
device: devpath,
444435
rootfs,
445436
rootfs_fd,
446437
rootfs_uuid: Some(root_uuid.to_string()),

0 commit comments

Comments
 (0)