Skip to content

Latest commit

 

History

History
253 lines (205 loc) · 13 KB

L01.md

File metadata and controls

253 lines (205 loc) · 13 KB
layout title license
default
Introduction to lab environment and tools
not needed

Introduction

The purpose of this lab is to introduce you to some package management tools for Ubuntu, to show you how to install Virtualbox on your system, and to get you to install an Ubuntu operating system from scratch, using Virtualbox. This will give you an environment that you can use safely in the lab, and also that you can install and use on your home PC, if you wish. The lab will involve the use of some commands with which you may not be familiar. At this stage, we'll just introduce enough to allow you to use the commands to achieve the goals of the lab. We'll revisit many of these commands in later weeks and explain them in more detail.

Before going any further, make sure that your machine is powered on and running the Ubuntu operating system.

Package Management

The labs contain desktop PCs running a version of the Ubuntu operating system. The first steps in mastering your operating system are to become familiar with the tools for installing software and package management, so that you can install and remove software to configure the environment to suit your needs.

There are a number of tools in Ubuntu that support package management, including dpkg, apt, apt-get, aptitude, synaptic, and Ubuntu software center.

In this session we are going to use the command line tools dpkg and apt-get, since they can be used to manage packages in both desktop and server environments. We'll use them to set up our environment with the Virtualbox tool that we'll be using extensively in this module.

  1. First, use dpkg to check that some standard packages are installed on your system, e.g.

    $ dpkg -l | grep gedit
    

This command will search through the names of all of the packages installed on your system and report any that contain the work gedit in them. It's an easy way to check whether or not gedit is installed.

$ dpkg -l | grep gcc

This command does a similar job and allow us to check that we have a C compiler installed.

$ dpkg -l | grep make_nufc_champions_league_winners

This command also behaves the same as before, but this time comes up with no entries, since there is not yet any software package that has this functionality and therefore it cannot be installed. Now check whether or not Virtualbox is already installed on your system.

$ dpkg -l | grep virtualbox

If there is an entry for virtualbox-5.2 then Virtualbox is already installed and you can skip to Using Virtualbox.

  1. To install software packages from the command line, use apt-get, which will download the required package and any dependencies from the software repositories that it knows about, and install it for you. The list of software repositories is maintained mainly in a file, /etc/apt/sources.list, but also in a set of smaller files, contained in the directory /etc/apt/sources.list.d. Use the less and ls commands to have a look at the known repositories:

    $ less /etc/apt/sources.list
    

Use the space bar to page through the list and press q when you want to stop.

$ ls /etc/apt/sources.list.d

We'll create a new file in /etc/apt/sources.list.d to hold a reference to our Virtualbox repository. You can use any text editor with which you are familiar to do this. You'll need to start the editor as the superuser since you'll be writing to a directory that is protected against modification by general users. The most useful editors to use from the command line are vim and nano. Here's an example of what you should do using nano.

$ sudo nano /etc/apt/sources.list.d/virtualbox.list

Now copy and paste the line below into your new file. Note that this is the correct repository for use on Ubuntu 16.04. If you have a different version of Ubuntu, you will need to change xenial to match your distribution name, e.g. trusty for 14.04.

deb http://download.virtualbox.org/virtualbox/debian xenial contrib

nano

then save the file and exit from `nano`.
  1. Add the Oracle public keys for apt-secure. These are used in checking that the downloads really are from Oracle.

    $ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
    $ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
    
  2. Before you can install Virtualbox, you will need to synchronise the package index files from their sources, as follows:

    $ sudo apt-get update
    

Then you can install Virtualbox, using the command

$ sudo apt-get install virtualbox-5.2

This is quite a large package and installation may take a few minutes. When the installation completes, you can start Virtualbox from the command line, as follows:

$ virtualbox &

You should see a window that looks like the one below. virtualbox start

Note there is further guidance for downloading Virtualbox at https://www.virtualbox.org/wiki/Linux_Downloads.

Using Virtualbox

We'll begin by installing a version of Ubuntu Server. We'll be able to do most of the lab work for this module on this system. It is significantly smaller than the desktop version. We'll use a variety of systems during the module but this will be the primary one.

Download OS image

Ubuntu is distributed from the Ubuntu website using DVD images that are provided in the form of .iso files. We are going to use Ubuntu Server 16.04.5. You can download the iso image using the following commands:

$ cd ~/Downloads
$ curl -L -O -J http://releases.ubuntu.com/16.04/ubuntu-16.04.5-server-amd64.iso

The file is about 870M in size and so will take a few minutes to download.

