Week 6 Laboratory Worksheet - Linux Commands
Week 6 Laboratory Worksheet - Linux Commands
Introduction
This week, we will learn about Linux Distributions or Distros, the BASH Shell commands, and how to Virtualise
Linux on Windows.
Learning Outcomes
The Learning Outcomes from this laboratory work are detailed in Appendix 1 of the Course Outline for this
paper. They include:
2. Select and apply systems tools, command line and scripting to configure, maintain, and secure
operating systems in local and virtual settings.
1
Question: Write down the names of three different Linux Distros that were talked
about today.
Ubuntu: Known for its ease of use and strong community support, it's often recommended for beginners.
Fedora: Known for featuring the latest technologies and software, it's popular among developers.
Arch Linux: Known for its simplicity and customizability, it requires a more hands-on approach to set up.
Question: Write down three things that make Linux different to Windows
1. Open Source vs. Proprietary:
Linux: Linux is open source, which means its source code is freely available for anyone
to view, modify, and distribute. This encourages transparency, community collaboration,
and customization.
Windows: Windows is proprietary software developed by Microsoft. Its source code is
not available to the public, and it is distributed under a commercial license.
2. Customization and Flexibility:
Linux: Linux offers a high degree of customization. Users can choose from various
desktop environments, window managers, and distributions, and they can modify nearly
every aspect of the system to suit their needs.
Windows: Windows provides a more standardized user experience with limited
customization options compared to Linux. Most changes are restricted to user interface
settings and some system preferences.
3. Package Management and Software Installation:
Linux: Linux uses package managers (like APT, YUM, or Pacman) to handle software
installation and updates. This system allows for easy installation, updating, and removal
of software packages from repositories.
Windows: Windows primarily relies on individual executable installers for software
installation. While it has its own package management system (like the Windows Store),
it is less central to the overall system management compared to Linux’s package
management approach.
2
Learning Linux BASH Shell commands
The Linux BASH (Bourne Again Shell) is a powerful terminal that is used to control Linux and perform tasks. In
this section, you will learn how to write BASH scripts and learn the important Linux Shell commands. This
section is a summary of example commands from https://linuxize.com/
#!/bin/bash
Good programs always have good documentation too. The # character starts a comment line:
#
# FIRST SHELL SCRIPT
# ================
# This is a simple Linux shell command script that
# demonstrates how run a set of commands as a
# single program.
#
# Revision History
# ================
# 24.08.2023 BRD Original version
#
3
Task 2 – Useful shell commands
touch programName
echo “Hello, world”
echo –n “Hello, world”
clear helloWorld
read variableName ;
4
Task 4 – Case statements
Learn how to write case decisions statements here: https://linuxize.com/post/bash-case-statement/
5
Look carefully at the different way the ; and ;; symbol is used on lines.
6
Task 5 – Making your program go in a loop
You can make a BASH program repeat tasks by adding a loop command like this:
You can also use an if statement to decide if it is time to get out of the loop:
7
Infinite with Exiting Loop
8
Task 6 – Getting ready for Assignment 1
Assignment 1 is all about creating a menu program that lets you make choices and run commands. It uses a
BASH shell script.
You have learnt enough commands now to begin writing the program.
As you write each part, show your tutor what you have done.
There are some parts in the assignment that we have not learnt yet. When you have a script running, explain
to your tutor what you want to do. Your tutor will then help you to code it.
9
Installing Linux on your laptop
We will learn how to install and run Oracle Virtual Box, a powerful virtualisation program. Virtual Box will
allow you to install your own copy of Oracle 22.04 and still have Windows running on your laptop at the same
time.
10
1. Testing and Development: VMs allow developers to test software on different operating systems and
configurations without needing multiple physical computers. This is crucial for ensuring compatibility
and debugging in various environments.
2. Isolation: VMs provide a separate environment from the host system, which can be used to safely run
potentially risky software or experiments without affecting the host OS.
3. Resource Optimization: By running multiple VMs on a single physical machine, you can make better
use of available hardware resources. This is especially valuable in server environments where resources
are pooled and allocated dynamically.
4. Snapshot and Rollback: VMs can take snapshots of their state, making it easy to revert to a previous
state if something goes wrong. This feature simplifies the process of recovering from mistakes or
failures.
5. Legacy Software: VMs enable you to run older operating systems or software that may not be
compatible with modern hardware or OSes, providing a way to access or maintain legacy applications.
6. Training and Simulation: They are useful for training purposes, allowing users to practice in a
controlled environment without the risk of damaging critical systems.
7. Cost Efficiency: Virtualization can reduce hardware costs by allowing multiple virtual machines to run
on a single physical server, reducing the need for additional hardware.
11
Task 9 – Building a Virtual Machine inside Oracle Virtual Box
Start Virtual Box from the shortcut. Click the blue New button to create a new Virtual Machine:
Use the Ubuntu 22.04 ISO image you downloaded in the last session. Give your new virtual machine a sensible
name:
Follow each of the next steps carefully. Use your own sensible names for the machine, your user name, your
password, and other fields. Talk to your team and or your tutor if you need help.
12
Think carefully. What is a good size for an Operating System? (Hint: Don’t use ALL your hard drive space up 😊.)
What does the installation program recommend? Do you have enough space? (Hint: Don’t make it too small…
won’t work properly)
13
14
Task 10 – Starting your Virtual Machine
Ubuntu is not installed yet. We have only installed Virtual Box.
Question: How do we install Ubuntu on Virtual Box? What do we need to do?
1. Download and Install VirtualBox
Download VirtualBox: Go to the VirtualBox website and download the appropriate version for your
operating system.
Install VirtualBox: Run the installer and follow the on-screen instructions to complete the installation.
2. Download Ubuntu ISO
Download Ubuntu: Visit the Ubuntu website and download the ISO file for the version of Ubuntu you
want to install.
3. Create a New Virtual Machine
1. Open VirtualBox: Launch the VirtualBox application.
2. Create New VM:
o Click on the "New" button in the toolbar.
o Name and Operating System: Enter a name for your VM, select "Linux" as the type, and
"Ubuntu" as the version.
o Memory Size: Allocate RAM for the VM. A good starting point is 2048 MB (2 GB) or more if you
have sufficient resources.
o Hard Disk: Choose "Create a virtual hard disk now" and click "Create".
4. Configure the Virtual Hard Disk
Disk Type: Choose "VDI (VirtualBox Disk Image)" and click "Next".
Storage on Physical Hard Disk: Choose either "Dynamically allocated" (grows as needed) or "Fixed
size" (pre-allocated). Click "Next".
File Location and Size: Set the size of the virtual hard disk. A minimum of 25 GB is recommended. Click
"Create".
5. Mount the Ubuntu ISO
1. Select the VM: Highlight your newly created VM in the VirtualBox Manager.
2. Settings: Click on the "Settings" button.
3. Storage: Go to the "Storage" tab.
4. Add ISO:
o Click on the "Empty" entry under "Controller: IDE."
o Click on the disk icon next to "Optical Drive" and select "Choose a disk file".
o Browse and select the downloaded Ubuntu ISO file. Click "Open" and then "OK".
15
6. Start the VM and Install Ubuntu
1. Start the VM: Click the "Start" button in VirtualBox.
2. Boot from ISO: The VM will boot from the ISO file, bringing up the Ubuntu installation menu.
3. Install Ubuntu:
o Choose "Install Ubuntu" from the menu.
o Follow the on-screen instructions to select your language, keyboard layout, and other
preferences.
o Installation Type: Choose "Erase disk and install Ubuntu" (this will only affect the virtual disk)
and click "Install Now".
o Partitioning: Confirm the partitioning setup and proceed.
o Set Up: Enter your time zone, user information, and password when prompted.
o Installation: The installer will copy files and set up Ubuntu. This may take some time.
7. Complete the Installation
Restart: Once the installation is complete, you’ll be prompted to restart the VM. Before doing so,
remove the Ubuntu ISO from the virtual drive by going back to the "Settings" > "Storage" tab and
unmounting the ISO.
Login: After restarting, you’ll be greeted with the Ubuntu login screen. Log in using the credentials you
created during installation.
16
5. Drag and Drop: Supports dragging and dropping files between the host and guest OS.
6. Time Synchronization: Keeps the guest OS's system clock synchronized with the host OS's clock.
7. Enhanced Networking: Improves network performance and support within the guest OS.
How to Install VirtualBox Guest Additions:
1. Start the VM: Boot up your virtual machine in VirtualBox.
2. Mount Guest Additions ISO:
o With the VM running, go to the VirtualBox menu and select "Devices".
o Click on "Insert Guest Additions CD image…". This mounts the Guest Additions ISO inside the
VM.
3. Run the Installer:
o Inside the guest OS, the mounted ISO will appear as a virtual CD drive. Open it and run the
installer script. On Linux guests, this is usually named VBoxLinuxAdditions.run, while on
Windows it will be an executable file.
o Follow the prompts to complete the installation. You may need to provide administrative or
root permissions.
4. Reboot the VM: After installation, restart the virtual machine to apply the changes.
The picture shows Virtual Box after Ubuntu has been installed:
17