mirror of
https://github.com/linka-cloud/d2vm.git
synced 2024-11-25 09:06:24 +00:00
builder: check dependencies
qemu.sh: fix kvm flag Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
362c6e1d8c
commit
c240aac13d
20
builder.go
20
builder.go
@ -19,6 +19,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
exec2 "os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ ff02::3 ip6-allhosts
|
|||||||
KERNEL /boot/vmlinuz
|
KERNEL /boot/vmlinuz
|
||||||
APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8
|
APPEND ro root=UUID=%s initrd=/boot/initrd.img net.ifnames=0 console=tty0 console=ttyS0,115200n8
|
||||||
`
|
`
|
||||||
|
mbrBin = "/usr/lib/EXTLINUX/mbr.bin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -84,6 +86,9 @@ type builder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewBuilder(workdir, src, disk string, size int64, osRelease OSRelease) (*builder, error) {
|
func NewBuilder(workdir, src, disk string, size int64, osRelease OSRelease) (*builder, error) {
|
||||||
|
if err := checkDependencies(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
size = 1
|
size = 1
|
||||||
}
|
}
|
||||||
@ -291,7 +296,7 @@ func (b *builder) installKernel(ctx context.Context) error {
|
|||||||
|
|
||||||
func (b *builder) setupMBR(ctx context.Context) error {
|
func (b *builder) setupMBR(ctx context.Context) error {
|
||||||
logrus.Infof("writing MBR")
|
logrus.Infof("writing MBR")
|
||||||
if err := exec.Run(ctx, "dd", "if=/usr/lib/EXTLINUX/mbr.bin", fmt.Sprintf("of=%s", b.diskRaw), "bs=440", "count=1", "conv=notrunc"); err != nil {
|
if err := exec.Run(ctx, "dd", fmt.Sprintf("if=%s", mbrBin), fmt.Sprintf("of=%s", b.diskRaw), "bs=440", "count=1", "conv=notrunc"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -318,3 +323,16 @@ func block(path string, size int64) error {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
return f.Truncate(size)
|
return f.Truncate(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkDependencies() error {
|
||||||
|
var merr error
|
||||||
|
for _, v := range []string{"mount", "blkid", "tar", "kpartx", "losetup", "qemu-img", "extlinux", "dd", "mkfs", "fdisk"} {
|
||||||
|
if _, err := exec2.LookPath(v); err != nil {
|
||||||
|
merr = multierr.Append(merr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(mbrBin); err != nil {
|
||||||
|
merr = multierr.Append(merr, err)
|
||||||
|
}
|
||||||
|
return merr
|
||||||
|
}
|
||||||
|
2
qemu.sh
2
qemu.sh
@ -21,7 +21,7 @@ ARGS=""
|
|||||||
if [[ $OSTYPE == 'darwin'* ]]; then
|
if [[ $OSTYPE == 'darwin'* ]]; then
|
||||||
ARGS="-M accel=hvf"
|
ARGS="-M accel=hvf"
|
||||||
else
|
else
|
||||||
ARGS="-use-kvm"
|
ARGS="-enable-kvm"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
qemu-system-x86_64 -drive file=$IMG,index=0,media=disk,format=qcow2 -m 4096 -cpu host -nographic ${ARGS} ${@: 2}
|
qemu-system-x86_64 -drive file=$IMG,index=0,media=disk,format=qcow2 -m 4096 -cpu host -nographic ${ARGS} ${@: 2}
|
||||||
|
Loading…
Reference in New Issue
Block a user