add a sata disk mode for freebsd 12

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-16 15:50:10 +00:00
parent a12f621dfe
commit d5ac2e76e0
2 changed files with 22 additions and 3 deletions

12
main.go
View File

@ -37,6 +37,7 @@ var (
zvolSize = flag.Int("zvol-size", 25, "the number of gigabytes for the virtual machine disk") zvolSize = flag.Int("zvol-size", 25, "the number of gigabytes for the virtual machine disk")
memory = flag.Int("memory", 512, "the number of megabytes of ram for the virtual machine") memory = flag.Int("memory", 512, "the number of megabytes of ram for the virtual machine")
cloudConfig = flag.String("user-data", "./var/xe-base.yaml", "path to a cloud-config userdata file") cloudConfig = flag.String("user-data", "./var/xe-base.yaml", "path to a cloud-config userdata file")
useSATA = flag.Bool("use-sata", false, "use SATA for the VM's disk interface? (needed if using freebsd-12)")
) )
func main() { func main() {
@ -99,9 +100,12 @@ func main() {
log.Printf("ram: %d MB", *memory) log.Printf("ram: %d MB", *memory)
log.Printf("id: %s", vmID) log.Printf("id: %s", vmID)
log.Printf("cloud config: %s", *cloudConfig) log.Printf("cloud config: %s", *cloudConfig)
if *useSATA {
log.Println("using SATA for the VM disk interface")
}
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
fmt.Print("press enter if this looks okay:") fmt.Print("press enter if this looks okay: ")
reader.ReadString('\n') reader.ReadString('\n')
cdir, err := os.UserCacheDir() cdir, err := os.UserCacheDir()
@ -149,8 +153,8 @@ func main() {
if hash != resultDistro.Sha256Sum { if hash != resultDistro.Sha256Sum {
log.Println("hash mismatch, someone is doing something nasty") log.Println("hash mismatch, someone is doing something nasty")
log.Printf("want: %s", resultDistro.Sha256Sum) log.Printf("want: %q", resultDistro.Sha256Sum)
log.Printf("got: %s", resultDistro.Sha256Sum) log.Printf("got: %q", hash)
os.Exit(1) os.Exit(1)
} }
@ -228,6 +232,7 @@ func main() {
ZVol string ZVol string
Seed string Seed string
MACAddress string MACAddress string
SATA bool
}{ }{
Name: *name, Name: *name,
UUID: vmID, UUID: vmID,
@ -235,6 +240,7 @@ func main() {
ZVol: zvol, ZVol: zvol,
Seed: isoPath, Seed: isoPath,
MACAddress: macAddress, MACAddress: macAddress,
SATA: *useSATA,
}) })
if err != nil { if err != nil {
log.Fatalf("can't generate VM template: %v", err) log.Fatalf("can't generate VM template: %v", err)

View File

@ -36,19 +36,32 @@
<disk type="block" device="disk"> <disk type="block" device="disk">
<driver name="qemu" type="raw" cache="none" io="native"/> <driver name="qemu" type="raw" cache="none" io="native"/>
<source dev="/dev/zvol/{{.ZVol}}"/> <source dev="/dev/zvol/{{.ZVol}}"/>
{{if .SATA}}
<target dev="sda" bus="sata"/>
{{else}}
<target dev="vda" bus="virtio"/> <target dev="vda" bus="virtio"/>
{{end}}
</disk> </disk>
<disk type="file" device="cdrom"> <disk type="file" device="cdrom">
<driver name="qemu" type="raw"/> <driver name="qemu" type="raw"/>
<source file="{{.Seed}}"/> <source file="{{.Seed}}"/>
{{if .SATA}}
<target dev="sdb" bus="sata"/>
{{else}}
<target dev="sda" bus="sata"/> <target dev="sda" bus="sata"/>
{{end}}
<readonly/> <readonly/>
</disk> </disk>
<controller type="usb" model="qemu-xhci" ports="15"/> <controller type="usb" model="qemu-xhci" ports="15"/>
<interface type="network"> <interface type="network">
<source network="default"/> <source network="default"/>
<mac address="{{.MACAddress}}"/> <mac address="{{.MACAddress}}"/>
{{if .SATA}}
<model type="e1000e"/>
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
{{else}}
<model type="virtio"/> <model type="virtio"/>
{{end}}
</interface> </interface>
<console type="pty"/> <console type="pty"/>
<channel type="unix"> <channel type="unix">