Skip to content

Commit 89d34c7

Browse files
committed
bugfix: Switch losetup to --direct-io=off by default
When using a loopback device pointing to a file on a 9p filesystem (e.g. the home mount of a podman machine), using direct-io=on causes the partitioning via sgdisk to fail. This is a temporary fix until podman machine switches away from 9p or another fix is found. Direct IO can be enabled via the BOOTC_DIRECT_IO=on environment variable. Fixes #485 Signed-off-by: Chris Kyrouac <ckyrouac@redhat.com>
1 parent 03d1a06 commit 89d34c7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

docs/src/bootc-install.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ podman run --rm --privileged --pid=host --security-opt label=type:unconfined_t
167167

168168
Notice that we use `--generic-image` for this use case.
169169

170+
Set the environment variable `BOOTC_DIRECT_IO=on` to create the loopback device with direct-io enabled.
171+
170172
### Using `bootc install to-existing-root`
171173

172174
This is a variant of `install to-filesystem`, which maximizes convenience for using

lib/src/blockdev.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
88
use regex::Regex;
99
use serde::Deserialize;
1010
use std::collections::HashMap;
11+
use std::env;
1112
use std::fs::File;
1213
use std::os::unix::io::AsRawFd;
1314
use std::path::Path;
@@ -83,8 +84,24 @@ pub(crate) struct LoopbackDevice {
8384
impl LoopbackDevice {
8485
// Create a new loopback block device targeting the provided file path.
8586
pub(crate) fn new(path: &Path) -> Result<Self> {
87+
let direct_io = match env::var("BOOTC_DIRECT_IO") {
88+
Ok(val) => {
89+
if val == "on" {
90+
"on"
91+
} else {
92+
"off"
93+
}
94+
}
95+
Err(_e) => "off",
96+
};
97+
8698
let dev = Task::new("losetup", "losetup")
87-
.args(["--show", "--direct-io=on", "-P", "--find"])
99+
.args([
100+
"--show",
101+
format!("--direct-io={direct_io}").as_str(),
102+
"-P",
103+
"--find",
104+
])
88105
.arg(path)
89106
.quiet()
90107
.read()?;

0 commit comments

Comments
 (0)