Skip to content

Commit

Permalink
test: add an option to boot from an USB stick
Browse files Browse the repository at this point in the history
Emulates a boot from a USB stick.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Dec 12, 2024
1 parent ef8c3e3 commit 3e9e027
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var (
nodeVmlinuzPath string
nodeInitramfsPath string
nodeISOPath string
nodeUSBPath string
nodeDiskImagePath string
nodeIPXEBootScript string
applyConfigEnabled bool
Expand Down Expand Up @@ -223,6 +224,9 @@ func downloadBootAssets(ctx context.Context) error {
{
path: &nodeISOPath,
},
{
path: &nodeUSBPath,
},
{
path: &nodeDiskImagePath,
},
Expand Down Expand Up @@ -462,6 +466,7 @@ func create(ctx context.Context) error {
KernelPath: nodeVmlinuzPath,
InitramfsPath: nodeInitramfsPath,
ISOPath: nodeISOPath,
USBPath: nodeUSBPath,
IPXEBootScript: nodeIPXEBootScript,
DiskImagePath: nodeDiskImagePath,

Expand Down Expand Up @@ -1239,6 +1244,7 @@ func init() {
createCmd.Flags().StringVar(&nodeInstallImage, nodeInstallImageFlag, helpers.DefaultImage(images.DefaultInstallerImageRepository), "the installer image to use")
createCmd.Flags().StringVar(&nodeVmlinuzPath, "vmlinuz-path", helpers.ArtifactPath(constants.KernelAssetWithArch), "the compressed kernel image to use")
createCmd.Flags().StringVar(&nodeISOPath, "iso-path", "", "the ISO path to use for the initial boot (VM only)")
createCmd.Flags().StringVar(&nodeUSBPath, "usb-path", "", "the USB stick image path to use for the initial boot (VM only)")
createCmd.Flags().StringVar(&nodeInitramfsPath, "initrd-path", helpers.ArtifactPath(constants.InitramfsAssetWithArch), "initramfs image to use")
createCmd.Flags().StringVar(&nodeDiskImagePath, "disk-image-path", "", "disk image to use")
createCmd.Flags().StringVar(&nodeIPXEBootScript, "ipxe-boot-script", "", "iPXE boot script (URL) to use")
Expand Down
12 changes: 10 additions & 2 deletions pkg/provision/providers/qemu/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type LaunchConfig struct {
KernelImagePath string
InitrdPath string
ISOPath string
USBPath string
ExtraISOPath string
PFlashImages []string
KernelArgs string
Expand Down Expand Up @@ -439,12 +440,19 @@ func launchVM(config *LaunchConfig) error {
}

if !diskBootable || !config.BootloaderEnabled {
if config.ISOPath != "" {
switch {
case config.ISOPath != "":
args = append(args,
"-drive",
fmt.Sprintf("file=%s,media=cdrom", config.ISOPath),
)
} else if config.KernelImagePath != "" {
case config.USBPath != "":
args = append(args,
"-drive", fmt.Sprintf("if=none,id=stick,format=raw,file=%s", config.USBPath),
"-device", "nec-usb-xhci,id=xhci",
"-device", "usb-storage,bus=xhci.0,drive=stick,removable=on",
)
case config.KernelImagePath != "":
args = append(args,
"-kernel", config.KernelImagePath,
"-initrd", config.InitrdPath,
Expand Down
1 change: 1 addition & 0 deletions pkg/provision/providers/qemu/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func (p *provisioner) createNode(state *vm.State, clusterReq provision.ClusterRe
launchConfig.KernelImagePath = strings.ReplaceAll(clusterReq.KernelPath, constants.ArchVariable, opts.TargetArch)
launchConfig.InitrdPath = strings.ReplaceAll(clusterReq.InitramfsPath, constants.ArchVariable, opts.TargetArch)
launchConfig.ISOPath = strings.ReplaceAll(clusterReq.ISOPath, constants.ArchVariable, opts.TargetArch)
launchConfig.USBPath = strings.ReplaceAll(clusterReq.USBPath, constants.ArchVariable, opts.TargetArch)
}

launchConfig.StatePath, err = state.StatePath()
Expand Down
1 change: 1 addition & 0 deletions pkg/provision/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ClusterRequest struct {
KernelPath string
InitramfsPath string
ISOPath string
USBPath string
DiskImagePath string
IPXEBootScript string

Expand Down
1 change: 1 addition & 0 deletions website/content/v1.9/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ talosctl cluster create [flags]
--skip-kubeconfig skip merging kubeconfig from the created cluster
--talos-version string the desired Talos version to generate config for (if not set, defaults to image version)
--talosconfig string The path to the Talos configuration file. Defaults to 'TALOSCONFIG' env variable if set, otherwise '$HOME/.talos/config' and '/var/run/secrets/talos.dev/config' in order.
--usb-path string the USB stick image path to use for the initial boot (VM only)
--use-vip use a virtual IP for the controlplane endpoint instead of the loadbalancer
--user-disk strings list of disks to create for each VM in format: <mount_point1>:<size1>:<mount_point2>:<size2>
--vmlinuz-path string the compressed kernel image to use (default "_out/vmlinuz-${ARCH}")
Expand Down

0 comments on commit 3e9e027

Please sign in to comment.