How to create a DietPi image for VirtualBox - MichaIng/DietPi GitHub Wiki

Download and install the later VirtualBox for your OS

Create and prepare the VM from VirtualBox GUI

  • Machine > New: Name: DietPi_VirtualBox-x86_64-Bullseye, Type: Linux, Version: Debian (64-bit)
  • Memory size: 1024 MB (default, can be easily adjusted later)
  • Create a virtual hard disk now => Create
  • File size: 8 GB (default, can be easily adjusted later)
  • VDI default native VirtualBox format, as this can be enlarged, compacted and converted better with VirtualBox tools
  • Dynamically allocated to reduce initial disk size. For best performance it could be beneficial to choose Fixed size on end machine. But especially when sharing the image through the web, for transfer, packing and unpacking this is not recommended. => Create
  • Select the new machine and Settings > System > Motherboard
  • Deselect Floppy
  • Chipset: ICH9, the modern one, supporting USB2+3, I never had issues with it
  • Pointing device: PS/2 Mouse, which allows disabling USB, although we leave USB enabled to allow live mounting on first boot
  • Display > Display Memory: 16 MB as default for initial headless server
  • Disable Audio and USB (https://github.com/Fourdee/DietPi/issues/2093#issuecomment-423964511) as default.
  • Network > Attached to: Bridged Adapter to allow local SSH, Advanced > Adapter Type: virtio-net, for best performance.

Download installer image

Mount image to machine

  • In case remove the dedicated IDE controller and add an optical drive to the existing SATA controller.
  • Mount/Select the downloaded iso file to this optical drive.
  • Start the VM.

Debian installer

  • NB: The following steps can be automated, however the effort on netboot installers is too high to have any benefit over manually going through the installation for a single VM: https://www.debian.org/releases/stable/amd64/apbs01.html.en#preseed-methods
  • Advanced options > Expert install
  • Choose language > English > United Kingdom > en_GB.UTF-8 > continue (select NO additional locales, any UTF-8 locale will work which is only important to have the correct console-setup character map right from the start.)
  • Configure the keyboard > British English
  • Detect network hardware
  • Deselect any Modules to load as we don't require them.
  • Configure the network > Yes (auto-configure) > hit return
  • Hostname: DietPi
  • Domain name: <leave empty>
  • APT mirror: Just use one near to your location or deb.debian.org. It will be overwritten anyway by DietPi-PREP, as actually most other settings as well 😉.
  • Debian version to install: bullseye - stable
  • Download installer components: deselect everything > Continue
  • Set up users > Enable shadow passwords? Yes > Allow login as root? Yes > Root password: dietpi
  • Create a normal user account now? No
  • Configure the clock > Use NTP? Yes > leave default mirror 0.debian.pool.ntp.org > time zone: UTC
  • Detect disks > Deselect any Modules to load > Partition discs > Manual > Select the drive > Create new empty partition table? Yes > msdos > Select the FREE SPACE > Create a new partition > New partition size: max > Primary
  • Verify: Ext4 and mount point / > Done setting up the partition > Finish partitioning > No return due to missing swap partition > Yes write to disk
  • Install the base system
  • Select kernel package: linux-image-amd64
  • Select targeted since no generic driver installation is required for virtual machines.
  • Configure the package manager > No nonfree, contrib and especially No source repository!
  • Select security/updates, backports are not required yet. This will be reset anyway during DietPi-PREP.
  • Select and install software > No virtualbox-guest extension > No automatic updates and No survey (user should decide this oneself later)
  • Deselect all additional software
  • Install the GRUB boot loader > Yes to master boot record > to the only available partition (/dev/sda) > Not to the EFI removable media path, actually no idea why it detects EFI, as it was not selected on machine and is definitely not available afterwards...
  • Finish the installation > set to UTC? Yes
  • BEFORE Continue: Unplug the optical drive (context menu on ROM symbol at button, Remove disc > Force removal!), to prevent reboot into installer > Continue

DietPi-PREP

  • Login as root:dietpi
  • apt update; apt install -y ca-certificates curl dropbear
  • Connect via SSH (IP: ip a) for easier copy&paste etc.
    bash -c "$(curl -sSfL 'https://raw.githubusercontent.com/MichaIng/DietPi/master/.build/images/dietpi-installer')"
    
  • Git branch: master
  • Enter your name to be shown as image creator within DietPi banner credits.
  • Enter Debian mini.iso as this was our base image above.
  • Device: 20 : x86_64 Virtual Machine
  • Deselect WLAN functionality for VMs as they virtualise Ethernet adapters for network only.
  • Distro version: 6: Bullseye
  • shutdown now

Image export and packaging

  • Mount virtual drive (vdi) to another Linux system or virtual machine, use zerofree -v /dev/sdx1 to reduce the final image size. In case: apt -y install zerofree
  • To reduce the actual image file size as well (which does not affect the exported appliance/download size), run:
    VBoxManage modifyhd --compact "[drive]:\[path_to_image_file]\DietPi_VirtualBox-x86_64-Bullseye.vdi"
    
  • Additionally might want to remove your default Bridged Network host adapter. For this, close VirtualBox, open DietPi_VirtualBox-x86_64-Bullseye.vbox (and remove DietPi_VirtualBox-x86_64-Bullseye.vbox-prev and Logs) and change the similar line to <BridgedInterface name="eth0"/>. As there is no way to keep the bridged networking setting without saving a certain interface name as well, and eth0 is at least the most general one that will fit for most Linux hosts. All others will face an error message and the option to adjust the interface to an available one. No bid deal, no better way to handle this. After editing the files, you MUST NOT open the VMs settings any more, otherwise it will insert your available interface again. Directly open the top menu to export the appliance first.
  • Export the whole appliance with OVF 1.0 format for compatibility reasons.
  • MAC Address Policy: Strip all network adapter MAC addresses
  • Create hashes, e.g. using HashMyFiles, saving the report to hash.txt.
  • Download the current README.md
  • Pack VM export file(s) + hash.txt + README.md with 7zip for high compression rate to DietPi_VirtualBox-x86_64-Bullseye.7z.