@@ -18,23 +18,6 @@ import (
1818 netcontext "golang.org/x/net/context"
1919)
2020
21- func firstExistingFile (candidates []string ) string {
22- for _ , file := range candidates {
23- if _ , err := os .Stat (file ); err == nil {
24- return file
25- }
26- }
27- return ""
28- }
29-
30- func getDefaultBundlePath () string {
31- cwd , err := os .Getwd ()
32- if err != nil {
33- return ""
34- }
35- return cwd
36- }
37-
3821var createCommand = cli.Command {
3922 Name : "create" ,
4023 Usage : "create a container" ,
@@ -140,38 +123,6 @@ func runContainer(context *cli.Context, createOnly bool) {
140123 }
141124 }
142125
143- kernel := context .GlobalString ("kernel" )
144- initrd := context .GlobalString ("initrd" )
145- // only set the default kernel/initrd when it is the first container(sharedContainer == "")
146- if kernel == "" && sharedContainer == "" {
147- kernel = firstExistingFile ([]string {
148- filepath .Join (bundle , spec .Root .Path , "boot/vmlinuz" ),
149- filepath .Join (bundle , "boot/vmlinuz" ),
150- filepath .Join (bundle , "vmlinuz" ),
151- "/var/lib/hyper/kernel" ,
152- })
153- }
154- if initrd == "" && sharedContainer == "" {
155- initrd = firstExistingFile ([]string {
156- filepath .Join (bundle , spec .Root .Path , "boot/initrd.img" ),
157- filepath .Join (bundle , "boot/initrd.img" ),
158- filepath .Join (bundle , "initrd.img" ),
159- "/var/lib/hyper/hyper-initrd.img" ,
160- })
161- }
162-
163- // convert the paths to abs
164- kernel , err = filepath .Abs (kernel )
165- if err != nil {
166- fmt .Fprintf (os .Stderr , "Cannot get abs path for kernel: %v\n " , err )
167- os .Exit (- 1 )
168- }
169- initrd , err = filepath .Abs (initrd )
170- if err != nil {
171- fmt .Fprintf (os .Stderr , "Cannot get abs path for initrd: %v\n " , err )
172- os .Exit (- 1 )
173- }
174-
175126 var namespace string
176127 var cmd * exec.Cmd
177128 if sharedContainer != "" {
@@ -188,18 +139,30 @@ func runContainer(context *cli.Context, createOnly bool) {
188139 os .Exit (- 1 )
189140 }
190141
142+ kernel , initrd , bios , cbfs , err := getKernelFiles (context , spec .Root .Path )
143+ if err != nil {
144+ fmt .Fprintf (os .Stderr , "Can't find kernel/initrd/bios/cbfs files" )
145+ os .Exit (- 1 )
146+ }
147+
191148 namespace , err = ioutil .TempDir ("/run" , "runv-namespace-" )
192149 if err != nil {
193150 fmt .Fprintf (os .Stderr , "Failed to create runv namespace path: %v" , err )
194151 os .Exit (- 1 )
195152 }
196153
197154 args := []string {
198- "--kernel" , kernel ,
199- "--initrd" , initrd ,
200155 "--default_cpus" , fmt .Sprintf ("%d" , context .GlobalInt ("default_cpus" )),
201156 "--default_memory" , fmt .Sprintf ("%d" , context .GlobalInt ("default_memory" )),
202157 }
158+
159+ // if user set bios+cbfs, then use bios+cbfs first
160+ if context .GlobalString ("bios" ) != "" && context .GlobalString ("cbfs" ) != "" {
161+ args = append (args , "--bios" , bios , "--cbfs" , cbfs )
162+ } else {
163+ args = append (args , "--kernel" , kernel , "--initrd" , initrd )
164+ }
165+
203166 if context .GlobalBool ("debug" ) {
204167 args = append (args , "--debug" )
205168 }
0 commit comments