Create a new virtual machine

  1. Select New in the Virtualbox Machine Manager (VMM) window. Give your machine a name, as below.

virtualbox new

  1. Click Next. Continue to accept the default options until your new virtual machine (VM) has been created. You should have a window that looks like the one below.

virtualbox start

Install the OS image

  1. Select the VM and click Start. Select icon with the green upward arrow and browse to the location of your .iso image file. Select the image file and the OS will begin its installation procedure, just as it would on a 'real' machine.

virtualbox start

2. Choose English as the language and select `Install Ubuntu Server` from the next menu. 3. Choose `English` again from the Installation Language menu, then `United Kingdom` when prompted to select your location. 4. Continue to select the default options until you get to `Configure the network` and need to enter a hostname. Choose a name based on your University computer name, e.g `w12345678`, and your server name, e.g. `s01`, so the host name that you choose might be `w12345678-s01`. 5. Enter your full name when prompted, e.g. `John Smith`. 6. You can just use `student` and `northumbria` when prompted for a user name and password. 7. Just choose the defaults until you get to `Partition disks` when you should choose the first option `Guided - use entire disk` 8. Select the disk that you are offered. Don't worry about the warnings - the 'disk' is not the whole hard drive, it's just the one that you created when you created the VM. 9. At the prompt `Write changes to disk`, choose `Yes`. 10. Allow the system to continue installing for a minute or two. 11. At the prompt for `HTTP proxy`, leave the entry blank and `Continue`. 12. Allow the installation to continue, selecting the defaults until you get to `Software selection`. Use the space bar to select `OpenSSH server` and then `Continue`. Allow the installation to proceed for a minute or two. 13. When prompted to `Install the GRUB boot loader to the master boot record`, choose `Yes`. 14. Choose `Continue` when prompted to `Finish the installation`.

Congratulations!!! You have just completed a full install of an Ubuntu Server operating system.

Using your new operating system

  1. Before going further, it's a good idea to update the packages on your new server, as follows:

    $ sudo apt-get update
    $ sudo apt-get upgrade
    
  2. You've going to need a C compiler and the Ubuntu server doesn't have one yet. Time to install one.

    $ sudo apt-get install gcc
    
  3. Although we used the nano editor earlier in this lab, there are many good editors available for Unix/Linux. One powerful editor that is always likely to be available on your system, whether desktop or server, is vim. It's an 'old-school' editor but still the editor of choice for DevOps and Sys admins. In other words, if you need to look after an operating system, it's a good idea to know how to use vim, at least for basic editing tasks. The source code of this web page was written using vim. vim is a modal editor and, as such, is different from any editor that you've used before. Start by working through the vimtutor. It should take you about 30 minutes.

    $ vimtutor
    
  4. Now check your understanding of vim and your C compiler by writing and executing the traditional helloworld program. Use vim to enter the text below.

    #include <stdio.h>
    
    int main() {
      printf("Hello world\n");
      return 0;
    }

Save the file as helloworld.c, then compile and run it.

$ gcc -o helloworld helloworld.c
$ ./helloworld
  1. When you're ready to shut down your system, you can do this from the command line using the shutdown command.

    $ sudo shutdown -h now
    

Linux tutorial

  1. Work through the tutorial at http://hesabu.net/unixtut.
  2. Work through the sections of Learning the Shell from 1. What is "The Shell"? through to 9. Permissions. Don't just read passively. Have a command line open and try everything. Experiment until you are comfortable with these ideas.
  3. Develop your understanding further by reading Chapters 1-6 in The Linux Command Line. Have a command line open and try out what you're reading about.

Homework

The main advantage for you in this module of knowing how to use Virtualbox is that you can create an Ubuntu system that will run on your home PC. This means that you'll be able to carry on working and exploring the operating system when you're not in a University lab.

  1. If you decide that you would like to be able to run an Ubuntu system on your Windows or Mac machine, visit the virtualbox home page. Download the installtion program for your system and install Virtualbox on your machine.

  2. Now work through the section above, Using Virtualbox, again, on your new system.

  3. If you're feeling adventurous, you could also download and install an Ubuntu desktop operating system for use at home. If you want an environment that is just the same as the lab environment, you should download Ubuntu 16.04.5 Xenial Xerus. If you have a 64-bit Windows machine you should download http://releases.ubuntu.com/16.04/ubuntu-16.04.5-desktop-amd64.iso. If you have a different machine, you should check the Ubuntu website for guidance about which image to download. Once you have download the image, you may find the installation instructions useful. See also the official Ubuntu documentation.

  4. You can develop your vim skills further by using the resources at Learning Vim for Beginners.