@@ -17,19 +17,29 @@ mod mbr;
1717mod pxe;
1818
1919const KERNEL_FILE_NAME : & str = "kernel-x86_64" ;
20+ const RAMDISK_FILE_NAME : & str = "ramdisk-x86_64" ;
2021const BIOS_STAGE_3 : & str = "boot-stage-3" ;
2122const BIOS_STAGE_4 : & str = "boot-stage-4" ;
2223
2324/// Create disk images for booting on legacy BIOS systems.
2425pub struct BiosBoot {
2526 kernel : PathBuf ,
27+ ramdisk : Option < PathBuf > ,
2628}
2729
2830impl BiosBoot {
2931 /// Start creating a disk image for the given bootloader ELF executable.
3032 pub fn new ( kernel_path : & Path ) -> Self {
3133 Self {
3234 kernel : kernel_path. to_owned ( ) ,
35+ ramdisk : None ,
36+ }
37+ }
38+
39+ pub fn with_ramdisk ( & self , ramdisk_path : & Path ) -> Self {
40+ Self {
41+ kernel : self . kernel ,
42+ ramdisk : Some ( ramdisk_path. to_owned ( ) )
3343 }
3444 }
3545
@@ -66,7 +76,9 @@ impl BiosBoot {
6676 files. insert ( KERNEL_FILE_NAME , self . kernel . as_path ( ) ) ;
6777 files. insert ( BIOS_STAGE_3 , stage_3_path) ;
6878 files. insert ( BIOS_STAGE_4 , stage_4_path) ;
69-
79+ if self . ramdisk . is_some ( ) {
80+ files. insert ( RAMDISK_FILE_NAME , self . ramdisk . unwrap ( ) . as_path ( ) )
81+ }
7082 let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
7183 fat:: create_fat_filesystem ( files, out_file. path ( ) )
7284 . context ( "failed to create BIOS FAT filesystem" ) ?;
@@ -78,13 +90,22 @@ impl BiosBoot {
7890/// Create disk images for booting on UEFI systems.
7991pub struct UefiBoot {
8092 kernel : PathBuf ,
93+ ramdisk : Option < PathBuf > ,
8194}
8295
8396impl UefiBoot {
8497 /// Start creating a disk image for the given bootloader ELF executable.
8598 pub fn new ( kernel_path : & Path ) -> Self {
8699 Self {
87100 kernel : kernel_path. to_owned ( ) ,
101+ ramdisk : None ,
102+ }
103+ }
104+
105+ pub fn with_ramdisk ( & self , ramdisk_path : & Path ) -> Self {
106+ Self {
107+ kernel : self . kernel ,
108+ ramdisk : Some ( ramdisk_path. to_owned ( ) )
88109 }
89110 }
90111
@@ -125,6 +146,9 @@ impl UefiBoot {
125146 let mut files = BTreeMap :: new ( ) ;
126147 files. insert ( "efi/boot/bootx64.efi" , bootloader_path) ;
127148 files. insert ( KERNEL_FILE_NAME , self . kernel . as_path ( ) ) ;
149+ if self . ramdisk . is_some ( ) {
150+ files. insert ( RAMDISK_FILE_NAME , self . ramdisk . unwrap ( ) . as_path ( ) )
151+ }
128152
129153 let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
130154 fat:: create_fat_filesystem ( files, out_file. path ( ) )
0 commit comments