DEV Community

阿豪
阿豪

Posted on

Complete Guide to OpenWrt in VirtualBox: Setup and Disk Expansion

Default OpenWrt images have limited storage space. For development and testing, use pre-expanded images from openwrt-virtualbox-build.

Recommended: openwrt-24.10.4-x86-64-generic-ext4-combined.img.vdi

The ext4 filesystem allows post-installation expansion if you need more space later.

Pre-Configuration: Network Setup

Critical: Configure networking before the first boot, or OpenWrt won't have internet access.

Configure VirtualBox Host-Only Network

  1. Open VirtualBox → FileHost Network Manager
  2. Note the adapter IP (default: 192.168.56.1)
  3. In the DHCP Server tab, uncheck "Enable Server"

This prevents IP conflicts between VirtualBox's DHCP and OpenWrt's network configuration.

Creating the Virtual Machine

Basic Settings

  • OS Type: Linux 2.6
  • OS Version: Linux 2.6 (64-bit)
  • Memory: 4096 MB
  • CPU Cores: 4

Attach the Disk

When prompted for a hard disk, select "Use an existing virtual hard disk file" and choose the downloaded .vdi file.

Network Configuration

Configure two network adapters:

  • Adapter 1: Host-Only Adapter (for management access from host)
  • Adapter 2: Bridged Adapter (for internet access)

First Boot Configuration

Set Root Password

After booting, immediately set the administrator password:

passwd
Enter fullscreen mode Exit fullscreen mode

Configure Static IP

Set OpenWrt's IP to match your host-only network range (192.168.56.2-255). Choose a higher number to avoid conflicts:

uci set network.lan.ipaddr=192.168.56.66
uci commit
reboot
Enter fullscreen mode Exit fullscreen mode

The system will reboot with the new IP address.

Setting Up SSH Key Authentication

Generate SSH Key on Host

If you don't already have an SSH key:

ssh-keygen -t rsa
Enter fullscreen mode Exit fullscreen mode

Save it with a descriptive name like ~/.ssh/openwrt.

Add Public Key to OpenWrt

Option 1: Web UI

  1. Navigate to http://192.168.56.66
  2. Go to SystemAdministrationSSH-Keys
  3. Paste the contents of your ~/.ssh/openwrt.pub file
  4. Click Add Key

Option 2: Command Line

OpenWrt uses Dropbear SSH server, which stores keys in a different location:

cat ~/.ssh/openwrt.pub | ssh root@192.168.56.66 "cat > /etc/dropbear/authorized_keys"
Enter fullscreen mode Exit fullscreen mode

Note: The standard ~/.ssh/authorized_keys path won't work with Dropbear.

Connect via SSH

ssh root@192.168.56.66 -i ~/.ssh/openwrt
Enter fullscreen mode Exit fullscreen mode

You can simplify this by adding an entry to ~/.ssh/config:

Host openwrt
    HostName 192.168.56.66
    User root
    IdentityFile ~/.ssh/openwrt
    Port 22
Enter fullscreen mode Exit fullscreen mode

Then connect with just:

ssh openwrt
Enter fullscreen mode Exit fullscreen mode

Verifying Storage

Check the current filesystem usage:

df -h
Enter fullscreen mode Exit fullscreen mode

Initial output shows limited space:

Filesystem                Size      Used Available Use% Mounted on
/dev/root                98.3M     25.5M     70.7M  27% /
tmpfs                     1.9G    204.0K      1.9G   0% /tmp
/dev/sda1                15.7M      5.7M      9.7M  37% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
Enter fullscreen mode Exit fullscreen mode

Only ~70MB is available on the root filesystem, even though the VDI image is 4GB.

Expanding the Root Filesystem

To utilize the full 4GB capacity, follow the official expansion guide.

# Install packages
opkg update
opkg install parted losetup resize2fs blkid

# Download expand-root.sh
wget -U "" -O expand-root.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/expand_root?codeblock=0"

# Source the script (creates /etc/uci-defaults/70-rootpt-resize and /etc/uci-defaults/80-rootpt-resize, and adds them to /etc/sysupgrade.conf so they will be re-run after a sysupgrade)
. ./expand-root.sh

# Resize root partition and filesystem (will resize partiton, reboot resize filesystem, and reboot again)
sh /etc/uci-defaults/70-rootpt-resize
Enter fullscreen mode Exit fullscreen mode

Verify Expansion

After the reboots complete, check storage again:

df -h
Enter fullscreen mode Exit fullscreen mode

Expected output:

Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.0G     27.3M      4.0G   1% /
tmpfs                     1.9G    188.0K      1.9G   0% /tmp
/dev/sda1                15.7M      5.7M      9.7M  37% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
Enter fullscreen mode Exit fullscreen mode

The root filesystem now has ~4GB available, perfect for development work.

Top comments (0)