DEV Community

God'stime Ojor
God'stime Ojor

Posted on

How I Built a Linux Virtual Machine by Hand (and Fixed the 3 Problems That Almost Stopped Me)

Today on my DevOps journey I learned virtualization and built a Linux virtual machine (VM) from scratch. It did not work the first time. Three things stood in my way, and none of them were obvious.

What you will get from this post
By the end, you will be able to build a CentOS VM in VirtualBox by hand, and fix the 3 problems that block most beginners: missing 64-bit option, conflicting Windows features, and a VM with no IP address.

What is virtualization?
Virtualization lets one physical computer run several virtual computers. Each VM has its own operating system, memory, disk and network adapter. The software that creates and runs them is called a hypervisor. In this tutorial the hypervisor is Oracle VirtualBox.
Why learn this for DevOps? Servers, containers and cloud instances all build on the same idea. Doing it by hand once shows you what automation tools do for you later.
What you need
• A Windows PC or an Intel-based Mac (these steps are written for those)
• Oracle VirtualBox installed
• A Linux ISO file (CentOS Stream 9 in this tutorial)
• At least 2 GB of RAM you can spare and about 20 GB of free disk space
• A CPU that supports virtualization (most modern ones do)

Part 1: Prepare your computer

Step 1: Enable virtualization in BIOS
Your computer must allow virtualization at hardware level. Restart, enter BIOS (the key depends on your brand, often F2, F10, F12 or Del), and look for a virtualization setting. The name changes by hardware vendor:
• VT-x (Intel)
• SVM / Secure Virtual Machine (AMD)
• Virtualization (generic label)
Enable it, save and exit.
Why this matters
If virtualization is off, VirtualBox will not show any 64-bit option when you create a VM. If you see that later, come back to this step.

Step 2: Turn off conflicting Windows features
Several Windows features use the same hardware virtualization and can conflict with VirtualBox. Open Turn Windows features on or off and uncheck:
• Hyper-V
• Windows Hypervisor Platform
• Virtual Machine Platform
• Windows Subsystem for Linux (WSL)
Also close or uninstall Docker Desktop, since it relies on the same features. Restart your computer.
Note: Newer VirtualBox versions can sometimes run alongside Hyper-V, but performance is often worse. Turning these off is the safest path for a first VM.

Part 2: Create the virtual machine

Step 3: Create the VM

  1. Open VirtualBox and click New.
  2. Give the VM a name.
  3. Set Type to Linux.
  4. Set Subtype to Red Hat (this is for CentOS), then choose the 64-bit version. If you do not see the 64-bit version, virtualization is not enabled in your BIOS. Go back to Step 1.

Step 4: Set memory and CPU
Under Hardware, set base memory to 2048 MB (2 GB). If your computer is low on resources, use 1024 MB (1 GB) instead. With 2048 MB, set the processor count to 2 CPUs.

Step 5: Create the virtual hard disk
Under Hard Disk, choose the disk size. Leave Pre-allocate Full Size unchecked. The disk will then grow dynamically as you use it, up to the maximum shown (20 GB here). Click Finish.

Where we are
You now have the virtual hardware. It is like a new computer with no operating system, so the next job is to install an OS on it.

Step 6: Attach the OS image (ISO)

  1. Search Google for CentOS Stream 9 ISO download and download the file named boot.iso.
  2. Go back to your VM, right-click it and open Settings, then Storage.
  3. Under Controller: IDE, click the Empty disc.
  4. Click the disc icon, choose Choose a disk file, and select the ISO you downloaded.
  5. Check the Live CD/DVD option, then click OK. What you are doing: attaching the ISO so the VM boots from that image the first time it starts. The boot.iso file is a network installer, so the VM needs internet during installation.

Part 3: Networking (the part that tripped me up)

