Exploring the Lightweight Alpine Linux in Virtual Box

Explore the lightweight Alpine Linux inside a Virtual Machine by following these steps.
Warp Terminal

Alpine Linux is one of the few Linux distributions out there that stands out of the crowd.

First, Alpine is an independent Linux distribution, not a derivative of any other popular option.

Second, it uses OpenRC as the init system. So, if you are someone who is not a fan of systemd, you can surely consider this one.

Third, it uses BusyBox by default, which is an interesting choice.

Now, Alpine is immensely popular as a container distro because of its small form factor. The base docker image is hardly 5 MB, making it an attractive choice.

But it doesn't mean that you can only use Alpine with Docker or it only has to be in the the server format.

In this tutorial, I'll share how you can install Alpine Linux with Xfce desktop in VirtualBox.

Sounds exciting? Let's go.

Step 1: Download Alpine Linux

Alpine Linux provides several options to download. Here, I downloaded the x86_64 Virt ISO that is made for virtual machine setups. It is around 60 MB in size. You may also use the standard edition which is ~200 MB, and an extended ISO, nearly 900 MB in size.

I have used the Virtual Machine edition since I am installing it in a VirtualBox VM.

Step 2: Setup VirtualBox VM with Alpine ISO

Open VirtualBox and click on the β€œNew” button to start creating a New VM.

Click on the New button to start creating a new Virtual Machine
Click on New

Now, choose the Guided Mode and Set the following:

  • Name: Alpine Linux
  • ISO: Choose the Downloaded ISO
  • Kernel: Other Linux kernel 5.x
Give a Name and Select the ISO
Name Virtual Machine

Click Next. On the next screen, allocate some RAM to the VM. Usually, 2 GB is enough for Alpine, but if you could, give it 4 GB of RAM. Also, allocate some processors. Here, I have assigned 2 processors. Click Next.

Allocate RAM and CPU for Virtual Machine
Allocate RAM and CPU

On the next screen, you need to provide the storage space. You can either go with the requirement or a bit extra for efficiency. 25 GB will be more than sufficient for a test virtual machine. Change according to your need.

Allocate Disk Size
Allocate Disk

Clicking Next will give you an overview of the settings. Click the Finish button here.

Click on the Finish button
Click on Finish

Now, select the machine, right-click on it and select the Settings option.

Select Virtual Machine Settings by right-clicking on the virtual machine
Select Virtual Machine Settings

Select the Display tab and put the display memory to max (128 MB). Click on OK after this.

Allocate Display Memory
Allocate Display Memory

Now, start the VM by double-clicking on its name.

Step 3: Text-based Alpine installation

Alpine installation is text-based. Yeah! It gives the Arch Linux vibes, I know.

When the machine starts, you will be prompted to log in. Just type root and enter. The default root user has no password. You will be ready to install the system now.

Login as root by entering the username "root"
Login as root

Start the text-based installer

Once logged in as root, enter:

setup-alpine

This will start the installer.

Keyboard layout

You need to select the keyboard layout. Here, I have chosen β€œus”. It will ask to select the variant in US keyboard. I again enter β€œus” as the option.

Seet US as the keyboard layout
Keyboard Layout

Hostname

Enter a hostname of your choice. The default was localhost. And then press enter.

Enter a hostname, all in small letters
Enter Hostname

Interface selection

Installer will ask for the network interface selection. Since, it selected the default for me, I will press Enter key. If you have other interfaces, you can select β€œ?” for help. For VirtualBox, the default is enough.

Select Network Interface
Select Network Interface

It now asks to set the IP. I am going with the default DHCP. Also, no further manual settings.

IP Address Settings
IP Address Settings

Root password

As I mentioned earlier, the root account has no password. You have to set it up for the security purpose.

You need to type and retype the root password in this step. Needless to say that nothing is displayed on the screen when you type the password. Just type it and press enter.

Set the root password and verify it by entering once more
Set Root Password

Timezone settings

You need to select the timezone. The default is UTC. Press β€œ?” for listing the available timezones. As you can see, I have set it to Asia and then pressed enter.

Select Timezone
Select Timezone

Subsequently, you have to set the region. Like before, press β€œ?” for listing all the available area in the given timezone. I have selected Kolkata.

Select Sub-timezone
Select Sub-timezone

Proxy settings

If you have any HTTP proxy, enter it at this stage, I had nothing, so I skipped the step by pressing the Enter key.

Proxy settings
Proxy Settings

NTP client

Select which NTP client to run. I am once again going with the default chrony.

Set NTP client
NTP Client

Mirror selection

