@@ -17,19 +17,29 @@ mod mbr;
17
17
mod pxe;
18
18
19
19
const KERNEL_FILE_NAME : & str = "kernel-x86_64" ;
20
+ const RAMDISK_FILE_NAME : & str = "ramdisk-x86_64" ;
20
21
const BIOS_STAGE_3 : & str = "boot-stage-3" ;
21
22
const BIOS_STAGE_4 : & str = "boot-stage-4" ;
22
23
23
24
/// Create disk images for booting on legacy BIOS systems.
24
25
pub struct BiosBoot {
25
26
kernel : PathBuf ,
27
+ ramdisk : Option < PathBuf > ,
26
28
}
27
29
28
30
impl BiosBoot {
29
31
/// Start creating a disk image for the given bootloader ELF executable.
30
32
pub fn new ( kernel_path : & Path ) -> Self {
31
33
Self {
32
34
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 ( ) )
33
43
}
34
44
}
35
45
@@ -66,7 +76,9 @@ impl BiosBoot {
66
76
files. insert ( KERNEL_FILE_NAME , self . kernel . as_path ( ) ) ;
67
77
files. insert ( BIOS_STAGE_3 , stage_3_path) ;
68
78
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
+ }
70
82
let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
71
83
fat:: create_fat_filesystem ( files, out_file. path ( ) )
72
84
. context ( "failed to create BIOS FAT filesystem" ) ?;
@@ -78,13 +90,22 @@ impl BiosBoot {
78
90
/// Create disk images for booting on UEFI systems.
79
91
pub struct UefiBoot {
80
92
kernel : PathBuf ,
93
+ ramdisk : Option < PathBuf > ,
81
94
}
82
95
83
96
impl UefiBoot {
84
97
/// Start creating a disk image for the given bootloader ELF executable.
85
98
pub fn new ( kernel_path : & Path ) -> Self {
86
99
Self {
87
100
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 ( ) )
88
109
}
89
110
}
90
111
@@ -125,6 +146,9 @@ impl UefiBoot {
125
146
let mut files = BTreeMap :: new ( ) ;
126
147
files. insert ( "efi/boot/bootx64.efi" , bootloader_path) ;
127
148
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
+ }
128
152
129
153
let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
130
154
fat:: create_fat_filesystem ( files, out_file. path ( ) )
0 commit comments