LUKS support touchups

This commit is contained in:
AlexSSD7 2023-09-01 12:40:13 +01:00
commit 598234d161
5 changed files with 44 additions and 20 deletions

View file

@ -1,6 +1,7 @@
package cmd
import (
"fmt"
"os"
"path/filepath"
"runtime"
@ -26,12 +27,19 @@ func Execute() {
}
}
var vmDebugFlag bool
var unrestrictedNetworkingFlag bool
var vmMemAllocFlag uint32
var vmSSHSetupTimeoutFlag uint32
var vmOSUpTimeoutFlag uint32
var dataDirFlag string
var (
vmDebugFlag bool
unrestrictedNetworkingFlag bool
vmMemAllocFlag uint32
vmSSHSetupTimeoutFlag uint32
vmOSUpTimeoutFlag uint32
dataDirFlag string
)
const (
defaultMemAlloc = 512
defaultMemAllocLUKS = 2048
)
func init() {
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
@ -45,7 +53,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.")
rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.")
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", 512, "Specifies the VM memory allocation in KiB")
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB (the default is %v in LUKS mode)", defaultMemAllocLUKS))
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
rootCmd.PersistentFlags().Uint32Var(&vmSSHSetupTimeoutFlag, "vm-ssh-setup-timeout", 60, "Specifies the VM SSH server setup timeout in seconds. This cannot be lower than the OS-up timeout.")

View file

@ -45,6 +45,15 @@ var runCmd = &cobra.Command{
os.Exit(1)
}
if luksFlag && !allowLUKSLowMemoryFlag {
if vmMemAllocFlag < 2048 {
if vmMemAllocFlag != defaultMemAlloc {
slog.Warn("Enforcing minimum LUKS memory allocation. Please add --allow-luks-low-memory to disable this.", "min", vmMemAllocFlag, "specified", vmMemAllocFlag)
}
vmMemAllocFlag = defaultMemAllocLUKS
}
}
os.Exit(runVM(args[0], func(ctx context.Context, i *vm.VM, fm *vm.FileManager, tapCtx *share.NetTapRuntimeContext) int {
slog.Info("Mounting the device", "dev", vmMountDevName, "fs", fsType, "luks", luksFlag)
@ -83,14 +92,18 @@ var runCmd = &cobra.Command{
},
}
var luksFlag bool
var shareListenIPFlag string
var ftpExtIPFlag string
var shareBackendFlag string
var smbUseExternAddrFlag bool
var (
luksFlag bool
allowLUKSLowMemoryFlag bool
shareListenIPFlag string
ftpExtIPFlag string
shareBackendFlag string
smbUseExternAddrFlag bool
)
func init() {
runCmd.Flags().BoolVarP(&luksFlag, "luks", "l", false, "Use cryptsetup to open a LUKS volume (password will be prompted).")
runCmd.Flags().BoolVar(&allowLUKSLowMemoryFlag, "allow-luks-low-memory", false, "Allow VM memory allocation lower than 2048 MiB when LUKS is enabled.")
var defaultShareType string
switch runtime.GOOS {