### Install and Deploy import2vbox using Make Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt Standard Unix-style installation instructions for the import2vbox script using Make. Supports custom installation prefixes, staged installation for packaging, uninstallation, and running the test suite. ```bash # Install to /usr/local/bin (default) sudo make install # Install to custom prefix sudo make install prefix=/opt/import2vbox # Staged install for packaging (Debian, RPM, etc.) make install DESTDIR=/tmp/package-root prefix=/usr # Uninstall sudo make uninstall # Run test suite make test # Manual installation install -D import2vbox.pl /usr/local/bin/import2vbox chmod +x /usr/local/bin/import2vbox # Verify installation import2vbox --help import2vbox --man # Display full manual ``` -------------------------------- ### Predictable Network Interface Name Conversion (Bash) Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This bash example demonstrates how the import2vbox script handles systemd predictable network interface names (e.g., eno1, ens33) for Debian-based VMs. It converts these names to the traditional eth0 format to ensure network connectivity after the VM is imported into VirtualBox, detailing the steps involved from mounting partitions to updating GRUB. ```bash # Enable network interface conversion for Debian VMs ./import2vbox.pl --no-predictable-nic-names debian-system.vmdk # The script performs the following operations: # 1. Mounts all partitions in the guest filesystem # 2. Scans /etc/network/interfaces for predictable NIC names (eno1, ens33, enp0s3, etc.) # 3. Replaces with eth0 using sed: s/(eno[0-9]|enp?[0-9]?s[0-9])/eth0/ # 4. Updates GRUB configuration: GRUB_CMDLINE_LINUX="net.ifnames=0 ..." # 5. Runs update-grub inside the VM # 6. Syncs and unmounts filesystems # Example /etc/network/interfaces before: # auto ens33 # iface ens33 inet dhcp # After conversion: # auto eth0 # iface eth0 inet dhcp ``` -------------------------------- ### Automated Testing of OVF Generation and VirtualBox Import Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This Perl script integrates with the Test::More framework to automate testing of OVF generation and VirtualBox import processes. It includes steps for downloading test images, generating OVF, importing into VirtualBox, verifying with ovftool, and checking VM configuration. ```perl #!/usr/bin/perl use Test::More tests => 5; # Download test image if not present my $disk = "ubuntu-18.04-minimal-cloudimg-amd64.img"; if (! -f $disk) { system("wget https://cloud-images.ubuntu.com/minimal/releases/bionic/release/$disk"); } # Test OVF generation my $vm_name = 'test_vm'; assert("./import2vbox.pl --vcpus 2 --memory 384 $disk --name $vm_name", 'successfull ovf generation'); # Test VirtualBox import assert("VBoxManage import ${vm_name}.ovf", "VBoxManage import ${vm_name}.ovf"); # Validate OVF with VMware ovftool assert("ovftool --verifyOnly ${vm_name}.ovf", "ovftool --verifyOnly ${vm_name}.ovf"); # Verify VM configuration open my $conf, "-|", "VBoxManage showvminfo $vm_name --machinereadable"; while (<$conf>) { if ($_ =~ m/^storagecontrollerportcount0=\"(.+)\"$/) { ok($1 == 1, "1 SATA port found"); } if ($_ =~ m/^graphicscontroller=\"(.+)\"$/) { ok($1 eq "vmsvga", "Default display set to vmsvga"); } } # Cleanup (unless --keep flag specified) system("VBoxManage unregistervm $vm_name --delete") if !$keep_vbox_vm; unlink "${vm_name}.ovf", "ubuntu-18.vmdk"; sub assert { my ($command, $description) = @_; my $rc = system("$command >/dev/null 2>&1"); ok($rc == 0, $description); } # Run tests: perl test.pl or make test ``` -------------------------------- ### Convert Disk Images to VMDK using qemu-img Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This script converts RAW disk images to VMDK format using the 'qemu-img' utility. VMDK files are passed through without modification. It also includes a check for 'qemu-img' availability. ```bash # Automatic conversion for RAW images ./import2vbox.pl disk.raw # Internally executes: qemu-img convert -p -O vmdk disk.raw disk.vmdk # VMDK files are used directly without conversion ./import2vbox.pl disk.vmdk # Output: "not converting disk.vmdk" # Test qemu-img availability before processing qemu-img create -f qcow2 .test.qcow2 10M >/dev/null # Exits with error if qemu-img not installed # Multiple disk handling ./import2vbox.pl system.raw data.vmdk swap.raw # Converts: system.raw -> system.vmdk, swap.raw -> swap.vmdk # Preserves: data.vmdk (already in VMDK format) ``` -------------------------------- ### OS Type Detection with libguestfs (Perl) Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This Perl code snippet illustrates how to use the libguestfs library to inspect a virtual disk image and detect operating system information. It extracts the OS type, distribution, architecture, and version, which are crucial for mapping to DMTF CIM OSType identifiers for OVF compatibility. ```perl # The script automatically detects OS information: use Sys::Guestfs; my $g = Sys::Guestfs->new(); $g->add_drive_opts($disk, readonly => 0); $g->launch(); my @roots = $g->inspect_os(); my $root = $roots[0]; # Extract OS information my $type = $g->inspect_get_type($root); # "linux" or "windows" my $distro = $g->inspect_get_distro($root); # "debian", "rhel", etc. my $arch = $g->inspect_get_arch($root); # "x86_64", "i386" my $major_version = $g->inspect_get_major_version($root); my $minor_version = $g->inspect_get_minor_version($root); # Example mappings: # RHEL 64-bit -> OSType 80 # Debian 64-bit -> OSType 96 # Windows 7 64 -> OSType "Windows7x64" # Generic Linux -> OSType 101 ``` -------------------------------- ### Import Disk Image to VirtualBox (Bash) Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This snippet demonstrates the basic usage of the import2vbox.pl script to convert VMDK or RAW disk images into VirtualBox OVF packages. It covers single and multi-disk imports, custom resource allocation, and specific handling for Debian systems. The output includes an OVF descriptor and potentially a converted disk image. ```bash # Basic usage: import a single disk image ./import2vbox.pl ubuntu-server.vmdk # Import with custom resource allocation ./import2vbox.pl --vcpus 4 --memory 2048 --name "MyServer" disk.raw # Import multiple disks for a single VM ./import2vbox.pl disk1.vmdk disk2.vmdk disk3.vmdk --name "MultiDiskVM" # Import Debian VM with network interface name conversion ./import2vbox.pl --no-predictable-nic-names debian-9.vmdk --name "DebianVM" # After import, load into VirtualBox VBoxManage import MyServer.ovf # Expected output files: # - MyServer.ovf (OVF descriptor file) # - disk.vmdk (converted disk if input was RAW format) ``` -------------------------------- ### OVF XML Generation with VirtualBox Extensions (Perl) Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt This Perl code snippet shows how the import2vbox script uses the XML::Writer module to generate OVF 1.0 compliant XML. It includes VirtualBox-specific extensions within the `` element to define hardware configurations such as CPU, memory, storage controllers (AHCI), and network adapters (E1000), ensuring compatibility with VirtualBox. ```perl use XML::Writer; my $ovf_ns = "http://schemas.dmtf.org/ovf/envelope/1"; my $vbox_ns = "http://www.virtualbox.org/ovf/machine"; my $rasd_ns = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"; my $w = XML::Writer->new( OUTPUT => $ovf, NAMESPACES => 1, PREFIX_MAP => %prefix_map, DATA_MODE => 1, DATA_INDENT => 4 ); # VirtualHardwareSection defines CPU, memory, storage, network # Example: 2 vCPUs, 1024 MB RAM # Item ResourceType="3" -> CPU # Item ResourceType="4" -> Memory (byte * 2^20) # Item ResourceType="20" ResourceSubType="AHCI" -> SATA Controller # Item ResourceType="10" ResourceSubType="E1000" -> Network Adapter # Item ResourceType="17" -> Disk drives # VirtualBox-specific machine descriptor for compatibility # # # # # # # # # # # # ``` -------------------------------- ### Query OS Type Definitions using os_types Perl Module Source: https://context7.com/emmanuelkasper/import2vbox/llms.txt A helper utility to query DMTF OS type definitions. It uses the 'os_types' Perl module to retrieve OS information based on its ID, returning details like the DMTF name and PVE type. ```perl #!/usr/bin/perl use warnings; use strict; # Query OS type by ID use os_types; # Get Debian 64-bit OS information my $debian = get_os_by('id', 96); # Returns: { id => 96, dtmf_name => 'Debian 64-Bit' } # Available OS types include: # - Linux distributions: RHEL (79/80), Debian (95/96), Ubuntu (93/94), SUSE, CentOS # - Windows: XP (67), 2003 (69/70), 2008 (76/77), 7 (105), 8 (113/114), 2012 (112/115) # - Unix variants: FreeBSD (42/78), Solaris (29/81), OpenBSD (65) # - Other: MacOS (2), AIX (9), HP-UX (8), QNX (48) if (defined $debian) { my $pve_type = $debian->{pve_type} || "other os"; print $pve_type; # Output: "Linux" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.