../debian-virtualbox-install-guide

Installing Debian in VirtualBox: A Step-by-Step Guide

This post will be short, but I've tried to compensate by including several screenshots. We will cover how to create a virtual machine and install Debian OS using VirtualBox. I'll describe two methods for installing Debian: a guided installation where you specify your preferences during the process, and an unattended installation where you predefine those preferences in a configuration file for the OS installation.

Create the Virtual Machine

Before installing any OS, we need to create the VM in which it will run. The first step is to download the operating system's CD ISO image file, which we'll use for the installation. To replicate the setup from our previous post, we'll use the same bullseye version. Download the debian-11.11.0-amd64-netinst.iso image. Optionally, download the SHA256SUMS file to verify the integrity of the downloaded image using checksums.

You can use the following command to download both files.

curl --location --remote-name-all "https://cdimage.debian.org/cdimage/archive/11.11.0/amd64/iso-cd/{debian-11.11.0-amd64-netinst.iso,SHA256SUMS}"

The following command can be used to check the disk image integrity.

sha256sum --check --ignore-missing SHA256SUMS

Once you've downloaded the files and verified their integrity, open VirtualBox and create the virtual machine.

Button to create a virtual machine

A pop-up window will appear, prompting you to create the virtual machine. In this window, select "Linux" as the type, "Debian (64-bit)" as the version, and the "Create a virtual hard disk now" option. You can choose any name you like. While the minimum required memory is "256 MiB", consider allocating at least "512 MiB" or even "1024 MiB" if you plan to run containers.

Pop-up to create virtual machine

Next, a pop-up window will appear to create the virtual hard drive. Select "VDI (VirtualBox Disk Image)" and "Dynamically allocated". Again, you can choose any name you prefer. Because the disk is dynamically allocated, the file size can be set to the recommended "30 GiB". For reference, the disk space used by the installation in this post was approximately 900 MiB.

Pop-up to create virtual hard disk

Once the virtual machine is created, ensure that the virtual network interface is enabled. To do this, select the virtual machine, click the "Settings" button, and go to the "Network" section. Check the box to enable network adapter #1 and select the desired network mode. "NAT" is generally a safe choice. If you select "NAT", also configure port forwarding from host port 2222 to guest port 22 to enable access via SSH.

Virtual machine network settings

The final step before OS installation is to load the CD image. In the settings pop-up window, navigate to the "Storage" section. For the empty IDE device, click the CD icon to load the disk image file you downloaded earlier.

Virtual machine load disk image file

Once the image is loaded, the IDE device will display the name of the disk image file.

Virtual machine CD ISO loaded

With the preceding steps completed, the virtual machine is ready for the OS installation. Start the VM and choose your preferred installation method: guided or unattended.

Guided Installation

The guided installation is straightforward but requires careful attention to select the correct options at each step. Below is a summary of the steps, followed by screenshots for reference.

Guided install: Select option Install

Guided install: Select language

Guided install: Select location

Guided install: Configure keyboard

Guided install: Set host name

Guided install: Set domain name

Guided install: Set root password

Guided install: Set user full name

Guided install: Set user name

Guided install: Set partitioning method

Guided install: Select disk to partition

Guided install: Select partitioning scheme

Guided install: Confirm partitioning

Guided install: Confirm write changes to disk

Guided install: Installation progress bar

Guided install: Scan extra installation media

Guided install: Set archive mirror country

Guided install: Set archive mirror domain name

Guided install: Set package manager proxy

Guided install: Select software to install

Guided install: Confirm boot loader installation

Guided install: Select device for boot loader

Guided install: Installation complete

Guided install: Select OS to boot

Guided install: Log in with user and ping Google

Unattended Installation

The unattended installation offers a faster approach, requiring a preconfiguration file with the settings you would normally choose interactively. You can find an example of such a file here. This file is required before starting the installation. Once started, the process is fully automated: you won't need to interact with it until the installation completes, the virtual machine restarts, and you see the login prompt. If you're interested, I've uploaded the preseed file that I used for this post.

For more information, consult the official Preseed documentation. Note that while pre-seeding from a floppy disk is listed as an option, it doesn't work.

Below is a summary of the unattended installation steps, followed by screenshots for reference.

adduser admin

Unattended install: Select advanced options

Unattended install: Select automated install

Unattended install: Set URL to preseed file

Unattended install: Installation progress bar

Unattended install: Select OS to boot

Unattended install: Log in with root and create admin user

System Setup

After either installation method, I recommend installing sudo to simplify system administration tasks. Assuming you're logged in as the admin user via SSH, switch to the root user with:

su -

Next, update the package repository, install "sudo", add the admin user to the "sudo" group, and configure the system to allow password-less execution of commands for members of this group. Below is the command to accomplish this, followed by a screenshot for reference.

apt update && \
apt install --no-install-recommends sudo && \
adduser admin sudo && \
sed -i -e 's/^%sudo.*/%sudo ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers

Install and setup sudo

Now you can install any applications you need. I suggest reviewing the recommended apps that were installed in the previous post.

Virtual Hard Disk Backup

As a final step, let's back up the virtual hard drive. This allows you to quickly create a new virtual machine with a fresh Debian installation if something goes wrong, or to share the disk backup with others. Below are the commands I used. Remember to adapt these commands to your specific file locations and names. This will result in a "VDI" file compressed with bzip2.

cd ~/VirtualBox \VMs/sandbox/
bzip2 --keep sandbox.vdi
mv sandbox.vdi.bz2 /path/to/backup/disk/image/

Wrapping Up

Well done! You've successfully installed Debian in VirtualBox. Now you have a virtual environment where you can safely experiment with the command line, explore the GNU/Linux ecosystem, and set up your development tools. I hope this tutorial has been a valuable resource for you. Happy hacking!

Take care and until next time!