mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #1867 from justincormack/qemu-disk-format
Allow specifying the format of a qemu drive
This commit is contained in:
commit
0398d208dc
@ -26,6 +26,7 @@ type QemuConfig struct {
|
|||||||
GUI bool
|
GUI bool
|
||||||
DiskPath string
|
DiskPath string
|
||||||
DiskSize string
|
DiskSize string
|
||||||
|
DiskFormat string
|
||||||
FWPath string
|
FWPath string
|
||||||
Arch string
|
Arch string
|
||||||
CPUs string
|
CPUs string
|
||||||
@ -54,9 +55,12 @@ func runQemu(args []string) {
|
|||||||
isoBoot := flags.Bool("iso", false, "Set Legacy BIOS boot from 'prefix'.iso")
|
isoBoot := flags.Bool("iso", false, "Set Legacy BIOS boot from 'prefix'.iso")
|
||||||
kernelBoot := flags.Bool("kernel", true, "Set boot using 'prefix'-kernel/-initrd/-cmdline")
|
kernelBoot := flags.Bool("kernel", true, "Set boot using 'prefix'-kernel/-initrd/-cmdline")
|
||||||
|
|
||||||
// Paths and settings for Disks and UEFI firware
|
// Paths and settings for disks
|
||||||
disk := flags.String("disk", "", "Path to disk image to use")
|
disk := flags.String("disk", "", "Path to disk image to use")
|
||||||
diskSz := flags.String("disk-size", "", "Size of disk to create, only created if it doesn't exist")
|
diskSz := flags.String("disk-size", "", "Size of disk to create, only created if it doesn't exist")
|
||||||
|
diskFmt := flags.String("disk-format", "qcow2", "Format of disk: raw, qcow2 etc")
|
||||||
|
|
||||||
|
// Paths and settings for UEFI firware
|
||||||
fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot")
|
fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot")
|
||||||
|
|
||||||
// VM configuration
|
// VM configuration
|
||||||
@ -95,6 +99,7 @@ func runQemu(args []string) {
|
|||||||
GUI: *enableGUI,
|
GUI: *enableGUI,
|
||||||
DiskPath: *disk,
|
DiskPath: *disk,
|
||||||
DiskSize: *diskSz,
|
DiskSize: *diskSz,
|
||||||
|
DiskFormat: *diskFmt,
|
||||||
FWPath: *fw,
|
FWPath: *fw,
|
||||||
Arch: *arch,
|
Arch: *arch,
|
||||||
CPUs: *cpus,
|
CPUs: *cpus,
|
||||||
@ -124,17 +129,17 @@ func runQemuLocal(config QemuConfig) error {
|
|||||||
// If disk doesn't exist then create one
|
// If disk doesn't exist then create one
|
||||||
if _, err := os.Stat(config.DiskPath); err != nil {
|
if _, err := os.Stat(config.DiskPath); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Infof("Creating new qemu disk [%s]", config.DiskPath)
|
log.Infof("Creating new qemu disk [%s] format %s", config.DiskPath, config.DiskFormat)
|
||||||
qemuImgCmd := exec.Command(config.QemuImgPath, "create", "-f", "qcow2", config.DiskPath, config.DiskSize)
|
qemuImgCmd := exec.Command(config.QemuImgPath, "create", "-f", config.DiskFormat, config.DiskPath, config.DiskSize)
|
||||||
log.Debugf("%v\n", qemuImgCmd.Args)
|
log.Debugf("%v\n", qemuImgCmd.Args)
|
||||||
if err := qemuImgCmd.Run(); err != nil {
|
if err := qemuImgCmd.Run(); err != nil {
|
||||||
return fmt.Errorf("Error creating disk [%s]: %s", config.DiskPath, err.Error())
|
return fmt.Errorf("Error creating disk [%s] format %s: %s", config.DiskPath, config.DiskFormat, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Using existing disk [%s]", config.DiskPath)
|
log.Infof("Using existing disk [%s] format %s", config.DiskPath, config.DiskFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,18 +211,18 @@ func runQemuContainer(config QemuConfig) error {
|
|||||||
// If disk doesn't exist then create one
|
// If disk doesn't exist then create one
|
||||||
if _, err = os.Stat(config.DiskPath); err != nil {
|
if _, err = os.Stat(config.DiskPath); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Infof("Creating new qemu disk [%s]", config.DiskPath)
|
log.Infof("Creating new qemu disk [%s] format %s", config.DiskPath, config.DiskFormat)
|
||||||
imgArgs := append(dockerArgs, QemuImg, "qemu-img", "create", "-f", "qcow2", config.DiskPath, config.DiskSize)
|
imgArgs := append(dockerArgs, QemuImg, "qemu-img", "create", "-f", config.DiskFormat, config.DiskPath, config.DiskSize)
|
||||||
qemuImgCmd := exec.Command(dockerPath, imgArgs...)
|
qemuImgCmd := exec.Command(dockerPath, imgArgs...)
|
||||||
log.Debugf("%v\n", qemuImgCmd.Args)
|
log.Debugf("%v\n", qemuImgCmd.Args)
|
||||||
if err = qemuImgCmd.Run(); err != nil {
|
if err = qemuImgCmd.Run(); err != nil {
|
||||||
return fmt.Errorf("Error creating disk [%s]: %s", config.DiskPath, err.Error())
|
return fmt.Errorf("Error creating disk [%s] format %s: %s", config.DiskPath, config.DiskFormat, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Using existing disk [%s]", config.DiskPath)
|
log.Infof("Using existing disk [%s] format %s", config.DiskPath, config.DiskFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +262,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.DiskPath != "" {
|
if config.DiskPath != "" {
|
||||||
qemuArgs = append(qemuArgs, "-drive", "file="+config.DiskPath+",format=qcow2,index=0,media=disk")
|
qemuArgs = append(qemuArgs, "-drive", "file="+config.DiskPath+",format="+config.DiskFormat+",index=0,media=disk")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check flags for iso/uefi boot and if so disable kernel boot
|
// Check flags for iso/uefi boot and if so disable kernel boot
|
||||||
|
Loading…
Reference in New Issue
Block a user