Start here: your Linux survival kit
Never used Linux or a command line before? Good, this page was written for you. Spend a little time here and the rest of the labs will feel much easier.
The story for all six labs. A small company has hired you as its only IT technician. It cannot afford real servers, so you will build its whole "data centre" inside a single ordinary computer using virtual machines. By the last lab you will create servers by typing one command, the way real cloud engineers do.
How this page helps you
- Words marked like this have a plain-language explanation. Click one and it opens in the Help panel. You can also search the Help panel for any word.
- Under most commands there is a link called What does this mean? It explains the command piece by piece. Open it every time until the command feels familiar.
- Tick each step when it works. Your progress is saved in this browser.
- Each lab has three levels. Guided gives you every command. Your turn gives you a goal and hints you can reveal one at a time. Challenge gives you only the goal. The help gets smaller as you get stronger.
Three computers, three places to type
You have one real computer and two pretend ones running inside it. Every command box on this page has a label at the top telling you where to type it. Typing a command in the wrong place is the most common beginner mistake, so always read the label first.
- Linux serverThe black text screen of your Linux VM, called
srv-linuxon this page. It is a guest. - Windows clientInside your Windows VM (
win-client), in a program called PowerShell. Also a guest. - Host computerThe real, physical computer you are sitting at, the host. It may be your own laptop or a PC in the computer lab. Use its terminal: PowerShell on Windows, Terminal on macOS or Linux.
If your VMs have different names, use your names wherever you see srv-linux and win-client.
Your own laptop, or a computer-lab PC?
Both work. The instructions are the same, and this page calls either one the host. If you use a computer-lab PC, four things are different:
| On a lab PC | What to do |
|---|---|
| Your VMs live on that PC's disk | They do not follow you to another computer. Sit at the same PC every session and write down its number. If that is not possible, ask your instructor about keeping your VMs on an external drive (Lab 3 shows how to move a VM as a single file). |
| You may not be an administrator | Installing software on the host, or changing its BIOS settings, may be blocked. When a step needs that (installing Vagrant in Lab 5, for example), ask your instructor instead of looking for a way around it. Inside your VMs you are always the administrator. |
| Other people use the same PC | You may see VMs in VirtualBox that are not yours. Never start, change or delete them. Shut your own VMs down before you leave, so the next student has the memory. |
| Your progress ticks are saved in this browser | They stay on that PC and that browser only. Keeping your own notes of where you stopped is a good habit anyway. |
Eight things every Linux beginner should know
| Thing | What it means for you |
|---|---|
| The prompt | A line such as student@srv-linux:~$ means "I am ready, type a command". If you do not see it, the computer is still busy. |
| sudo | Put sudo in front of a command to run it as the administrator. It asks for your own password. Nothing appears while you type the password, not even dots. That is normal. Type it and press Enter. |
| Capital letters matter | Documents and documents are two different names. Copy commands exactly. |
| Tab finishes words for you | Type the first letters of a command or file name and press Tab. Linux completes it. Fewer typing mistakes. |
| ↑ repeats | The up arrow brings back your previous commands, so you can fix a typo without retyping everything. |
| Ctrl+C stops | If a command never ends (like ping on Linux), this stops it and gives you the prompt back. |
| No news is good news | Many Linux commands print nothing when they succeed. Silence means it worked. |
| Read the error | Errors look scary but usually say exactly what is wrong. command not found = typo or program not installed. Permission denied = you forgot sudo. No such file or directory = wrong name or wrong folder. |
Editing a file with nano
Several labs ask you to edit a settings file. You will use nano, the simplest text editor on Linux. There is no mouse. Move with the arrow keys and type normally. To save and leave:
- Press Ctrl+O (the letter O, for "write Out"), then Enter to confirm the file name. The file is saved.
- Press Ctrl+X to exit.
GuidedWarm-up: your first commands
Start
srv-linuxin VirtualBox and log in with the username and password you chose during installation. When you see the prompt, you are in.Ask the server a few questions about itself. Type each line, press Enter, and read the answer before typing the next one.
whoami hostname pwd ls
What does this mean?
- whoami
- "Who am I?" Prints the username you are logged in as.
- hostname
- Prints the name of this computer.
- pwd
- "Print working directory". Shows which folder you are standing in.
/home/yournameis your personal folder. - ls
- "List". Shows the files in the current folder. On a fresh server it may show nothing, because the folder is empty.
Now a command that needs administrator rights. It refreshes the list of software the server is able to install. Remember: the password stays invisible while you type.
sudo apt update
What does this mean?
- sudo
- Run the rest of the line as the administrator.
- apt
- The program that installs software on Ubuntu and Debian. Think of it as the app store, without pictures.
- update
- Download the latest catalogue of available software. It does not install or change anything yet.
If this fails with network errors, your VM has no internet. Check that its network adapter is set to NAT (VM Settings > Network), then try again.
Type your Linux username into the box at the bottom of the left menu on this page. From now on the commands here will show your real username instead of
youruser.Shut the server down properly. Never just close the window of a running server, in the same way you would not pull the plug on a real one.
sudo poweroff
Your turn
Start the server again. Find out how much free disk space it has, shown in units a human can read (GB, not bytes).
-h to mean "human-readable".df -h. Look at the line that ends with /. That is your main disk. The Avail column is the free space.Checkpoint
- I can log in to
srv-linuxand I know what the prompt looks like. - I ran a
sudocommand and I was not surprised by the invisible password. - I can explain the difference between the host and a guest.
- I know how to save and exit in nano.
Lab 1: Connect the machines
A server nobody can reach is useless. In this lab you discover the four ways VirtualBox can connect a VM to the world, and you build the network that every later lab depends on.
Your job today. The company wants its server to download updates from the internet, but it must also talk privately to the office PC. Find out which kind of virtual network can do what, then set it up.
Before you type anything: five ideas
Click each word and read its explanation. You will need all five today: IP address, ping, network adapter, DHCP, firewall.
Copy this table into your notes and fill it in as you go. Write your prediction first, then test.
| Mode | VM's IP address | VM reaches internet? | VMs reach each other? | Host reaches VM? |
|---|---|---|---|---|
| NAT | ||||
| Bridged | ||||
| Host-only | ||||
| Internal network |
Your testing toolkit
You will repeat these same tests in every part. On the server:
ip -br addr ping -c 3 8.8.8.8 ping -c 3 <client-ip>
What does this mean?
- ip -br addr
- Show this machine's network adapters and their IP addresses.
-brmeans "brief": one short line per adapter. Ignore the line calledlo; that is the machine talking to itself. - ping -c 3 8.8.8.8
- Send 3 test messages (
-c 3= count 3) to 8.8.8.8, a Google server that always answers. Replies mean "I can reach the internet". - <client-ip>
- A placeholder. Do not type the
< >signs. Replace the whole thing with the Windows VM's address, for exampleping -c 3 192.168.56.101.
lo UNKNOWN 127.0.0.1/8 enp0s3 UP 10.0.2.15/24
In that example the adapter is called enp0s3 and its address is 10.0.2.15. The /24 is explained under subnet.
On the Windows client, open the Start menu, type PowerShell, and open it:
ipconfig ping 8.8.8.8 ping <server-ip>
What does this mean?
- ipconfig
- The Windows way to show IP addresses. Look for the line IPv4 Address.
- ping
- Same idea as on Linux. Windows stops by itself after 4 messages, so no
-cis needed.
GuidedPart A: NAT, the default
For each VM, open Settings > Network > Adapter 1 in VirtualBox and check that Attached to says NAT. Start both VMs.
Find each VM's IP address with your toolkit. You will probably see
10.0.2.15on both. That is not an error: under NAT each VM lives behind its own private pretend router, so they never meet.Run the three tests (internet, other VM, and from your host try
ping 10.0.2.15). Write the results in your table.
GuidedPart B: Bridged
Change Adapter 1 on both VMs to Bridged Adapter. In the Name list choose the network card the host is really using: usually Wi-Fi on a laptop, or Ethernet (the cable) on a computer-lab PC. You can do this while the VM is running.
Ask for a new address. The easy way is to reboot each VM. On Windows you can run
ipconfig /renewinstead.Look at the addresses now. They should resemble the host's own address, as if the VMs were two extra computers plugged into the same network. Repeat the three tests.
Many campus networks refuse bridged VMs. If a VM gets no address, write "blocked by the network" in your table and move on. Think about why an administrator would want that.
GuidedPart C: Host-only
In the main VirtualBox window open File > Tools > Network Manager and choose the Host-only Networks tab. If the list is empty, click Create. Note the address range (normally
192.168.56.x) and make sure its DHCP server is enabled.Change Adapter 1 on both VMs to Host-only Adapter. Reboot the VMs and repeat the tests.
Pinging the Windows client will probably fail even though the network is fine. Windows Firewall silently drops incoming pings. Allow them: open the Start menu, type PowerShell, right-click it, choose Run as administrator, then:
New-NetFirewallRule -DisplayName "Allow ping" -Protocol ICMPv4 -IcmpType 8 -Direction Inbound -Action Allow
What does this mean?
- New-NetFirewallRule
- Add a new rule to Windows Firewall.
- -DisplayName "Allow ping"
- The label you will see in the firewall's list of rules.
- -Protocol ICMPv4 -IcmpType 8
- The technical name for a ping request. ICMP is the "are you there?" language of networks; type 8 is the question itself.
- -Direction Inbound -Action Allow
- Let these messages come in instead of dropping them.
Remember this moment. "The network is fine but a firewall drops the traffic" is the single most common problem in real cloud systems.
GuidedPart D: Internal network
Change Adapter 1 on both VMs to Internal Network and type the same name on both:
labnet. Reboot both.Check the addresses. Nobody hands out addresses on this network (there is no DHCP), so the server has none, and Windows invents a 169.254.x.x address for itself.
Give the server an address by hand. First find your adapter's name, then use it in the second command.
ip -br link sudo ip addr add 10.10.10.1/24 dev enp0s3
What does this mean?
- ip -br link
- List the network adapters and their names, without addresses. Yours is usually
enp0s3. If it is different, use your name in the next command. - ip addr add 10.10.10.1/24
- Add the address 10.10.10.1 to an adapter.
/24means "my neighbours are everyone whose address starts with 10.10.10." - dev enp0s3
- "On the device called enp0s3". This says which adapter receives the address.
- (temporary)
- An address added this way disappears when the machine reboots. Good for experiments.
Give the client an address too, in an administrator PowerShell. If it complains about the adapter name, run
Get-NetAdapterto see the real name and use that.New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.10.10.2 -PrefixLength 24
What does this mean?
- New-NetIPAddress
- Give a Windows network adapter a fixed address.
- -InterfaceAlias "Ethernet"
- Which adapter. "Ethernet" is the usual name of the first one.
- -PrefixLength 24
- The Windows way of writing
/24.
Repeat the three tests and complete your table. Then put the client back to automatic addressing:
Remove-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.10.10.2 -Confirm:$false Set-NetIPInterface -InterfaceAlias "Ethernet" -Dhcp Enabled
Check your table
Only look after you have filled in your own. If a result differs, find out why before moving on.
| Mode | Internet | VM to VM | Host to VM |
|---|---|---|---|
| NAT | Yes | No | No (only with port forwarding, Lab 2) |
| Bridged | Yes | Yes | Yes |
| Host-only | No | Yes | Yes |
| Internal network | No | Yes | No |
GuidedPart E: The network you keep
No single mode gives the company everything. Real servers solve this by having two network adapters: one road to the internet, and one private road between your own machines.
Shut down both VMs. On each one, set Adapter 1 back to NAT. Then open the Adapter 2 tab, tick Enable Network Adapter, and attach it to Host-only Adapter. Start both VMs.
Windows sets up its second adapter by itself. Ubuntu Server does not. Check: the new adapter (usually
enp0s8) shows as DOWN with no address.ip -br addr
A server should never change its address, or clients could not find it. So give it a static address, permanently this time. Ubuntu keeps network settings in netplan files. Create a new one:
sudo nano /etc/netplan/60-hostonly.yaml
What does this mean?
- sudo nano
- Open the nano text editor as administrator, because system settings files are protected.
- /etc/netplan/
/etcis the folder where Linux keeps almost all its settings.netplanis the sub-folder for network settings.- 60-hostonly.yaml
- The new file's name. The name is your choice; it must end in
.yaml.
Type exactly this into the file. The file is written in YAML, where indentation is part of the meaning: use the space bar, two spaces per level, never the Tab key.
network: version: 2 ethernets: enp0s8: dhcp4: false addresses: [192.168.56.10/24]What does this mean?
- ethernets:
- "Here come settings for wired network adapters."
- enp0s8:
- The adapter these settings belong to. Use your own adapter's name if it differs.
- dhcp4: false
- Do not ask anyone for an automatic address.
- addresses: [...]
- Use this address instead.
.10is safe because VirtualBox's DHCP only hands out.101and above.
Save with Ctrl+O, Enter, then exit with Ctrl+X.
Protect the file, apply the settings, and look at the result.
sudo chmod 600 /etc/netplan/60-hostonly.yaml sudo netplan apply ip -br addr
What does this mean?
- chmod 600
- "Change mode": set who may read the file.
600means only its owner (the administrator) can read and write it. Netplan prints a warning if its files are readable by everyone. - netplan apply
- Read all the netplan files and make the network match them, right now, without rebooting.
lo UNKNOWN 127.0.0.1/8 enp0s3 UP 10.0.2.15/24 enp0s8 UP 192.168.56.10/24
An error fromnetplan applyalmost always means wrong indentation. Open the file again and compare it with the box above, space by space.
Your turn
The boss wants the office PC to have a fixed address too. Give win-client the permanent address 192.168.56.30 on its host-only adapter, and prove that the server can still ping it.
Get-NetAdapter and ipconfig together to work out which name belongs to the 192.168.56.x one. It is often called "Ethernet 2".New-NetIPAddress -InterfaceAlias "Ethernet 2" -IPAddress 192.168.56.30 -PrefixLength 24. Then on the server: ping -c 3 192.168.56.30.Challenge
Draw your finished network on paper: the host, both VMs, all four adapters with their addresses, the two networks, and the internet. Draw the path of a ping from the client to the server, and the path of sudo apt update from the server to the internet. A good drawing here will save you hours later.
Checkpoint
- The server shows
192.168.56.10on its second adapter. ping -c 3 8.8.8.8works on the server.- The client can ping
192.168.56.10. - My host can ping
192.168.56.10.
Hand in: your completed table, a screenshot of the checkpoint pings, your network drawing, and two or three sentences answering: why did both VMs have the same IP address under NAT, and why was that not a conflict?
How this looks in a real cloud
NAT is a private subnet behind a "NAT gateway": servers can fetch updates, but nobody outside can start a conversation with them. Bridged is a server with a public address. Host-only is a private subnet you reach through a management connection. Internal network is an isolated subnet, the kind used for databases. Your two-adapter design in Part E is the standard cloud pattern.
Lab 2: Make the server useful
A server exists to serve. Today yours gets three jobs: letting you log in from another computer, hosting the company website, and sharing files with the office PC.
Your job today. The boss wants to manage the server from her desk, see a company web page, and save documents to a shared folder. You need the two-adapter network from Lab 1, Part E.
Before you type anything: four ideas
Read these first: service, package, port, SSH.
GuidedPart A: Log in from far away with SSH
Install the SSH server program and check that it is running.
sudo apt update sudo apt install -y openssh-server sudo systemctl status ssh
What does this mean?
- apt install
- Download and install a program.
- -y
- Answer "yes" automatically when apt asks "Do you want to continue?"
- openssh-server
- The name of the package that lets other computers log in to this one.
- systemctl status ssh
- systemctl manages services.
statusasks "is it running?" Look for the green words active (running). Press q to leave the status screen.
Connect from the Windows client. Windows 10 and 11 already include an SSH program. The first time, it asks whether you trust the server's fingerprint: type
yes. Then enter your Linux password.ssh youruser@192.168.56.10What does this mean?
- ssh
- Open a secure remote terminal.
- youruser@192.168.56.10
- "Log in as this user, on the computer at this address." Same shape as an email address: who @ where.
Look at the prompt. It now says
srv-linux, although you are sitting at Windows. Everything you type is happening on the server.Passwords can be guessed. A key pair cannot. Type
exitto come back to Windows, then create your key pair. Press Enter at every question to accept the defaults.exit ssh-keygen -t ed25519
What does this mean?
- exit
- Leave the server and return to the Windows prompt.
- ssh-keygen
- "Key generator". Creates two matching files: a private key (your secret, never share it) and a public key (safe to hand out, ends in
.pub). - -t ed25519
- The type of key. Ed25519 is a modern, strong and short kind.
Install your public key on the server. This is one long line; use the Copy button. It asks for your Linux password one last time.
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh youruser@192.168.56.10 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"What does this mean?
- type ...id_ed25519.pub
- Windows command that prints the contents of your public key file.
- |
- The pipe. It sends the output of the command on the left into the command on the right.
- ssh ... "..."
- Log in to the server, run the commands inside the quotes, and leave.
- mkdir -p ~/.ssh
- Make a folder called
.sshin your home folder (~means "my home").-pmeans "no error if it already exists". - &&
- "And then, if that worked, do the next thing."
- cat >> ...authorized_keys
- Add the incoming key to the end of the list of keys allowed to log in.
>>means "append to this file". - chmod 700 / 600
- Make the folder and file private to you. SSH refuses keys kept in files that other users could change.
Connect again. This time there is no password question. Stay connected: from now on, do all server work through this SSH window, not the black VirtualBox screen. You can finally copy and paste, and it is how real cloud servers are managed, because they have no screen at all.
ssh youruser@192.168.56.10
GuidedPart B: A website, and a locked door
Install the nginx web server and replace its welcome page with your own. Put your real name in it.
sudo apt install -y nginx echo "<h1>Served by $(hostname) - YOUR NAME</h1>" | sudo tee /var/www/html/index.html curl http://localhost
What does this mean?
- echo "..."
- Print the text between the quotes.
- $(hostname)
- Run the
hostnamecommand and paste its answer right here, so the page shows the server's name. - | sudo tee file
- tee writes what it receives into a file. We use it because the web folder belongs to the administrator, and
sudo echo ... > filewould not work. - /var/www/html/index.html
- The file nginx shows when somebody visits the site.
- curl http://localhost
- curl fetches a web page and prints it as text: a browser without a screen. localhost means "this same machine".
On the Windows client, open a browser and go to
http://192.168.56.10. You should see your page.Turn on the server's firewall, ufw. Allow SSH first, or the firewall will cut off the very connection you are typing in.
sudo ufw allow OpenSSH sudo ufw enable sudo ufw status
What does this mean?
- ufw allow OpenSSH
- Add a rule: let SSH connections in.
- ufw enable
- Switch the firewall on, now and at every boot. From this moment everything not explicitly allowed is blocked.
- ufw status
- Show the list of rules.
Refresh the browser on the client. The page no longer loads. nginx is running perfectly, but the firewall only lets SSH through. Open the web door and refresh again.
sudo ufw allow 80/tcp
What does this mean?
- 80/tcp
- Port 80 is the door number that websites use. TCP is the kind of connection web browsers make.
Now reach the site from your host, through the NAT adapter, using port forwarding. In VirtualBox open
srv-linuxSettings > Network > Adapter 1 > Advanced > Port Forwarding. Add a rule: Protocol TCP, Host Port 8080, Guest Port 80, leave the other boxes empty. On your host, browse tohttp://localhost:8080.
Your turnPart C: A shared folder
Windows shares folders using a language called SMB. The Linux program that speaks it is Samba. Your goal: the folder /srv/share on the server appears on the Windows client as \\192.168.56.10\labshare, protected by a username and password. A file created from Windows must show up on the server.
Try with as few hints as you can. Note how many you needed.
samba. (2) Create the folder and make yourself its owner. (3) Describe the share at the end of Samba's settings file, /etc/samba/smb.conf. (4) Give your user a Samba password. (5) Restart the service. (6) Open the firewall. Which earlier commands can you reuse?sudo mkdir -p /srv/share and take ownership with sudo chown $USER:$USER /srv/share (chown = change owner). A share is described by a name in square brackets followed by settings such as path, read only and valid users.sudo smbpasswd -a youruser. The service is called smbd. ufw knows an application profile named Samba.sudo apt install -y samba sudo mkdir -p /srv/share sudo chown $USER:$USER /srv/share sudo nano /etc/samba/smb.conf
Add at the very end of the file, then save and exit:
[labshare]
path = /srv/share
browseable = yes
read only = no
valid users = yourusersudo smbpasswd -a youruser
testparm -s
sudo systemctl restart smbd
sudo ufw allow Samba
What does this mean?
- smbpasswd -a
- Add a user to Samba's password list and set their sharing password.
- testparm -s
- Check the settings file for mistakes before you restart.
- systemctl restart smbd
- Restart the Samba service so it reads the new settings.
On the client, type \\192.168.56.10\labshare into the File Explorer address bar, or map it as drive Z:
net use Z: \\192.168.56.10\labshare /user:youruserCreate a text file there, then check on the server with ls -l /srv/share.
Challenge
The boss wants a second website, for staff only, on the same server. Make nginx serve a different page on port 8080. It must open from the Windows client at http://192.168.56.10:8080 and from your host at http://localhost:8081.
server { } block that says listen 8080; with its own root folder (look in /etc/nginx/sites-available/default for the pattern, and run sudo nginx -t to test your settings before sudo systemctl reload nginx). Then the firewall. Then VirtualBox.Checkpoint
- I can SSH from the client to the server without typing a password.
- My web page opens from the client at
http://192.168.56.10. - My web page opens from the host at
http://localhost:8080. - A file I created in Windows appears in
/srv/shareon the server.
Hand in: screenshots of the checkpoint items, the output of sudo ufw status, how many Samba hints you used, and a short answer: in Part B step 4 the web server was running perfectly, so why could the client not see the page?
How this looks in a real cloud
ufw rules are what clouds call security groups, and "allow SSH before you enable" is a lesson many engineers learn the hard way. Port forwarding is how a load balancer exposes one door of a private machine. And key pairs are the normal way to log in to cloud Linux servers; most providers will not even offer a password.
Lab 3: Save, copy and move servers
On real hardware, one bad command can cost a day of reinstalling. A virtual machine is only files on a disk, and files can be saved, copied and carried. That changes everything.
Your job today. Protect the server you built, destroy it on purpose to prove the protection works, then copy it to make a second server in minutes.
Before you type anything: three ideas
Snapshot, clone, appliance (.ova).
GuidedPart A: Snapshot, break, restore
In the VirtualBox window select
srv-linux, click the small menu icon beside its name and choose Snapshots. Click Take and name the snapshotservices-working. You can do this while the VM runs.Now break the server on purpose. Yes, really.
sudo rm -rf /etc/nginx sudo systemctl restart nginx
What does this mean?
- rm
- "Remove". Deletes files. There is no recycle bin on a Linux server: deleted means gone.
- -rf
r= the folder and everything inside it.f= force, do not ask questions. Together they are the most dangerous letters in Linux. Always read the path twice before pressing Enter.- /etc/nginx
- The folder holding all of nginx's settings.
The restart fails and the website is dead. On a physical server you would now be reinstalling.
Shut the VM down (
sudo poweroff). In the Snapshots view selectservices-workingand click Restore. Untick "Create a snapshot of the current machine state": you do not want to keep the broken version.Start the VM and reload the web page from the client. It is back, as if nothing had happened.
Take a second snapshot called
after-restore. Then, on your host, open the VM's folder (right-click the VM > Show in Explorer / Finder) and look inside itsSnapshotssub-folder.You will find small disk files with long names. A snapshot does not copy the whole disk. It freezes the current disk and writes every later change into a new differencing disk. That is why snapshots are instant, and also why a snapshot is not a backup: if the original disk file is lost, every snapshot is useless.Delete the
after-restoresnapshot (select it, click Delete). VirtualBox merges its changes back. The running state of your VM does not change.
GuidedPart B: Clone the server
Shut down
srv-linux. Right-click it and choose Clone. Name the clonesrv-linux-2. For MAC Address Policy choose Generate new MAC addresses for all network adapters (what is a MAC address?). Choose Full clone.Leave
srv-linuxpowered off and start onlysrv-linux-2. Log in at its black console window and look around withhostnameandip -br addr. Same name, same address, same users, same website. It is a perfect twin, and that is a problem: two machines with the same identity cannot share a network.Give the twin its own name and address. In the netplan file, change
192.168.56.10to192.168.56.11.sudo hostnamectl set-hostname srv-linux-2 sudo nano /etc/netplan/60-hostonly.yaml sudo netplan apply
What does this mean?
- hostnamectl set-hostname
- Change the computer's name permanently.
Two hidden identities were copied too. Replace them, change the web page so you can tell the twins apart, and reboot.
sudo rm /etc/machine-id sudo systemd-machine-id-setup sudo rm /etc/ssh/ssh_host_* sudo dpkg-reconfigure openssh-server echo "<h1>Served by srv-linux-2 - YOUR NAME</h1>" | sudo tee /var/www/html/index.html sudo reboot
What does this mean?
- /etc/machine-id
- A unique serial number Linux creates for itself at installation. See machine ID. We delete it and let
systemd-machine-id-setupcreate a fresh one. - /etc/ssh/ssh_host_*
- The server's own SSH host keys, the source of the fingerprint you accepted in Lab 2. The
*means "every file whose name starts like this". - dpkg-reconfigure openssh-server
- Re-run the SSH package's setup, which creates new host keys.
Start
srv-linuxas well. From the client, browse tohttp://192.168.56.10andhttp://192.168.56.11. Two web servers, and the second took minutes instead of hours.
Your turn
Make another clone of srv-linux, but this time a linked clone. Compare the size on disk of three folders on your host: the original VM, the full clone, the linked clone. Then delete the linked clone completely.
Challenge
Package srv-linux-2 into a single .ova file that could be carried on a USB drive. Prove the file is complete: delete srv-linux-2 with all its files, then bring it back to life from the .ova. Better still, swap files with a classmate and boot each other's server. Record the size of the .ova and compare it with the VM's folder.
Checkpoint
- After the restore,
srv-linuxserves its web page again. - Both servers answer at the same time on
.10and.11. - My imported appliance boots.
Hand in: a screenshot of the snapshot tree, both web pages side by side, the sizes you recorded (original, full clone, linked clone, .ova), and a short answer: why is a linked clone so much smaller, and what happens to it if the original VM is deleted?
When you finish, keep srv-linux-2 powered off to save memory.
How this looks in a real cloud
A snapshot is a "volume snapshot". A clone or .ova is a machine image, the template that every new cloud server is launched from. The identity clean-up you did by hand in Part B is done automatically by a tool called cloud-init the first time a Linux image boots in the cloud.
Lab 4: Control and resize without the mouse
Cloud engineers manage thousands of servers and never click on any of them. Today you stop using the VirtualBox window and start giving orders by command, then you change how powerful your server is.
Your job today. The company is growing. Run the server with no window, make it smaller and bigger, measure the difference, and give it a second disk for data.
Before you type anything: three ideas
VBoxManage, headless, vCPU.
GuidedPart A: Meet VBoxManage
Open a terminal on your host. On macOS and Linux,
VBoxManageworks immediately. On a Windows host, first move into VirtualBox's folder:cd "C:\Program Files\Oracle\VirtualBox" .\VBoxManage.exe --version
What does this mean?
- cd "folder"
- "Change directory": walk into that folder. The quotes are needed because the path contains a space.
- .\VBoxManage.exe
.\means "the program in this folder". On Windows, type.\VBoxManage.exeeverywhere this page saysVBoxManage.
Look around.
VBoxManage list vms VBoxManage list runningvms VBoxManage showvminfo "srv-linux"
What does this mean?
- list vms
- Every VM VirtualBox knows about.
- list runningvms
- Only those switched on right now.
- showvminfo "name"
- Everything about one VM: memory, CPUs, disks, adapters. It is long; scroll up to read it.
Shut down
srv-linuxif it is running. Now start it headless: no window appears at all. Give it half a minute to boot, then connect the way you would reach a cloud server.VBoxManage startvm "srv-linux" --type headless ssh youruser@192.168.56.10What does this mean?
- startvm
- Power on a VM.
- --type headless
- Run it invisibly in the background.
- ssh ...
- Your host can use SSH too, thanks to the host-only network. It will ask for your password, because your key lives on the Windows client, not on the host.
Type
exitto leave the server, then switch it off politely from the host.VBoxManage controlvm "srv-linux" acpipowerbutton
What does this mean?
- controlvm
- Send an order to a VM that is running.
- acpipowerbutton
- Pretend somebody pressed the physical power button. Linux notices and shuts down cleanly. (The other option,
poweroff, is like pulling the plug.)
GuidedPart B: Smaller, then bigger
With the server powered off, shrink it and start it.
VBoxManage modifyvm "srv-linux" --memory 1024 --cpus 1 VBoxManage startvm "srv-linux" --type headless
What does this mean?
- modifyvm
- Change the settings of a VM that is switched off.
- --memory 1024
- Give it 1024 MB (1 GB) of RAM.
- --cpus 1
- Give it one virtual CPU.
Check from inside that the server really sees the new size.
free -h nproc
What does this mean?
- free -h
- Show memory, human-readable. Read the total column of the Mem line. It is a little less than what you gave, because the kernel keeps some for itself.
- nproc
- "Number of processors" the system can see.
Power off again, grow it with
--memory 2048 --cpus 2, start it and re-check. Making one machine bigger is called vertical scaling. Notice you had to switch the machine off to do it; most clouds have the same rule.Put the CPUs to work for one minute, and watch your host's Task Manager (or Activity Monitor) at the same time. Write down the
bogo ops/snumber at the end.sudo apt install -y stress-ng stress-ng --cpu 2 --timeout 60s --metrics-brief
What does this mean?
- stress-ng
- A tool that keeps the computer busy on purpose, for testing.
- --cpu 2
- Start two workers, one per vCPU.
- --timeout 60s
- Stop after 60 seconds.
- --metrics-brief
- Print a score at the end. "Bogo ops" are made-up units; only compare them with other runs on the same machine.
Your turn
Task 1. Cloud providers sell cheap "shared CPU" servers. Find out how: limit srv-linux to 50% of each CPU it owns, run the same stress test, and compare the scores. Then remove the limit.
modifyvm or controlvm?VBoxManage controlvm "srv-linux" cpuexecutioncap 50, run the test, then the same command with 100. The score should roughly halve.Task 2. Are you overcommitting? Find how many CPU threads and how much RAM the host computer really has. Add up the vCPUs and memory given to all your VMs. Is the total bigger than what really exists?
showvminfo shows the numbers for each VM. On a Windows host, Task Manager > Performance shows "Logical processors" and total memory.GuidedPart C: A second disk for data
Shut down
srv-linux. Open Settings > Storage, select the controller that holds the existing disk, click the Add hard disk icon, then Create. Choose type VDI, leave Pre-allocate Full Size unticked, size 2 GB, namedata. Select it, attach it, start the VM.Find the new disk. Look for one of about 2G with nothing listed under it.
lsblk
What does this mean?
- lsblk
- "List block devices", meaning disks.
sdais the first disk,sdbthe second. Entries such assda1,sda2are partitions, the sections inside a disk.
NAME SIZE TYPE MOUNTPOINTS sda 25G disk ├─sda1 1M part └─sda2 25G part / sdb 2G disk
Stop and check. In the next step, make sure the name you type is the empty 2G disk. Formattingsdawould erase your server. (If that ever happens, you know about snapshots now.)Prepare the disk and connect it to a folder.
sudo mkfs.ext4 /dev/sdb sudo mkdir /mnt/data sudo mount /dev/sdb /mnt/data df -h /mnt/data
What does this mean?
- mkfs.ext4 /dev/sdb
- "Make filesystem": format the disk with ext4, the standard Linux format.
/dev/is where Linux lists its hardware. - mkdir /mnt/data
- Create an empty folder that will become the door to the disk.
- mount
- Linux has no D: drive. Instead you mount a disk onto a folder; whatever you save in that folder lands on that disk.
- df -h /mnt/data
- Show the size and free space of the disk behind that folder.
On the host, look at the size of the file
data.vdi. It is a few megabytes, not 2 GB. The file only grows as data is written. Cloud providers call this thin provisioning.
Challenge
Without touching the VirtualBox window: take a snapshot of srv-linux named after-lab4, list its snapshots, create a file on the server, then go back to the snapshot and prove the file has vanished.
VBoxManage snapshot with nothing after it and read the usage text. Remember from Lab 3 what state the VM must be in before a restore.Checkpoint
- I can start, reach and stop
srv-linuxwithout opening the VirtualBox window. nprocandfree -hmatch the sizes I set./mnt/datashows a 2 GB disk.
Hand in: your two stress-test scores with one sentence explaining the difference, your overcommitment numbers, and the output of df -h /mnt/data and of your snapshot list.
How this looks in a real cloud
modifyvm is choosing a server size from a price list. A CPU cap is how "shared" servers are sold cheaply. Overcommitment is the business model of the cloud: providers sell more virtual CPUs than they own, because customers rarely use them all at once. Your data.vdi is a "block storage volume". And VirtualBox is a type 2 hypervisor; data centres use type 1, but the ideas you practised are the same.
Lab 5: Servers from a recipe
It took you four labs to build one server by hand. Nobody runs a cloud that way. Today you write the server down as a recipe and let a tool cook it, as many times as you like.
Your job today. Build a web server with a single command. Destroy it. Rebuild it, identical. Then serve two at once. Your final challenge is to recreate your entire Lab 2 server without typing a single command inside it.
Before you type anything: five ideas
Vagrant, Vagrantfile, box, provisioning, infrastructure as code.
win-client, srv-linux and srv-linux-2 first to free memory. Today you test from your host's browser.GuidedPart A: One server from one file
First check whether Vagrant is already installed on the host by running the command below; on a computer-lab PC your instructor may have installed it for you. If you get
command not found, install the latest Vagrant from HashiCorp's official download page (search for "Vagrant install"). Installing needs administrator rights on the host, so on a lab PC ask your instructor. With VirtualBox 7.2 you need Vagrant 2.4.9 or newer. Close and reopen your terminal, then check:vagrant --version
Make a folder for the project and go into it. Every Vagrant project lives in its own folder.
mkdir vagrant-lab cd vagrant-lab
Inside that folder, create a text file named exactly
Vagrantfile, capital V, no extension. Use a plain text editor such as Notepad or VS Code, not Word. (In Notepad, choose "All files" as the type when saving, or you will getVagrantfile.txt.)Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-24.04" config.vm.hostname = "web-auto" config.vm.network "private_network", ip: "192.168.56.20" config.vm.provider "virtualbox" do |vb| vb.name = "web-auto" vb.memory = 1024 vb.cpus = 1 end config.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y nginx echo "<h1>Built automatically - YOUR NAME</h1>" > /var/www/html/index.html SHELL endWhat does this mean?
- Vagrant.configure("2") do ... end
- The wrapper every Vagrantfile needs. Everything between
doand the finalenddescribes your machine. - config.vm.box
- The ready-made disk to start from: Ubuntu 24.04, already installed. This replaces the whole OS installation you did by hand.
- config.vm.hostname
- The computer's name. You did this with
hostnamectlin Lab 3. - private_network, ip:
- Add a host-only adapter with a static address. This one line replaces all of Lab 1, Part E.
- vb.memory / vb.cpus
- The size of the machine, as in Lab 4.
- provision "shell"
- Commands to run inside the new server the first time it starts. They run as administrator, so no
sudois needed. Everything between<<-SHELLandSHELLis the script. - apt-get
- The older, script-friendly brother of
apt. Same job.
Build it, and time how long it takes. Read the messages scrolling by: you will recognise every stage.
vagrant up
When it finishes, browse to
http://192.168.56.20on your host. Open the VirtualBox window too:web-autois there, running headless, a VM like any other.Log in. You do not need to know any password or address; Vagrant set up a key pair for you.
vagrant ssh exit
Destroy the server completely. Check that the web page is gone. Then rebuild it.
vagrant destroy -f vagrant up
What does this mean?
- vagrant destroy -f
- Switch off the VM and delete it and its disk.
-f= force, do not ask "are you sure?". Your Vagrantfile is untouched.
The second build is much faster because the box is already downloaded, and the result is identical. You no longer need to protect this server, because you can always make another. Engineers call this treating servers as cattle, not pets.Other commands worth knowing:
vagrant status(is it running?),vagrant halt(shut down but keep),vagrant provision(run the script again).
Your turnPart B: Two servers
The website is popular and one server is not enough. Change your Vagrantfile so that a single vagrant up creates two servers, web1 at 192.168.56.21 and web2 at 192.168.56.22, each showing its own name on its page. Give each 768 MB of memory. Run vagrant destroy -f before you start editing.
config.vm.define "name" do |node| ... end. Inside the block, write node.vm... where you wrote config.vm... before.(1..2).each do |i| ... end. Inside a text in double quotes, #{i} becomes the number, so "web#{i}" gives web1, then web2.Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-24.04"
(1..2).each do |i|
config.vm.define "web#{i}" do |node|
node.vm.hostname = "web#{i}"
node.vm.network "private_network", ip: "192.168.56.2#{i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = 768
vb.cpus = 1
end
node.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y nginx
echo "<h1>Hello from web#{i} - YOUR NAME</h1>" > /var/www/html/index.html
SHELL
end
end
endRun vagrant up, then vagrant status. To log in to one of them: vagrant ssh web1.
vagrant destroy -f.GuidedPart C: A VM versus a container
Start
srv-linuxagain. Run one more web server on it, this time in a container, and time it.sudo apt install -y docker.io time sudo docker run -d --name web-c -p 8081:80 nginx
What does this mean?
- docker.io
- Ubuntu's package name for Docker, the most common container tool.
- time
- Measure how long the rest of the line takes.
- docker run nginx
- Download the ready-made
nginximage, if needed, and start a container from it. - -d
- "Detached": run in the background.
- --name web-c
- A name of your choice for the container.
- -p 8081:80
- Port forwarding again: the server's port 8081 leads to the container's port 80.
Browse to
http://192.168.56.10:8081. Now start a second one withsudo docker run -d --name web-c2 -p 8082:80 nginxand notice: once the image is downloaded, a new container starts in about a second. Your VM needed minutes.Find out why.
uname -r sudo docker exec web-c uname -r
What does this mean?
- uname -r
- Print the version of the kernel this system runs on.
- docker exec web-c ...
- Run a command inside the container named web-c.
The two answers are identical. A VM carries a complete operating system of its own on pretend hardware. A container is only a fenced-off program borrowing the kernel of the machine it runs on. Lighter and faster, but less separated, and it is why you cannot run a Windows container on this Linux server.
ChallengeThe capstone
Prove you understood every lab. Write one Vagrantfile that rebuilds your complete Lab 2 server with no manual steps. After vagrant destroy -f and vagrant up, all of this must be true:
- The server is called
office-srvand has the static address192.168.56.40. - Your web page, with your name, opens at
http://192.168.56.40. - A password-protected share called
labsharecan be opened fromwin-client. - The firewall is on and allows only SSH, the website and Samba.
vagrant sshstill works afterwards.
ufw enable asks for confirmation unless you write ufw --force enable. And remember Lab 2's lesson about which rule must exist before the firewall switches on, or Vagrant locks itself out.smbpasswd normally asks you to type a password twice. With -s it reads from a pipe instead: (echo "secret"; echo "secret") | smbpasswd -s -a vagrant. The box's built-in user is named vagrant. To add lines to the end of smb.conf from a script, use cat >> /etc/samba/smb.conf <<EOF ... EOF.Checkpoint
vagrant upgives me a working web page with no manual steps.vagrant statusshowedweb1andweb2running together.- I can explain the difference between a VM and a container in two sentences.
Hand in: your capstone Vagrantfile, a screenshot of vagrant status with both web pages open, your build times (first vagrant up, second vagrant up, container), and a paragraph: what are two advantages of describing a server in a file instead of building it by hand?
How this looks in a real cloud
A box is a machine image. The Vagrantfile plays the part that tools like Terraform play in production. The provisioning script is the "user data" you hand to a new cloud server. Your loop in Part B is a miniature auto-scaling group: one definition, stamped out as many times as demand requires.
What you built, and what the cloud calls it
Everything you did on one ordinary computer has a twin on a real cloud platform. The names differ between providers; the ideas do not.
| You did this in VirtualBox | Lab | The cloud calls it |
|---|---|---|
| Created a VM | before 1 | Launching an instance |
| NAT adapter | 1 | Private subnet with a NAT gateway |
| Host-only / internal network | 1 | Private or isolated subnet in a virtual network (VPC) |
| ufw rules | 2 | Security groups, firewall rules |
| Port forwarding | 2 | Load balancer, public endpoint |
| SSH key pair | 2 | Instance key pair |
| Snapshot | 3 | Volume snapshot |
| Clone, .ova export | 3 | Machine image, template |
| Fixing the clone's identity | 3 | cloud-init (Linux), Sysprep (Windows) |
| modifyvm --memory --cpus | 4 | Changing instance type (vertical scaling) |
| CPU execution cap | 4 | Shared and burstable instances |
| Extra .vdi disk | 4 | Block storage volume |
| VBoxManage | 4 | Cloud command-line tools and APIs |
| Vagrantfile | 5 | Infrastructure as code (Terraform and similar) |
| Two servers from a loop | 5 | Auto-scaling group (horizontal scaling) |
| Docker container | 5 | Container services, Kubernetes |
Final clean-up. Delete srv-linux-2 and leftover clones, run vagrant destroy -f in your project folder, and remove old .ova files. Keep srv-linux and win-client with their snapshots.
When something goes wrong
First, read the error message slowly. Second, check where you typed the command. Third, look here.
| Problem | Likely cause and fix |
|---|---|
I type my password after sudo and nothing appears | Normal. Linux hides passwords completely. Type it and press Enter. |
command not found | A typo, or the program is not installed yet. Check the spelling; check you did the install step. |
Permission denied | You forgot sudo. Press ↑, go to the start of the line, add it. |
| I cannot leave nano | Ctrl+X. If it asks to save, press Y then Enter. |
| The command never finishes | Ctrl+C stops it. A status screen closes with q. |
| My mouse is trapped in the VM window | Press the host key: Right Ctrl (left ⌘ on a Mac). |
| VM will not start: "VT-x is not available" or "AMD-V is disabled" | Hardware virtualization is switched off in the host's BIOS/UEFI settings. On your own laptop, ask your instructor to help you enable it. On a computer-lab PC, do not change it yourself: tell your instructor or the lab technician. |
| VM is extremely slow and shows a green turtle icon | A Windows host running Hyper-V features (WSL2, Memory Integrity). VirtualBox works, but slowly. Ask your instructor before disabling them. |
| Server pings the client and gets no reply | Windows Firewall. Add the rule from Lab 1, Part C. |
netplan apply shows an error | Indentation. Spaces only, two per level, exactly as shown. |
| SSH says "REMOTE HOST IDENTIFICATION HAS CHANGED" | The server's host keys changed, or another machine now uses that address. On the client run ssh-keygen -R 192.168.56.10 and connect again. |
Locked out after ufw enable | SSH was not allowed first. Log in on the VirtualBox console and run sudo ufw allow OpenSSH. |
| Windows rejects my password for the share | Use the Samba password set with smbpasswd. Check sudo systemctl status smbd. |
| Both servers unreachable after cloning | Two machines share 192.168.56.10. Power one off and finish Lab 3, Part B. |
vagrant up: "VirtualBox version not supported" | Your Vagrant is older than your VirtualBox. Install the latest Vagrant. |
vagrant up does nothing useful; "Vagrantfile not found" | You are in the wrong folder, or the file is named Vagrantfile.txt. |
| The host computer freezes or becomes very slow | Too many VMs running. Power off those you are not using. Headless VMs still use RAM: check VBoxManage list runningvms. |