Add --download-only to the VM launchers
The option downloads the media a launcher would fetch automatically and exits without checking for QEMU, creating a VM disk or starting the VM: the base image for Debian, AlmaLinux and Fedora, and the VirtIO tools ISO for Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YKxXLyiL7XJ3a9e8HmR2my
This commit is contained in:
1 parent
7912a1549e
commit
204051f930
5 files changed
+80
-21
No files matched your search
+35
-9
@@ -36,6 +36,18 @@ def is_executable(path):
|
||||
return path.is_file() and os.access(path, os.X_OK)
|
||||
|
||||
|
||||
def find_image_downloader():
|
||||
if env("VM_IMAGE_HELPER"):
|
||||
image_downloader = Path(env("VM_IMAGE_HELPER"))
|
||||
elif is_executable(script_dir / "vm-images" / "download-images.sh"):
|
||||
image_downloader = script_dir / "vm-images" / "download-images.sh"
|
||||
else:
|
||||
image_downloader = script_dir / ".." / "vm-images" / "download-images.sh"
|
||||
if not is_executable(image_downloader):
|
||||
die(f"shared image helper is unavailable: {image_downloader}")
|
||||
return image_downloader
|
||||
|
||||
|
||||
state_dir = Path(env("WIN11_VM_STATE_DIR") or script_dir / ".vm" / "windows11")
|
||||
disk_size = env("WIN11_VM_DISK_SIZE") or "64G"
|
||||
memory = env("WIN11_VM_MEMORY") or "8G"
|
||||
@@ -69,12 +81,13 @@ uefi_vars_template = pick_firmware(
|
||||
)
|
||||
daemonize = False
|
||||
install_from_iso = False
|
||||
download_only = False
|
||||
extra_args = []
|
||||
|
||||
|
||||
def usage(stream=sys.stdout):
|
||||
stream.write(f"""\
|
||||
Usage: {Path(sys.argv[0]).name} [--daemon] [--install-from-iso] [--state-dir DIR] [-- QEMU_ARGUMENT ...]
|
||||
Usage: {Path(sys.argv[0]).name} [--daemon] [--download-only] [--install-from-iso] [--state-dir DIR] [-- QEMU_ARGUMENT ...]
|
||||
|
||||
If the system disk (DIR/disk.qcow2, see --state-dir) is missing, create it from
|
||||
the Windows 11 QCOW2 base image.
|
||||
@@ -83,6 +96,8 @@ If it exists, start Windows normally without attaching installation media.
|
||||
|
||||
Options:
|
||||
--daemon Run QEMU in the background
|
||||
--download-only Download the VirtIO tools ISO if it is missing, then exit
|
||||
(the Windows ISO and base QCOW2 are supplied manually)
|
||||
--install-from-iso Install from ISO when the system disk is missing
|
||||
--state-dir DIR Directory for the VM disk, seed ISO and runtime files
|
||||
(default: .vm/windows11; overrides WIN11_VM_STATE_DIR)
|
||||
@@ -111,6 +126,8 @@ while args:
|
||||
arg = args.pop(0)
|
||||
if arg == "--daemon":
|
||||
daemonize = True
|
||||
elif arg == "--download-only":
|
||||
download_only = True
|
||||
elif arg == "--install-from-iso":
|
||||
install_from_iso = True
|
||||
elif arg == "--state-dir":
|
||||
@@ -130,6 +147,22 @@ while args:
|
||||
usage(sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
if download_only:
|
||||
# The VirtIO tools ISO is the only medium the launcher downloads itself.
|
||||
if env("WIN11_VM_TOOLS_ISO"):
|
||||
tools_iso = Path(env("WIN11_VM_TOOLS_ISO"))
|
||||
if not tools_iso.is_file():
|
||||
die(f"VirtIO Windows tools ISO was not found: {tools_iso}")
|
||||
else:
|
||||
image_downloader = find_image_downloader()
|
||||
tools_iso = Path(capture([str(image_downloader), "--print-path", "virtio-win"]))
|
||||
if not tools_iso.is_file():
|
||||
run([str(image_downloader), "virtio-win"])
|
||||
if not tools_iso.is_file():
|
||||
die(f"downloader did not create: {tools_iso}")
|
||||
print(f"VirtIO Windows tools ISO is ready: {tools_iso}")
|
||||
sys.exit(0)
|
||||
|
||||
disk_image = Path(env("WIN11_VM_DISK_IMAGE") or state_dir / "disk.qcow2")
|
||||
seed_iso = Path(env("WIN11_VM_SEED_ISO") or disk_image.parent / "seed.iso")
|
||||
uefi_vars = state_dir / "OVMF_VARS_4M.fd"
|
||||
@@ -143,14 +176,7 @@ installing_from_iso = False
|
||||
if not disk_image.is_file():
|
||||
installing = True
|
||||
installing_from_iso = install_from_iso
|
||||
if env("VM_IMAGE_HELPER"):
|
||||
image_downloader = Path(env("VM_IMAGE_HELPER"))
|
||||
elif is_executable(script_dir / "vm-images" / "download-images.sh"):
|
||||
image_downloader = script_dir / "vm-images" / "download-images.sh"
|
||||
else:
|
||||
image_downloader = script_dir / ".." / "vm-images" / "download-images.sh"
|
||||
if not is_executable(image_downloader):
|
||||
die(f"shared image helper is unavailable: {image_downloader}")
|
||||
image_downloader = find_image_downloader()
|
||||
if install_from_iso:
|
||||
install_iso = Path(env("WIN11_VM_INSTALL_ISO")
|
||||
or capture([str(image_downloader), "--print-path", "windows11", "--iso"]))
|
||||
|
||||
Reference in new issue
Block a user