Install Arch Linux in Virtualbox with UEFI Firmware in 2019

Hello and welcome. Arch Linux is one of my favourite Linux distros. It’s a rolling release, which means there’s no new version to upgrade to. The installation process is kind of difficult for new Linux users. But once you successfully install Arch Linux on your computer, it’s actually easy to use. In this tutorial, I’m going to simulate a UEFI boot in virtualbox and install Arch Linux in it.

Enable UEFI in Virtualbox

First, create a virtual machine in Virtualbox. To enable UEFI, go to the settings window of your virtual machine. Select System on the left pane, then tick on Enable EFI and hit the OK button.
Install Arch Linux in Virtualbox with UEFI Firmware

Install Arch Linux with UEFI Firmware in Virtualbox

Go to the Storage settings and add Arch Linux ISO image to the virtual optical drive before starting virtual machine, or you will be dropped into UEFI shell.

Install Arch Linux in Virtualbox with UEFI Firmware

Now start your virtual machine. Choose the first option so we can install Arch Linux in UEFI mode.

Install Arch Linux in Virtualbox with UEFI Firmware

You will be automatically logged in as the root user.

install arch linux uefi 2019

Check if you can access Internet in this virtual machine with the following command.

ping -c6 www.linuxbabe.com

If you install Arch Linux on a real laptop, you can use the following command to connect to Wi-Fi networks.
wifi-menu

Set US keyboard as the keyboard layout:

loadkeys us

Now let’s configure the partition. I’m using only one virtual hard drive, so the name of virtual hard drive is /dev/sda. You can run the following command to find out the name of your hard drive.

parted -l

In the following screenshot, there are two disks:

  • /dev/sda: This is my main hard drive.
  • /dev/sr0: This is the Arch Linux ISO.

install arch linux virtualbox uefi

Since we install Arch Linux on UEFI hardware, it’s better to partition the disk in GPT (GUID Partition Table) instead of in MBR (Master Boot Record). Run the following command to make a GPT style disk with the parted partition editor.

parted /dev/sda mklabel gpt

You can confirm it’s a GPT disk using this command:

parted /dev/sda -l

install arch linux uefi gpt

Make parted use /dev/sda.

parted /dev/sda

An EFI system partition (ESP) is required for GPT disks. Run the following command to make a EFI system partition with 512MB space.

mkpart primary fat32 2048s 1050624s
  • Partition type is set to primary.
  • File system is set to fat32.
  • This partition spans from sector 2048 to sector 1050624. (My virtual hard disk’s sector size is 512B both logically and physically. This will make a 512MB partition.)

Check EFI system partition.

unit MiB

print

arch-uefi-Running-Oracle-VM-VirtualBox

You can see that the file system is fat32. To make it an EFI system partition (ESP), we need to turn on the boot flag for this partition.

set 1 boot on

Now if you run the print command again, you will see it has been converted to an EFI system partition.

install arch linux efi system partition

Then run the following command to make a root partition, which will start from sector 1050625. 100% means this partition will use all remaining disk space because I’m not going to make a swap partition.

mkpart primary ext4 1050625s 100%

Now, exit out of parted partition editor.

q

Format /dev/sda1 as fat file system and /dev/sda2 as ext4 file system.

mkfs -t fat /dev/sda1
mkfs -t ext4 /dev/sda2

Mount the root partition under /mnt.

mount /dev/sda2 /mnt

Make a boot directory on /dev/sda2 partition.

mkdir /mnt/boot

Mount the EFI system partition (/dev/sda1) under /mnt/boot/

mount /dev/sda1 /mnt/boot/

Select a mirror that is close to your location with the nano command line text editor.

nano /etc/pacman.d/mirrorlist

To set your preferred mirror, copy that mirror address to the top of the mirror list. I live in China so I selected a mirror in China as my preferred mirror.

Install Arch Linux in Virtualbox with UEFI Firmware

Save and close this file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.) Now run the following command to install Arch Linux base system with the Linux kernel and Nano text editor on /dev/sda2.

pacstrap -i /mnt base linux linux-firmware nano

Press Enter to select all software packages.

Next, generate a file system table file /etc/fstab.

genfstab -U -p /mnt >> /mnt/etc/fstab

Change root

arch-chroot /mnt

Edit the locale.gen file.

nano /etc/locale.gen

Find locales that you need and uncomment them. For example, I uncommmented en_US.UTF-8 UTF-8 and zh_CN.UTF-8 UTF-8. Save the file. Then run the following command to generate /etc/locale.conf file and make en_US.UTF-8 as the default locale.

echo LANG=en_US.UTF-8 > /etc/locale.conf

export LANG=en_US.UTF-8

List time zones.

timedatectl list-timezones

You can press J to move down, press K to move up. When you find your time zone, press Q to quit.

arch linux timedatectl list-timezones

Then run the following command to set your time zone for Arch Linux. I set Asia/Shanghai as my time zone.

timedatectl set-timezone Asia/Shanghai

To check your current time zone on your OS, run

timedatectl

Enable eth0 network interface.

systemctl enable [email protected]

If you install Arch Linux on a laptop, then you probably want to install wireless networking tools:
pacman -S wireless_tools wpa_supplicant dialog
Run the following command to connect to a wireless network.
wifi-menu
And enable wireless network interface.
systemctl enable net-auto-wireless.service

Install network manager and related tools.

pacman -S networkmanager networkmanager-vpnc network-manager-applet

Enable network manager.

systemctl enable NetworkManager

Configure pacman package manager.

nano /etc/pacman.conf

Find repositories section, [core], [extra], [community] repository is enabled by default. If your Arch Linux is 64 bit and you want to be able to install and run 32 bit software, you must enable [multilib] repository. To enable [multilib] repository, copy and paste the following two lines at the end of this file.

[multilib]
       Include = /etc/pacman.d/mirrorlist

Save and close this file. Now update repositories.

pacman -Sy

Set a password for the root user.

passwd root

Create a standard user account. Replace <username> with your preferred username.

useradd -m -g users -G wheel,storage,power -s /bin/bash <username>

Set a password for this user.

passwd <username>

Install sudo utility

pacman -S sudo

Allow member of wheel group to use sudo.

EDITOR=nano visudo

Find this line.

# %wheel ALL=(ALL) ALL

Remove the # sign and save this file.

Install grub and efi boot manager

pacman -S grub efibootmgr

Install Grub boot loader to /dev/sda.

grub-install /dev/sda --target=x86_64-efi --efi-directory=/boot

Generate Grub configuration file.

grub-mkconfig -o /boot/grub/grub.cfg

Exit out of chroot environment.

exit

Reboot virtual machine.

shutdown -r now

You will be greeted by Grub2 boot menu. Press Enter to choose the first menu entry.

Install Arch Linux in Virtualbox with UEFI Firmware

Login with the standard user. Then run the following command to change hostname:

sudo hostnamectl set-hostname <your-hostname>

Install alsa-utils.

sudo pacman -S alsa-utils

Start alsamixer sound configuration tool.

alsamixer

install alsamixer arch linux

MM stands for mute. Press M key to unmute and use up and down arrow key to adjust sound volume. You must unmute Master and PCM.

Press ESC to exit out of sound configuration. Now enter this command to test sound.

speaker-test -c2

If you hear something, that means the sound system is working. Press Ctrl+C to stop sound test.

Install X window system.

sudo pacman -S xorg-server xorg-xinit

Install mesa to enable 3D support.

sudo pacman -S mesa

Check what graphics card your system has.

lspci -k | grep -A 2 -i "VGA"

If you have an integrated Intel graphics card, install intel open source graphics card driver.

sudo pacman -S xf86-video-intel

If you have Nvidia graphics card, install Nvidia closed-source graphics driver.

sudo pacman -S nvidia lib32-nvidia-utils

For ATI card:

sudo pacman -S xf86-video-ati

The vesa display driver works with most video cards.

sudo pacman -S xf86-video-vesa

I’m using the Virtualbox graphics adapter and I have to install this package.

sudo pacman -S virtualbox-guest-utils

Notebook users can install trackpad driver.

sudo pacman -S xf86-input-synaptics

Install xorg test widget.

sudo pacman -S xorg-twm xorg-xclock xterm

Use this command to test  xorg.

startx

If you can see the following 3 programs running, that means X.org is working.

Install Arch Linux in Virtualbox with UEFI Firmware

Press Ctrl+D to quit. Then install font.

sudo pacman -S ttf-dejavu ttf-ubuntu-font-family

Install xfce4 desktop environment

sudo pacman -S xfce4 xfce4-goodies firefox

Before we start our xfce4 desktop encironment we need to copy xinitrc file to our home directory and edit it.

cp /etc/X11/xinit/xinitrc ~/.xinitrc

nano ~/.xinitrc

Comment out the last 5 lines (add # symbol) and add following line at the end of this file.

exec startxfce4

arch_arch-uefi-Running-Oracle-VM-VirtualBox

Save and close the file. Now start XFCE4 desktop environment.

startxfce4

You should be able to enter into XFCE4 desktop.

Install Arch Linux in Virtualbox with UEFI Firmware

Install Slim Login Manager

Instead of typing startxfce4 command every time, we can install a login manager such as Slim to enable us to automatically boot into graphical user interface. To install Slim login manager, execute this command:

sudo pacman -S slim slim-themes

Then enable Slim to auto-start when computer is power on.

sudo systemctl enable slim.service

Edit /etc/slim.conf to select a theme for our login manager.

sudo nano /etc/slim.conf

Find this line:

current_theme     default

change it to this:

current_theme       archlinux-simplyblack

To pre-load username on the login screen, find the following line

#default_user     simone

Remove the # symbol and change simone to your own username. Then find the following line.

#focus_password    no

Remove the # symbol and change no to yes. Save and close the file. Reboot your Arch Linux computer.

sudo shutdown -r now

you will be greeted by the Slim login manager.

Install Arch Linux in Virtualbox with UEFI Firmware 2019

Enable NTP Time Synchronization

If you run timedatectl command in terminal, you will see that NTP time synchronization isn’t enabled. Run the following command to enable it.

timedatectl set-ntp true

Some common packages that you may like after you install Arch Linux:

sudo pacman -S flashplugin vlc terminator htop parted gparted transmission-cli transmission-gtk wine wine-mono wine_gecko winetricks banshee

How to Exit the EFI Shell

If your Arch Linux machine accidentally drops into an EFI shell, first enter the following command to add the Grub boot loader.

bcfg boot add 1 fs0:/EFI/arch/grubx64.efi "Manually Added"

Then

exit

Select Continue in the next screen and you will see the Grub boot menu.

To prevent dropping into EFI shell in the future, once you boot into Arch Linux, run the following command to make Arch Linux Grub as the default boot loader.

sudo mkdir /boot/EFI/BOOT

sudo cp /boot/EFI/arch/grubx64.efi /boot/EFI/BOOT/BOOTX86.EFI

So that EFI can find the default boot loader.

You can also create a startup.nsh script on the root of EFI system partition.

sudo nano /boot/startup.nsh

And put the following text into the shell script.

bcfg boot add 1 fs0:/EFI/arch/grubx64.efi "Manually Added"
exit

So even if you drop into the EFI shell, you don’t need to manually execute these two commands.

Wrapping Up

It’s not easy for Linux beginners to install Arch Linux, but after it’s installed, Arch Linux is actually easy to use. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 22 Average: 4.7]

22 Responses to “Install Arch Linux in Virtualbox with UEFI Firmware in 2019

  • Erik van de Ven
    6 years ago

    One thing, you don’t necessarily have to install slim login manager, just to prevent you from typing startx everytime. You can just automatically execute startx, after login, check this out: https://wiki.archlinux.org/index.php/Xinit#Autostart_X_at_login. But I do think it’s nicer to have a graphical login screen, instead of the terminal.

  • fortnite mac hack
    6 years ago

    Hello, i really think i will be back to your website

  • Dear Xiao,

    want to thank you for this wonderful install guide. It was the first to get me through to the end without many hassles at all.

    I did start installing packages in the terminal in xfce4 to get petsc to work among other things. (Needs compilers/wget/git etc). For some reason when I rebooted at the end, I get the bootloader menu (Archiso, UEFI shell, EFI, boot into firmware…something like that). And I can no longer enter into xfce4.

    Was wondering if you’ve encountered this problem before, or perhaps know a simple adjustment to get into the grub boot menu?

    Right now I can only get into the root@archiso terminal. And the UEFI shells.

    Thanks for your reply!
    BS

  • When sizing the ext4 partition I get a warning that the partition is not properly aligned for best performance. Is this something that everyone is seeing and just ignoring, or is there another solution to optimize performance? Might it depend on the hard drive size?

    • I am seeing this too. I tried moving the start of partition 2 up to the next 2048 boundary but something (I’m hoping this is the reason) caused me to drop into grub> prompt when I rebooted. Still poking at this to see what things I did wrong.

    • I hit this issue. I moved up to the next 2048 boundary:

      mkpart primary ext4 1052672s 100%
    • I hit the same problem but I was familiar with using fdisk at partitioning so I canceled out then fdisk /dev/sdX push n at the prompt for new partition and just keep pushing enter if you want to use the rest of the disk. You can double check with p. After it creates (well nothing real is done yet) the part push w to write it. Then follow along as the guide says. It is cool that the installer has multiple parting tools available. Also cfdisk. Try it. Be familiar with them all I says.

  • Guo-An, many thanks for your comprehensive tutorial, really helpful!
    I’ve successfully deployed Arch Linux in a virtual machine following your instructions here, in preparation for a subsequent installation in a real machine (as an educational process).
    In this sense, would there be differences in your tutorial applicable to a real installation in a physical machine? What would change?

    • Xiao Guoan (Admin)
      4 years ago

      You just need to change some command options when partitioning your hard drive, if there are other operating systems already installed.

  • Before:
    grub-install /dev/sda –target=x86_64-efi –efi-directory=/boot
    You have to install:
    pacman -S grub
    pacman -S efibootmgr

    • Xiao Guoan (Admin)
      4 years ago

      I think I have already said that in this article.

      Install grub and efi boot manager.
      
      pacman -S grub efibootmgr
      • Ouch, yes, I’m sorry.
        Btw, thanks for the article. It really helped me. 👍

  • Eric S.
    4 years ago

    Thank you for this !
    I was stuck with installing a Desktop Environment on Arch in a Virtualbox. Solved thanks to your manual !

  • I’m finding small inconsistencies after the arch-chroot and before the reboot. 1) nano is not available. 2) systemctl refuses to work giving the error “Running in chroot, ignoring request.”

    • I tried this twice and kept getting to the “grub>” prompt with the first reboot. From the Arch install page on their wiki, I changed to “pacstrap /mnt base linux linux-firmware” because when I dug around using the grub commands, I didn’t have a kernel. I’m curious if “base” use to include a kernel or where the kernel is suppose to come from.

      Thank you for the article. It helped especially with a good minimum install of an X11 desktop and logon page.

    • Xiao Guoan (Admin)
      4 years ago

      Yes. The group base used to include package linux, linux-firmware and nano by default. Now it doesn’t.

  • At some point I shut down the VM and when I booted back up, I plopped into the grub> prompt. After much time, here are some things I
    discovered.

    1) The grub-install –bootloader-id= defaults to “arch” which is not mentioned in grub page in Arch’s Wiki

    2) grub-install creates a “menu” item with the –bootloader-id and makes it the first place to boot from. This can be seen with efibootmgr -v. This is why the “shutdown -r now” works and does not boot from the CD. BUT…

    3) The above menu item is supposed to survive a power outage but with Virtual Box it does not. To rephrase, if the VM is “Powered Off”, the setting that grub-install creates is lost and only the defaults or whatever Virtual Box creates are present when the VM is powered back on.

    4) The default grub path for 64 bit architecture is esp/EFI/BOOT/BOOTX64.EFI where esp is your EFI partition (which we’ve called /boot). This page says it is EFI/BOOT/BOOTX86.EFI (note the 64 instead of the 86).

    5) For me, I did not have a kernel to boot from until I installed “linux” and “linux-firmware” with the pacstrap command. It also seems appropriate to add “nano” to the pacstrap command. I’m not sure if “base” changed and use to include these items. To rephrase, I’m confused how these instructions worked for others and would love to understand this better.

    Thank you again for this page.

  • This article worked perfectly except when I turn off virtualbox and go back into Arch, it doesn’t save what I’ve done and wants me to set up the whole operating system again. Is there a workaround for this? thank you 🙂

    • Xiao Guoan (Admin)
      4 years ago

      Remove Arch ISO from the virtual optical drive after you have installed Arch.

  • Hello, I am running into an issue while working on mounting /dev/sda2. It is telling me that this doesn’t exist.

  • Charlie
    1 year ago

    Thank you so much.

    My Arch install kept dropping back to the grub> prompt. I finally gave up and went back to legacy boot, which is working. If I need to reinstall I will follow these instructions over and above what’s in the Arch wiki. The copy of grubx64.efi to bootx64.efi in the boot directory is what I think is the magic.

    I also have Manjaro installed and apparently it’s installer is VirtualBox aware and did this for me.

    This has been driving me nuts. Thank you.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here