Step 7: Understand why the VM needs a bridge
Build the idea from the ground up:

  1. A computer needs a network adapter to connect to a router. The adapter can be wireless (Wi-Fi) or wired (Ethernet cable).
  2. The router runs a service called DHCP, which hands out an IP address to each device that connects.
  3. A computer can have several network adapters, and each one has its own IP address.
  4. A VM behaves like another computer, so it has its own virtual network adapter.
  5. To reach your physical router, the VM adapter must connect through your real adapter. This is called bridging. VM adapter <--> Computer network adapter <--> Router (acts as the bridge) With bridging, the router treats the VM as its own device and gives it its own IP address. That IP is what you will use for SSH later.

Step 8: Configure the adapters

  1. On your computer, open Command Prompt and run ipconfig to see your adapters and IP address.
  2. Open Network and Sharing Center and note which adapter is connected (Wi-Fi or Ethernet).
  3. In VirtualBox, open your VM Settings, then Network.
  4. Keep Adapter 1 as NAT (the default).
  5. Open Adapter 2, tick Enable Network Adapter, and set Attached to to Bridged Adapter.
  6. In Name, select the adapter you are actually using (Wi-Fi or Ethernet), then click OK.

Step 9 (optional): Make the mouse work smoothly
In Settings, go to System, then Motherboard, and set Pointing Device to USB Tablet. This makes the mouse cursor behave better inside the VM.
Part 4: Install CentOS

Step 10: Start the VM and run the installer

  1. Click Start. When the installer menu appears, click inside the VM window to capture your mouse, then use the arrow keys to choose the install option.
  2. To release your mouse and keyboard, press the Right Ctrl key.
  3. Wait a few minutes for the installer to load, then select your language (English).
  4. Open Installation Destination, select the virtual hard disk and click Done.
  5. Open Network & Host Name. Turn on the bridge adapter, give the machine a host name, click Apply, then Done.
  6. Open Root Password, set a password, and click Done.
  7. Click Begin Installation and wait for it to finish.

Step 11: Remove the ISO and restart
When installation finishes, go to Settings > Storage and remove the ISO from the virtual drive. This stops the VM from booting into the installer again. Then restart the VM.

If it connects, you have a working VM that you built by hand. To shut it down, power it off from VirtualBox or use an ACPI shutdown.

Bonus: Doing the same with Ubuntu Server
The approach is almost identical. The differences:
• Set Subtype to Ubuntu when creating the VM
• The default disk size is about 25 GB
• Download the Ubuntu Server ISO and attach it as in Step 6
In the Ubuntu installer:

  1. Select English, then continue without updating the installer.
  2. Accept the keyboard layout and choose Done.
  3. Under storage, use the whole disk and continue.
  4. Fill in your name, server name, username and password.
  5. Select Install OpenSSH server so you can SSH in later.
  6. Do not select anything under Featured Server Snaps.
  7. Wait for installation to finish, then remove the disc from the virtual drive and restart.

Troubleshooting: the 3 problems that nearly stopped me
Problem
No 64-bit option when creating the VM
VM will not start or runs badly
VM has no IP address
Installer appears again after install

Likely cause
Virtualization is disabled in BIOS
Hyper-V, WSL, Virtual Machine Platform or Docker Desktop is competing for virtualization
Wrong adapter selected, or the router is not assigning an address
The ISO is still attached

Fix
Enable VT-x, SVM or Virtualization in BIOS (Step 1)
Turn those features off and restart (Step 2)
Check Adapter 2 is Bridged and uses your real adapter. If still no IP: power off your computer, reboot the router, power the computer on again.
Remove the ISO from Settings > Storage (Step 11)

Key takeaways
• Most "it is not working" moments are setup problems, not broken tools.
• A VM is just another computer with its own virtual hardware and network adapter.
• Bridging connects that virtual adapter to your real network so the VM gets its own IP.

• Which step would you have gotten stuck on?
• Was the bridged adapter explanation clear?
• What should I break down next?

Thanks for reading. Follow along as I document my Cloud/DevOps journey.

Top comments (2)

Collapse
 
posi_the_dev profile image
Anuoluwaposimi Adegbayi •

Keep on the great work bro 💪🔥

Collapse
 
ojor_g profile image
God'stime Ojor •

Thank you brother.