Machine Creation

I don't like GUIs, clicking is too prone to errors. And I do not want to have virtual disks mixed up in one directory, so I use:

_setup_vboxName="SomeMachineName" _setup_vboxDir="${HOME}/MyFavoriteVirtualBoxMachineDir/${_setup_vboxName}" mkdir -p -- "${_setup_vboxDir}" # Select instance type, see VBoxManage list ostypes # Does not work with newer vbox? Use --basefolder [dir] vboxmanage createvm --name "${_setup_vboxName}" --ostype Ubuntu --basefolder "${_setup_vboxDir}/.." mv -i -- "${_setup_vboxDir}/${_setup_vboxName}.vbox" "${_setup_vboxDir}/Instance.xml" < /dev/null # On older vbox variants (lucid and before) the --settingsfile was working, # the two lines from above could be replaced by # vboxmanage createvm --name "${_setup_vboxName}" --ostype Ubuntu --settingsfile "${_setup_vboxDir}/Instance.xml" vboxmanage registervm "${_setup_vboxDir}/Instance.xml" # Remove macaddress1 if autogenerated mac is sufficient vboxmanage modifyvm "${_setup_vboxName}" --memory 256 --rtcuseutc on --nic1 hostonly --nictype1 Am79C973 --macaddress1 00505605xxxx --hostonlyadapter1 vboxnet0 vboxmanage modifyvm "${_setup_vboxName}" --audio alsa --audiocontroller ac97 vboxmanage storagectl "${_setup_vboxName}" --name LsiLogic --add scsi --controller LsiLogic vboxmanage createhd --filename "${_setup_vboxDir}/Root.vdi" --format VDI --size 4096 vboxmanage storageattach "${_setup_vboxName}" --storagectl LsiLogic --port 0 --device 0 --type hdd --medium "${_setup_vboxDir}/Root.vdi" # Add a distinct swap disk, that can be reset or ignored in backups vboxmanage createhd --filename "${_setup_vboxDir}/Swap.vdi" --format VDI --size 512 vboxmanage storageattach "${_setup_vboxName}" --storagectl LsiLogic --port 1 --device 0 --type hdd --medium "${_setup_vboxDir}/Swap.vdi" # Add a cdrom drive vboxmanage storagectl "${_setup_vboxName}" --name PIIX4 --add ide --controller PIIX4 vboxmanage storageattach "${_setup_vboxName}" --storagectl PIIX4 --port 0 --device 0 --type dvddrive --medium "${HOME}/PathToSetupMedium.iso" # Add usb if needed vboxmanage modifyvm "${_setup_vboxName}" --usb on --usbehci on

Running, Debugging

Use Magic Sysrq-key in guest:

Magic Sysrq is a great aid for interaction with otherwise inaccessible linux machines (machines, where remote shell still available, echo s > /proc/sysrq-trigger can be used instead). With virtualbox, the magic sysrq key sequence cannot be sent to guest since it is always interpreted by the host. But the sysrq sequence can be sent using the management interface, e.g.
VBoxManage controlvm [vbox-name] keyboardputscancode 1d 38 54 [request type press/release] d4 b8 9d
The request-type press/release hex code is the scancode of the sysrq code letter plus the scancode|0x80 for key release, e.g.

See https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html section 1.4 for complete list of scancodes. Caveat: The scancode deplends on your keyboard layout, the codes here correspond to a standard QUERTZ-layout.

Extract physical memory from guest:

VirtualBox does not support direct access to physical memory of the guest. I use the term physical memory because that it is called in the intel processor specification. The data extracted that way is just the flat memory independent of segmentation unit or paging information from the processor state. This memory content can be extracted that way:

VBoxManage debugvm TestVm dumpguestcore --filename guest.dump gdb --core guest.dump # dump memory [phys-mem-file] 0x0 [size vm-memory]

One may then just search the memory dump for known strings and data or use the processor state to reconstruct the paging/segmentation information. Therefore the content of all registers has to be dumped, e.g.

VBoxManage debugvm TestVm getregisters all

After that, when virtual CPU is in protected mode, one can use cpu0.cr3 (page table base pointer) containing the physical address of the currently active page table. With page table and global descriptor table register, current state of vm program can be reconstructed. See also section memory management in Intel system programming guide.

Last modified 20171228
Contact e-mail: me (%) halfdog.net