@@ -97,6 +97,7 @@ impl Bios {
9797 }
9898
9999 // check bios_boot partition on gpt type disk
100+ #[ allow( dead_code) ]
100101 fn get_bios_boot_partition ( & self ) -> Option < String > {
101102 match blockdev:: get_single_device ( "/" ) {
102103 Ok ( device) => {
@@ -147,24 +148,37 @@ impl Component for Bios {
147148 Ok ( meta)
148149 }
149150
150- fn query_adopt ( & self ) -> Result < Option < Adoptable > > {
151+ fn query_adopt ( & self , devices : & Option < Vec < String > > ) -> Result < Option < Adoptable > > {
151152 #[ cfg( target_arch = "x86_64" ) ]
152- if crate :: efi:: is_efi_booted ( ) ? && self . get_bios_boot_partition ( ) . is_none ( ) {
153+ if crate :: efi:: is_efi_booted ( ) ? && devices . is_none ( ) {
153154 log:: debug!( "Skip BIOS adopt" ) ;
154155 return Ok ( None ) ;
155156 }
156157 crate :: component:: query_adopt_state ( )
157158 }
158159
159- fn adopt_update ( & self , _: & openat:: Dir , update : & ContentMetadata ) -> Result < InstalledContent > {
160- let Some ( meta) = self . query_adopt ( ) ? else {
160+ fn adopt_update (
161+ & self ,
162+ rootcxt : & RootContext ,
163+ update : & ContentMetadata ,
164+ ) -> Result < InstalledContent > {
165+ let bios_devices = blockdev:: find_colocated_bios_boot ( & rootcxt. devices ) ?;
166+ let Some ( meta) = self . query_adopt ( & bios_devices) ? else {
161167 anyhow:: bail!( "Failed to find adoptable system" )
162168 } ;
163169
164- let target_root = "/" ;
165- let device = blockdev:: get_single_device ( & target_root) ?;
166- self . run_grub_install ( target_root, & device) ?;
167- log:: debug!( "Install grub modules on {device}" ) ;
170+ let mut parent_devices = rootcxt. devices . iter ( ) ;
171+ let Some ( parent) = parent_devices. next ( ) else {
172+ anyhow:: bail!( "Failed to find parent device" ) ;
173+ } ;
174+
175+ if let Some ( next) = parent_devices. next ( ) {
176+ anyhow:: bail!(
177+ "Found multiple parent devices {parent} and {next}; not currently supported"
178+ ) ;
179+ }
180+ self . run_grub_install ( rootcxt. path . as_str ( ) , & parent) ?;
181+ log:: debug!( "Installed grub modules on {parent}" ) ;
168182 Ok ( InstalledContent {
169183 meta : update. clone ( ) ,
170184 filetree : None ,
@@ -176,12 +190,12 @@ impl Component for Bios {
176190 get_component_update ( sysroot, self )
177191 }
178192
179- fn run_update ( & self , sysroot : & RootContext , _: & InstalledContent ) -> Result < InstalledContent > {
193+ fn run_update ( & self , rootcxt : & RootContext , _: & InstalledContent ) -> Result < InstalledContent > {
180194 let updatemeta = self
181- . query_update ( & sysroot . sysroot ) ?
195+ . query_update ( & rootcxt . sysroot ) ?
182196 . expect ( "update available" ) ;
183197
184- let mut parent_devices = sysroot . devices . iter ( ) ;
198+ let mut parent_devices = rootcxt . devices . iter ( ) ;
185199 let Some ( parent) = parent_devices. next ( ) else {
186200 anyhow:: bail!( "Failed to find parent device" ) ;
187201 } ;
@@ -192,7 +206,7 @@ impl Component for Bios {
192206 ) ;
193207 }
194208
195- self . run_grub_install ( sysroot . path . as_str ( ) , & parent) ?;
209+ self . run_grub_install ( rootcxt . path . as_str ( ) , & parent) ?;
196210 log:: debug!( "Install grub modules on {parent}" ) ;
197211
198212 let adopted_from = None ;
0 commit comments