Windows fixes
This commit is contained in:
parent
41b9fea146
commit
1b69e6294d
7 changed files with 30 additions and 20 deletions
|
|
@ -28,11 +28,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
"github.com/AlexSSD7/linsk/utils"
|
"github.com/AlexSSD7/linsk/utils"
|
||||||
"github.com/alessio/shellescape"
|
"github.com/alessio/shellescape"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/exp/slog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Available() bool {
|
func Available() bool {
|
||||||
|
|
@ -66,7 +67,8 @@ func NewTapManager(logger *slog.Logger) (*TapManager, error) {
|
||||||
var tapNameRegexp = regexp.MustCompile(`^LinskTap-\d+$`)
|
var tapNameRegexp = regexp.MustCompile(`^LinskTap-\d+$`)
|
||||||
|
|
||||||
func NewUniqueTapName() (string, error) {
|
func NewUniqueTapName() (string, error) {
|
||||||
return fmt.Sprintf("LinskTap-%v", time.Now().UnixNano())
|
time.Sleep(time.Millisecond)
|
||||||
|
return fmt.Sprintf("LinskTap-%v", time.Now().UnixNano()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm *TapManager) CreateNewTap(tapName string) error {
|
func (tm *TapManager) CreateNewTap(tapName string) error {
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ func TerminateProcess(pid int) error {
|
||||||
return exec.Command("TASKKILL", "/T", "/F", "/PID", fmt.Sprint(pid)).Run()
|
return exec.Command("TASKKILL", "/T", "/F", "/PID", fmt.Sprint(pid)).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
var physicalDriveCheckRegexp = regexp.MustCompile(`^\\\\.\\PhysicalDrive(\d+)$`)
|
var physicalDriveCheckRegexp = regexp.MustCompile(`(?i)^\\\\.\\PhysicalDrive(\d+)$`)
|
||||||
var physicalDriveFindRegexp = regexp.MustCompile(`PhysicalDrive(\d+)`)
|
var physicalDriveFindRegexp = regexp.MustCompile(`(?i)PhysicalDrive(\d+)`)
|
||||||
|
|
||||||
// This is never used except for a band-aid that would check
|
// This is never used except for a band-aid that would check
|
||||||
// that there are no double-mounts.
|
// that there are no double-mounts.
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var safeArgs = map[string]ArgAcceptedValue{
|
var safeArgs = map[string]ArgAcceptedValue{
|
||||||
"accel": ArgAcceptedValueString,
|
"accel": ArgAcceptedValueKeyValue,
|
||||||
"boot": ArgAcceptedValueString,
|
"boot": ArgAcceptedValueString,
|
||||||
"m": ArgAcceptedValueUint,
|
"m": ArgAcceptedValueUint,
|
||||||
"smp": ArgAcceptedValueUint,
|
"smp": ArgAcceptedValueUint,
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,6 @@ func NewKeyValueArg(key string, items []KeyValueArgItem) (*KeyValueArg, error) {
|
||||||
return nil, fmt.Errorf("empty key not allowed")
|
return nil, fmt.Errorf("empty key not allowed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(item.Value) == 0 {
|
|
||||||
// Values *can* be empty, though. We do not allow them for consistency.
|
|
||||||
return nil, fmt.Errorf("empty value for key '%v' is not allowed", item.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := validateArgStrValue(item.Key)
|
err := validateArgStrValue(item.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "validate key '%v'", item.Key)
|
return nil, errors.Wrapf(err, "validate key '%v'", item.Key)
|
||||||
|
|
|
||||||
|
|
@ -45,5 +45,9 @@ func validateArgStrValue(s string) error {
|
||||||
return fmt.Errorf("backslashes are not allowed")
|
return fmt.Errorf("backslashes are not allowed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(s, "=") {
|
||||||
|
return fmt.Errorf("equals sign is not allowed")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
vm/cfg.go
27
vm/cfg.go
|
|
@ -35,10 +35,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func getUniqueQEMUNetID() string {
|
func getUniqueQEMUNetID() string {
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
return "net" + utils.IntToStr(time.Now().UnixNano())
|
return "net" + utils.IntToStr(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUniqueQEMUDriveID() string {
|
func getUniqueQEMUDriveID() string {
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
return "drive" + utils.IntToStr(time.Now().UnixNano())
|
return "drive" + utils.IntToStr(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,28 +58,31 @@ func cleanQEMUPath(s string) string {
|
||||||
func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg, error) {
|
func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg, error) {
|
||||||
baseCmd := "qemu-system"
|
baseCmd := "qemu-system"
|
||||||
|
|
||||||
if osspecifics.IsWindows() {
|
|
||||||
baseCmd += ".exe"
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []qemucli.Arg{
|
args := []qemucli.Arg{
|
||||||
qemucli.MustNewStringArg("serial", "stdio"),
|
qemucli.MustNewStringArg("serial", "stdio"),
|
||||||
qemucli.MustNewUintArg("m", cfg.MemoryAlloc),
|
qemucli.MustNewUintArg("m", cfg.MemoryAlloc),
|
||||||
qemucli.MustNewUintArg("smp", runtime.NumCPU()),
|
qemucli.MustNewUintArg("smp", runtime.NumCPU()),
|
||||||
}
|
}
|
||||||
|
|
||||||
var accel string
|
var accel []qemucli.KeyValueArgItem
|
||||||
switch {
|
switch {
|
||||||
case osspecifics.IsWindows():
|
case osspecifics.IsWindows():
|
||||||
// TODO: To document: For Windows, we need to install QEMU using an installer and add it to PATH.
|
// TODO: To document: For Windows, we need to install QEMU using an installer and add it to PATH.
|
||||||
// Then, we should enable Windows Hypervisor Platform in "Turn Windows features on or off".
|
// Then, we should enable Windows Hypervisor Platform in "Turn Windows features on or off".
|
||||||
// IMPORTANT: We should also install libusbK drivers for USB devices we want to pass through.
|
// IMPORTANT: We should also install libusbK drivers for USB devices we want to pass through.
|
||||||
// This can be easily done with a program called Zadiag by Akeo.
|
// This can be easily done with a program called Zadiag by Akeo.
|
||||||
accel = "whpx,kernel-irqchip=off"
|
accel = []qemucli.KeyValueArgItem{
|
||||||
|
{Key: "whpx"},
|
||||||
|
{Key: "kernel-irqchip", Value: "off"},
|
||||||
|
}
|
||||||
case osspecifics.IsMacOS():
|
case osspecifics.IsMacOS():
|
||||||
accel = "hvf"
|
accel = []qemucli.KeyValueArgItem{{
|
||||||
|
Key: "hvf",
|
||||||
|
}}
|
||||||
default:
|
default:
|
||||||
accel = "kvm"
|
accel = []qemucli.KeyValueArgItem{{
|
||||||
|
Key: "kvm",
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch runtime.GOARCH {
|
switch runtime.GOARCH {
|
||||||
|
|
@ -102,7 +107,7 @@ func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg,
|
||||||
return "", nil, fmt.Errorf("arch '%v' is not supported", runtime.GOARCH)
|
return "", nil, fmt.Errorf("arch '%v' is not supported", runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, qemucli.MustNewStringArg("accel", accel))
|
args = append(args, qemucli.MustNewKeyValueArg("accel", accel))
|
||||||
|
|
||||||
if cfg.BIOSPath != "" {
|
if cfg.BIOSPath != "" {
|
||||||
biosPath := cleanQEMUPath(cfg.BIOSPath)
|
biosPath := cleanQEMUPath(cfg.BIOSPath)
|
||||||
|
|
@ -130,6 +135,10 @@ func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg,
|
||||||
args = append(args, cdromArg, qemucli.MustNewStringArg("boot", "d"))
|
args = append(args, cdromArg, qemucli.MustNewStringArg("boot", "d"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if osspecifics.IsWindows() {
|
||||||
|
baseCmd += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
return baseCmd, args, nil
|
return baseCmd, args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func (fm *FileManager) luksOpen(sc *ssh.Client, fullDevPath string) error {
|
||||||
return errors.Wrap(err, "write prompt to stderr")
|
return errors.Wrap(err, "write prompt to stderr")
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd, err := term.ReadPassword(syscall.Stdin)
|
pwd, err := term.ReadPassword(int(syscall.Stdin))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "read luks password")
|
return errors.Wrap(err, "read luks password")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue