How to Install Ubuntu Server 24.04

Overview

This article will teach us how to:

  • Install Ubuntu Server 24.04 on a laptop from scratch

  • Install Ubuntu server by using Vagrant tool with ISO image

Prerequisites:

  1. A laptop without any OS installed;

  2. A virtualization software Virtualbox that Vagrant uses to create virtual machines.

  3. Vagrant which automates the setup and provisioning of virtual machines.

Installing Ubuntu Server on Laptop

Installing Ubuntu Server on a laptop is a straightforward process, though it involves several steps:

  1. Go to the Ubuntu Server Download Page and click the download link to get the ISO file. In this hands-on, Ubuntu Server 24.04.1 LTS version was downloaded and used as a base image.

  2. Download a balenaEtcher, a USB creation tool that allows you to create bootable media.

  3. Now, when balenaEtcher is downloaded as a .zip file, extract it with the unzip command:

    After extraction, you will find an executable file with .AppImage extension.

  4. Insert your USB drive with at least 4 GB of space into your computer.

  5. Run the balenaEtcher, select the downloaded Ubuntu Server ISO, choose the USB drive, and start the flashing process:

    💡
    This process will erase all data on the USB drive, so make sure to back up any important files.
  6. Insert the bootable USB drive into your laptop, restart your laptop, and enter the boot menu (usually by pressing F12 on the Dell laptop).

    💡
    If you have any important data on your laptop, back it up as the installation process may erase the entire disk.
  7. Select the USB drive from the boot options and press Enter.

  8. Choose the language you want to use for the installation process.

  9. Select your preferred keyboard layout.

  10. Choose the type of installation.

  11. Configure Network:

    If your network is not found among other networks, you can continue without a network and later configure the network at your own pace.

  12. If your system requires a proxy to connect to the Internet, configure your Proxy.

  13. If you use an alternative mirror for Ubuntu, enter the Mirror address details.

  14. Set Up the Storage:

    💡
    In this hands-on, an entire disk was chosen for the Ubuntu Server OS, however choosing the entire disk is not recommended since it will erase all data on the disk, making it unsuitable if you need to preserve existing data or partitions.
  15. Create a user account by entering your name, the server name, and a username and password for the system.

  16. If you plan to access your server remotely, choose to install the OpenSSH server.

  17. Confirm the installation details and start the process. The installer will copy the files and configure the system. This may take some time.

  18. Once the installation is complete, remove the installation media and press Enter to reboot.

  19. Log in with the username and password you created during the installation.

    Your Ubuntu Server installation is now complete. You can start using it as a server or install additional services as needed.

Install Ubuntu Server via Vagrant

