Skip to content

Commit 01a6fae

Browse files
committed
install/baseline: Drop separate /dev mount
Now that we hard require the host's `/dev`, let's drop our duplicate `devtmpfs` copy. My main motivation here is I wanted to add some other debugging and trying to invoke e.g. `lsblk` on our temporary copy doesn't work. With the combination of the host `/dev` plus our invocation of udev settling, we shouldn't hit races. Signed-off-by: Colin Walters <[email protected]>
1 parent 2138aa0 commit 01a6fae

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

lib/src/install/baseline.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ pub(crate) fn install_create_rootfs(
170170
// Verify that the target is empty (if not already wiped in particular, but it's
171171
// also good to verify that the wipe worked)
172172
let device = crate::blockdev::list_dev(&opts.device)?;
173+
// Canonicalize devpath
174+
let devpath: Utf8PathBuf = device.path().into();
173175

174176
// Handle wiping any existing data
175177
if opts.wipe {
@@ -193,20 +195,6 @@ pub(crate) fn install_create_rootfs(
193195
if mntdir.exists() {
194196
std::fs::remove_dir_all(&mntdir)?;
195197
}
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);
210198

211199
// Use the install configuration to find the block setup, if we have one
212200
let block_setup = if let Some(config) = state.install_config.as_ref() {
@@ -245,7 +233,7 @@ pub(crate) fn install_create_rootfs(
245233
// sgdisk is too verbose
246234
sgdisk.cmd.stdout(Stdio::null());
247235
sgdisk.cmd.arg("-Z");
248-
sgdisk.cmd.arg(&device);
236+
sgdisk.cmd.arg(device.path());
249237
sgdisk.cmd.args(["-U", "R"]);
250238
#[allow(unused_assignments)]
251239
if cfg!(target_arch = "x86_64") {
@@ -316,27 +304,28 @@ pub(crate) fn install_create_rootfs(
316304
{
317305
let mut f = std::fs::OpenOptions::new()
318306
.write(true)
319-
.open(&device)
320-
.with_context(|| format!("opening {device}"))?;
307+
.open(&devpath)
308+
.with_context(|| format!("opening {devpath}"))?;
321309
crate::blockdev::reread_partition_table(&mut f, true)
322310
.context("Rereading partition table")?;
323311
}
324312

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

327317
// 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)?
318+
let device_partitions = crate::blockdev::list_dev(&devpath)?
329319
.children
330320
.ok_or_else(|| anyhow::anyhow!("Failed to find children after partitioning"))?;
331321
// Given a partition number, return the path to its device.
332322
let findpart = |idx: u32| -> Result<String> {
333323
// checked_sub is here because our partition numbers start at 1, but the vec starts at 0
334-
let devname = device_partitions
324+
let devpath = device_partitions
335325
.get(idx.checked_sub(1).unwrap() as usize)
336326
.ok_or_else(|| anyhow::anyhow!("Missing partition for index {idx}"))?
337-
.name
338-
.as_str();
339-
Ok(devdir.join(devname).to_string())
327+
.path();
328+
Ok(devpath)
340329
};
341330

342331
let base_rootdev = findpart(rootpn)?;
@@ -448,7 +437,7 @@ pub(crate) fn install_create_rootfs(
448437
};
449438
Ok(RootSetup {
450439
luks_device,
451-
device,
440+
device: devpath,
452441
rootfs,
453442
rootfs_fd,
454443
rootfs_uuid: Some(root_uuid.to_string()),

0 commit comments

Comments
 (0)