Skip to content

Commit 25970b4

Browse files
committed
fde: Fix "Failed to load kernel module 'nbd'" when used in docker container
Signed-off-by: Kun Lai <[email protected]>
1 parent 15c5bc2 commit 25970b4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cryptpilot.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%global debug_package %{nil}
2-
%define release_num 3
2+
%define release_num 4
33

44
Name: cryptpilot
55
Version: 0.2.5
@@ -139,6 +139,9 @@ fi
139139

140140

141141
%changelog
142+
* Wed Jul 2 2025 Kun Lai <[email protected]> - 0.2.5-4
143+
- Fix "Failed to load kernel module 'nbd'" when used in docker container.
144+
142145
* Mon Jun 30 2025 Kun Lai <[email protected]> - 0.2.5-3
143146
- cryptpilot-convert: fix occasional "device or resource busy" error when rootfs encryption is enabled
144147

src/fs/nbd.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub struct NbdDevice {
2727
}
2828

2929
impl NbdDevice {
30+
pub fn is_module_loaded() -> bool {
31+
Path::new("/dev/nbd0").exists()
32+
}
33+
3034
pub async fn modprobe() -> Result<()> {
3135
tokio::task::spawn_blocking(|| {
3236
liblmod::modprobe(
@@ -48,7 +52,9 @@ impl NbdDevice {
4852
}
4953

5054
pub async fn get_avaliable() -> Result<NbdDeviceNumber> {
51-
Self::modprobe().await?;
55+
if !Self::is_module_loaded() {
56+
Self::modprobe().await?;
57+
}
5258

5359
for i in 0..=99 {
5460
let dev = PathBuf::from(format!("/dev/nbd{i}"));

0 commit comments

Comments
 (0)