To install Ubuntu Server manually using a Vagrant machine with a downloaded ISO file, follow these steps:

  1. Edit the Vagrantfile to configure the virtual machine and specify that it should boot from the ISO file:

      Vagrant.configure("2") do |config|
       config.vm.box = "bento/ubuntu-20.04"
       config.vm.provider "virtualbox" do |vb|  
           vb.gui = true 
           # Ensure the boot order prioritizes booting from the virtual DVD drive
           vb.customize ["modifyvm", :id, "--boot1", "dvd", "--boot2", "disk"]
           # Attach the ISO file to the VM as a virtual DVD drive to the existing SATA controller
           vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "0", "--device", "0", "--type", "dvddrive", "--medium", "path/to/your/ubuntu-24.04.1-live-server-amd64.iso"]
    
           # Create and attach a virtual hard disk to the SATA controller for installation
          vb.customize ["createhd", "--filename", "ubuntu-server-disk.vdi", "--size", 20000]  # creates a 20 GB virtual hard disk that the Ubuntu Server can be installed on.
          vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--device", "0", "--type", "hdd", "--medium", "ubuntu-server-disk.vdi"] #the new virtual hard disk is attached to the SATA controller
    
           # Optionally increase VM resources (like memory or CPU)
           vb.memory = "4096"
           vb.cpus = 2
       end
       # Configure a bridged network
       config.vm.network "public_network", bridge: "wlo1: Wi-Fi (Home)"
       #This configuration forwards requests made to port 2222 on your host machine to port 22 on the Vagrant guest machine
       config.vm.network "forwarded_port", guest: 22, host: 2222, auto_correct: true
     end
    

    Replace "path/to/your/ubuntu-server.iso" with the actual path to the Ubuntu Server ISO file on your system.

  2. Once your Vagrantfile is ready, you can boot the machine:

     vagrant up
    

    This will start the virtual machine and boot from the ISO file to install Ubuntu Server on the virtual hard disk.

  3. Since the ISO is loaded, the Ubuntu Server installation screen will appear. You should now be able to install Ubuntu Server as if you were on physical hardware. Proceed with the standard Ubuntu Server installation steps within the VM.

  4. After installation is complete, you may see an error “Failed unmounting crdom.mount /cdrom“, which means that the installation medium (ISO image) is still mounted in the virtual machine's virtual CD-ROM drive. Power off the VM to make sure that the ISO file is detached from the virtual machine so that the system can reboot from the newly installed Ubuntu Server operating system on the virtual hard disk.

  5. Now edit the Vagrantfile to change the boot order to boot directly from the virtual hard disk (where the OS was already installed).

     # Ensure the boot order prioritizes booting from the virtual DVD drive
     vb.customize ["modifyvm", :id, "--boot1", "dvd", "--boot2", "disk"]
    
    💡
    The default boot order typically prioritizes the hard disk once an operating system is installed.
  6. To access your Ubuntu Server installed via VirtualBox with vagrant ssh, you need to ensure that the VM is configured to allow SSH access. Power on the server through VirtualBox again and install SSH to be able to interact with the Ubuntu Server directly via the terminal:

     sudo apt install openssh-server 
     sudo systemctl enable ssh #to start the service at boot
     sudo systemctl start ssh
     sudo systemctl status ssh
    

  7. Now that SSH is running on your Ubuntu Server, we need to update the Vagrantfile to handle SSH connections correctly:

     Vagrant.configure("2") do |config|
       # Use the existing box or manually installed Ubuntu Server
       config.vm.box = "bento/ubuntu-20.04"
       config.vm.provider "virtualbox" do |vb|
         # Ensure the boot order prioritizes the hard disk
         vb.customize ["modifyvm", :id, "--boot1", "disk", "--boot2", "dvd"]
         # Optionally increase VM resources
         vb.memory = 4096
         vb.cpus = 2
       end
       # SSH Configurations
       #config.vm.network "public_network", bridge: "wlo1: Wi-Fi (Home)"  # Adjust to your network interface
       config.vm.network "forwarded_port", guest: 22, host: 2222, auto_correct: true  # Forward SSH port
       # Use vagrant's default insecure key (no need for password)
       config.ssh.username = "vagrant"  # Ensure this matches the username created during Ubuntu installation
       config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key" # Ensure key matches
     end
    
  8. If Ubuntu Server was installed manually and a vagrant user was not created, create one now. Vagrant expects to use a user vagrant with passwordless SSH access.

     sudo adduser vagrant
     sudo usermod -aG sudo vagrant
    

  9. Add Vagrant’s Public Key: The default Vagrant SSH key needs to be added to the vagrant user’s authorized_keys. Copy Vagrant's default insecure public key to the vagrant user’s SSH directory to allow passwordless SSH access.

     sudo mkdir /home/vagrant/.ssh
     sudo curl -Lo /home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub
     sudo chown -R vagrant:vagrant /home/vagrant/.ssh
     sudo chmod 700 /home/vagrant/.ssh
     sudo chmod 600 /home/vagrant/.ssh/authorized_keys
    

    • Adding the Vagrant public key ensures Vagrant can authenticate using the default key and configuring authorized_keys and permissions resolves any SSH authentication issues.
  10. Now that the Vagrantfile was updated and the vagrant user was set up, reload the Vagrant configuration:

    vagrant reload
    
    💡
    If you encounter “Warning. Authentication failure. Retrying…“ you can ignore it by pressing Ctrl+C
  11. At this point, the VM should be up and running. On the host machine, run the following:

    ssh -i ~/.vagrant.d/insecure_private_key -p 2222 vagrant@localhost
    

    If you can successfully SSH into the server, it confirms that the SSH configuration is correct. Enter the password of your Ubuntu Server if needed.

  12. You can also run the following:

    vagrant ssh
    

References

  1. How to Deploy Ubuntu Server 24.04 LTS: Step-by-Step Installation Overview

  2. Create An Ubuntu 20.04 Server Using Vagrant

  3. How to Install, Deploy, and Uninstall Vagrant on Ubuntu 22.04

0
Subscribe to my newsletter

Read articles from Karlygash Yakiyayeva directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Karlygash Yakiyayeva
Karlygash Yakiyayeva

Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.