@@ -17,6 +17,7 @@ import (
1717 "github.com/Microsoft/hcsshim/internal/uvmfolder"
1818 "github.com/Microsoft/hcsshim/internal/wclayer"
1919 "github.com/Microsoft/hcsshim/internal/wcow"
20+ "github.com/Microsoft/hcsshim/osversion"
2021 "github.com/linuxkit/virtsock/pkg/hvsock"
2122 specs "github.com/opencontainers/runtime-spec/specs-go"
2223 "github.com/sirupsen/logrus"
@@ -46,6 +47,7 @@ type UVMOptions struct {
4647 // LCOW specific parameters
4748 BootFilesPath string // Folder in which kernel and root file system reside. Defaults to \Program Files\Linux Containers
4849 KernelFile string // Filename under BootFilesPath for the kernel. Defaults to `kernel`
50+ KernelDirect bool // Skip UEFI and boot directly to `kernel`
4951 RootFSFile string // Filename under BootFilesPath for the UVMs root file system. Defaults are `initrd.img` or `rootfs.vhd`.
5052 KernelBootOptions string // Additional boot options for the kernel
5153 EnableGraphicsConsole bool // If true, enable a graphics console for the utility VM
@@ -179,6 +181,9 @@ func Create(opts *UVMOptions) (_ *UtilityVM, err error) {
179181 uvm .vpmemMaxSizeBytes = * opts .VPMemSizeBytes
180182 }
181183 }
184+ if opts .KernelDirect && osversion .Get ().Build < 18286 {
185+ return nil , fmt .Errorf ("KernelDirectBoot is not support on builds older than 18286" )
186+ }
182187
183188 scsi ["0" ] = hcsschema.Scsi {Attachments : attachments }
184189 uvm .scsiControllerCount = 1
@@ -333,19 +338,21 @@ func Create(opts *UVMOptions) (_ *UtilityVM, err error) {
333338 vmDebugging := false
334339 vm .GuestConnection .UseVsock = true
335340 vm .GuestConnection .UseConnectedSuspend = true
336- vm .Devices .VirtualSmb = & hcsschema.VirtualSmb {
337- Shares : []hcsschema.VirtualSmbShare {
338- {
339- Name : "os" ,
340- Path : opts .BootFilesPath ,
341- Options : & hcsschema.VirtualSmbShareOptions {
342- ReadOnly : true ,
343- TakeBackupPrivilege : true ,
344- CacheIo : true ,
345- ShareRead : true ,
341+ if ! opts .KernelDirect {
342+ vm .Devices .VirtualSmb = & hcsschema.VirtualSmb {
343+ Shares : []hcsschema.VirtualSmbShare {
344+ {
345+ Name : "os" ,
346+ Path : opts .BootFilesPath ,
347+ Options : & hcsschema.VirtualSmbShareOptions {
348+ ReadOnly : true ,
349+ TakeBackupPrivilege : true ,
350+ CacheIo : true ,
351+ ShareRead : true ,
352+ },
346353 },
347354 },
348- },
355+ }
349356 }
350357
351358 if uvm .vpmemMaxCount > 0 {
@@ -355,8 +362,13 @@ func Create(opts *UVMOptions) (_ *UtilityVM, err error) {
355362 }
356363 }
357364
358- kernelArgs := "initrd=/" + opts .RootFSFile
359- if actualRootFSType == PreferredRootFSTypeVHD {
365+ var kernelArgs string
366+ switch actualRootFSType {
367+ case PreferredRootFSTypeInitRd :
368+ if ! opts .KernelDirect {
369+ kernelArgs = "initrd=/" + opts .RootFSFile
370+ }
371+ case PreferredRootFSTypeVHD :
360372 kernelArgs = "root=/dev/pmem0 init=/init"
361373 }
362374
@@ -428,10 +440,22 @@ func Create(opts *UVMOptions) (_ *UtilityVM, err error) {
428440 }
429441
430442 kernelArgs += ` pci=off -- ` + initArgs
431- vm .Chipset .Uefi .BootThis = & hcsschema.UefiBootEntry {
432- DevicePath : `\` + opts .KernelFile ,
433- DeviceType : "VmbFs" ,
434- OptionalData : kernelArgs ,
443+
444+ if ! opts .KernelDirect {
445+ vm .Chipset .Uefi .BootThis = & hcsschema.UefiBootEntry {
446+ DevicePath : `\` + opts .KernelFile ,
447+ DeviceType : "VmbFs" ,
448+ OptionalData : kernelArgs ,
449+ }
450+ } else {
451+ vm .Chipset .Uefi = nil
452+ vm .Chipset .LinuxKernelDirect = & hcsschema.LinuxKernelDirect {
453+ KernelFilePath : filepath .Join (opts .BootFilesPath , opts .KernelFile ),
454+ KernelCmdLine : kernelArgs ,
455+ }
456+ if actualRootFSType == PreferredRootFSTypeInitRd {
457+ vm .Chipset .LinuxKernelDirect .InitRdPath = filepath .Join (opts .BootFilesPath , opts .RootFSFile )
458+ }
435459 }
436460 }
437461
0 commit comments