The next screen is about the mirrors. You can view several lines of mirror list. Press R to view all. Now, you need to press β€œf” and enter to automatically analyze and save the fastest mirror from the list.

Select fastest mirror
Select fastest mirror

This will analyze and do the rest for you. Wait for a couple of minutes.

Set up a new user

You will need an additional user besides the root, for normal use cases. You can create it here, right within the installer, to avoid difficulties letter. For this, you need to enter a username (all small letters), full name for the user and type and retype the user password.

Set up a new user with password
Set up a new user

Some SSH Settings

Next is some SSH related settings, and I have chosen all the default options, by just pressing the enter key.

Go through some SSH settings. You can accept the default.
SSH Settings

Partitioning the Disk

This step is important, as it decides the installation of the system. You need to partition the disk. It will list the available disk, and you can enter β€œ?” for help.

Then select the disk that needs to be used by name. In my case, it is the SDA, with the storage space. This will ask how to use it. You have several options like β€œsys”, β€œdata” etc. For normal use cases, you need to select the β€œsys” option and press enter.

It will then show a warning about erasing the data. Press β€œy” and enter.

After some time, you will get a notification that the installation is complete.

Partitioning the Disk
Partitioning the Disk

You can either reboot the system here. But I will shut down the system using:

poweroff

Then, remove the attached ISO and start the machine again to avoid booting into the live ISO.

Step 4: Post-install set up

Now, you have installed the base system, but there is no desktop installed. So, you will be logged into the console again. You will now set up a minimal Xfce desktop and LightDM display manager for our Alpine Linux installation.

So, after booting into the system, login as root. Just use the username as root and enter the root password you have set during the installation.

Ensure superuser privileges

You need an editor for editing some config files. Since Alpine is a minimal set up, you need to install an editor first. Install Nano editor using:

apk add nano
πŸ’‘
In Alpine Linux, you have doas instead of sudo. But that is not used here because you are running as root.

First, make sure that the default user is added to wheel group. For me, it was added automatically. To check, run:

groups <your-username>

This will list the groups your user is currently in. Look for the word β€œwheel”.

User is added to the Wheel Group
User in Wheel Group

If not, you can add by using the command:

adduser <your-username> wheel

Now that the user is added to the wheel group. make sure the wheel group has its privileges by checking for the following line in /etc/doas.d/doas.conf

permit persist :wheel
Check if the user has Superuser privileges
Superuser privileges for User

If not, edit the file using:

nano /etc/doas.d/doas.conf

Enable community repositories

By default, Alpine Linux does not have the community repository enabled. But you should have this to install more packages. So, edit the repositories file using:

nano /etc/apk/repositories
Enable Community repositories in Alpine Linux
Enable Community repositories

Now, uncomment the line that refers to community repositories, save and exit.

Step 5: Install Xfce desktop

Before installing the Xfce desktop, you need to make sure that you have xorg-base set up. For this, Alpine Linux provides a neat way. Run the code below:

setup-xorg-base

This will install the required packages for you.

Install Xfce and LightDM

Now, you need to install the Xfce and related packages. I am going to use the LightDM Desktop Manager. So, run the command below to install.

# apk add xfce4 xfce4-terminal xfce4-screensaver lightdm-gtk-greeter dbus

Once installation is finished, start the dbus (desktop bus) service:

rc-service dbus start

Enable dbus to start on boot:

rc-update add dbus
Add DBus Service
Add DBus Service
πŸ’‘
If dbus is not running, it leads to issues like missing icons and keyboard shortcuts

Enable udev service:

setup-devd udev

Now start the LightDM using:

rc-service lightdm start

If your LightDM GUI has started and prompts a login, log in as root and open a terminal. Next, run the below command to enable LightDM to start up during boot. If not started, run the command in the same prompt.

Login as root in LightDM login page
Login as root
rc-update add lightdm
Enable LightDM during system start
Enable LightDM during system start

Allow Users to shut down and reboot

If you want to allow the users to shut down the machine or reboot the system, you need to have polkit-elogind and elogind installed.

apk add elogind polkit-elogind

Now, reboot the system:

reboot
Running Alpine Linux Xfce in VirtualBox
Running Alpine Linux

That's the end...

I understand that it is slightly different than the usual way of installing Linux in VirtualBox. But then Alpine Linux is slightly different from most other Linux distributions.

I hope you find this quick tutorial helpful in getting started with Alpine Linux. Please let me know if you have questions or suggestions.

About the author
Sreenath

Sreenath

Linux tinkerer by day, Lord of the Rings fanatic by night. When I'm not busy conquering the command line, you can find me kicking back and watching some football while quoting JRR Tolkien

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.