Skip to content

Commit 848ce44

Browse files
committed
bios.rs: remove get_device()
1 parent b2d0ddd commit 848ce44

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

src/bios.rs

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::blockdev;
66
use crate::component::*;
77
use crate::model::*;
88
use crate::packagesystem;
9-
use crate::util;
109

1110
use anyhow::{bail, Result};
1211

@@ -17,40 +16,6 @@ pub(crate) const GRUB_BIN: &str = "usr/sbin/grub2-install";
1716
pub(crate) struct Bios {}
1817

1918
impl Bios {
20-
// get target device for running update
21-
fn get_device(&self) -> Result<String> {
22-
let mut cmd: Command;
23-
#[cfg(target_arch = "x86_64")]
24-
{
25-
// find /boot partition
26-
cmd = Command::new("findmnt");
27-
cmd.arg("--noheadings")
28-
.arg("--nofsroot")
29-
.arg("--output")
30-
.arg("SOURCE")
31-
.arg("/boot");
32-
let partition = util::cmd_output(&mut cmd)?;
33-
34-
// lsblk to find parent device
35-
cmd = Command::new("lsblk");
36-
cmd.arg("--paths")
37-
.arg("--noheadings")
38-
.arg("--output")
39-
.arg("PKNAME")
40-
.arg(partition.trim());
41-
}
42-
43-
#[cfg(target_arch = "powerpc64")]
44-
{
45-
// get PowerPC-PReP-boot partition
46-
cmd = Command::new("realpath");
47-
cmd.arg("/dev/disk/by-partlabel/PowerPC-PReP-boot");
48-
}
49-
50-
let device = util::cmd_output(&mut cmd)?;
51-
Ok(device)
52-
}
53-
5419
// Return `true` if grub2-modules installed
5520
fn check_grub_modules(&self) -> Result<bool> {
5621
let usr_path = Path::new("/usr/lib/grub");
@@ -168,9 +133,13 @@ impl Component for Bios {
168133
anyhow::bail!("Failed to find adoptable system")
169134
};
170135

171-
let device = self.get_device()?;
172-
let device = device.trim();
173-
self.run_grub_install("/", device)?;
136+
let target_root = "/";
137+
let devices = blockdev::get_backing_devices(&target_root)?
138+
.into_iter()
139+
.next();
140+
let dev = devices.unwrap();
141+
self.run_grub_install(target_root, &dev)?;
142+
log::debug!("Install grub2 on {dev}");
174143
Ok(InstalledContent {
175144
meta: update.clone(),
176145
filetree: None,
@@ -184,9 +153,14 @@ impl Component for Bios {
184153

185154
fn run_update(&self, sysroot: &openat::Dir, _: &InstalledContent) -> Result<InstalledContent> {
186155
let updatemeta = self.query_update(sysroot)?.expect("update available");
187-
let device = self.get_device()?;
188-
let device = device.trim();
189-
self.run_grub_install("/", device)?;
156+
let sysroot = sysroot.recover_path()?;
157+
let dest_root = sysroot.to_str().unwrap_or("/");
158+
let devices = blockdev::get_backing_devices(&dest_root)?
159+
.into_iter()
160+
.next();
161+
let dev = devices.unwrap();
162+
self.run_grub_install(dest_root, &dev)?;
163+
log::debug!("Install grub modules on {dev}");
190164

191165
let adopted_from = None;
192166
Ok(InstalledContent {

0 commit comments

Comments
 (0)