0% found this document useful (0 votes)
42 views

Week 6 Laboratory Worksheet - Linux Commands

Uploaded by

sujalgajera009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Week 6 Laboratory Worksheet - Linux Commands

Uploaded by

sujalgajera009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Week 6 Laboratory Worksheet part one

Linux Distributions and the Linux Shell


Commands for BASH scripts
Name Sujal Rajubhai Gajera Student ID 1000130692

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.

Why Linux is different to Windows


Question: What is a Linux Distro?
A Linux distribution (or "distro") is a complete operating system built around the Linux kernel. It includes the
kernel itself, as well as a collection of software, utilities, and tools that provide a fully functional operating
system. Different distros can vary widely in terms of their target users, default software, package management
systems, and overall design philosophy.
Here are some key components typically included in a Linux distro:
1. Kernel: The core part of the operating system that interacts directly with the hardware.
2. Package Manager: A tool for installing, updating, and managing software packages. Examples include
APT for Debian-based distros and RPM for Red Hat-based distros.
3. Desktop Environment: The graphical user interface (GUI) that users interact with. Popular
environments include GNOME, KDE Plasma, and XFCE.
4. System Libraries and Utilities: Essential components and tools needed for the operating system and
applications to function.
5. Software Packages: Applications and utilities that come pre-installed or can be installed from
repositories.

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/

Task 1 – Creating a shell program


Every shell program starts with this line, called the shebang:

#!/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 ;

Task 3 – Running scripts and setting permissions


You have to give a program permission to run by changing its security clearance:

Task 4 – if … then … else … and switch statements


The topics at Linuxize show example commands from https://linuxize.com/

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:

You can find more examples here on https://www.cyberciti.biz/faq/bash-infinite-loop/


While 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.

Task 7 – Downloading and installing Oracle Virtual Box


Download the setup program for Oracle Virtual Box from this site: https://www.virtualbox.org/
Make sure you put the installation program in a directory on your Drive C, not on OneDrive or a cloud service.

Task 8 – Revision – What is a Virtual Machine?


Question: Look at the lecture notes for today and explain briefly what Oracle Virtual Box does:
Oracle VirtualBox is a free and open-source virtualization software that allows you to create and run virtual
machines on your computer. With VirtualBox, you can install and use multiple operating systems on a single
physical machine, effectively running different OSes in separate, isolated environments. This is useful for
testing software, running legacy applications, or creating a safe environment for experimenting with new
systems. VirtualBox supports a variety of host and guest operating systems, including Windows, macOS, Linux,
and more.

Question: Why is a Virtual Machine useful?


A virtual machine (VM) is useful for several reasons:

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.

Start your new Virtual Machine and configure it:


Question: What are Guest Additions? (Hint: Google “What are Google Oracle Box Guest Additions?”)
Google Oracle Box Guest Additions are actually a bit of a mix-up in terminology. What you're referring to are
VirtualBox Guest Additions.
VirtualBox Guest Additions are a set of drivers and system applications designed to improve the performance
and usability of virtual machines (VMs) running on Oracle VirtualBox. They provide enhanced integration
between the host and guest operating systems. Here's what they offer:
Key Features of VirtualBox Guest Additions:
1. Seamless Mouse Integration: Allows the mouse pointer to move smoothly between the host and guest
operating systems without needing to capture or release it manually.
2. Improved Graphics Performance: Provides better video support and acceleration for the guest OS,
enabling smoother graphics and higher resolutions.
3. Shared Folders: Allows you to share files and folders between the host and guest OS, making it easy to
exchange data without needing network-based solutions.
4. Clipboard Sharing: Enables copy-paste functionality between the host and guest systems, allowing you
to transfer text and files.

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

You might also like