diff --git a/src/main.rs b/src/main.rs index 4f36690..96488c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -330,7 +330,14 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> { None }; - let storage_device = storage::StorageDevice::from_path(&command.block_device)?; + let mut loop_device: Option; + let storage_device = match storage::StorageDevice::from_path(&command.block_device) { + Ok(b) => b, + Err(_) => { + loop_device = Some(LoopDevice::create(&command.block_device)?); + storage::StorageDevice::from_path(loop_device.as_ref().unwrap().path())? + } + }; let mount_point = tempdir().context(ErrorKind::TmpDirError)?; let boot_partition = storage_device.get_partition(BOOT_PARTITION_INDEX)?; diff --git a/src/storage/loop_device.rs b/src/storage/loop_device.rs index 89b5b37..7156ce0 100644 --- a/src/storage/loop_device.rs +++ b/src/storage/loop_device.rs @@ -26,10 +26,10 @@ impl LoopDevice { ))? } - Ok(LoopDevice { - path: PathBuf::from(String::from_utf8(output.stdout).unwrap().trim()), - losetup, - }) + let path = PathBuf::from(String::from_utf8(output.stdout).unwrap().trim()); + info!("Mounted {} to {}", file.display(), path.display()); + + Ok(LoopDevice { path, losetup }) } pub fn path(&self) -> &Path {