Lab 1 Linux

Contents

The Computer System

What is a Computer?

The PC

Zero / Thin Client

Laptop

Tablet

Smart-Phone

Lab 1: The Raspberry Pi

Components Required for this Lab

Identifying the components of a Computer System

Detail of the CPU (brain) in the Pi

Getting the Operating System (O/S)

Assemble the Raspberry Pi computer.

Update the operating system.

Optional

Programming with Python

Install the Python (V3) integrated development environment (IDE) IDLE.

Start the Graphical User Interface

Launch IDLE and write one or more of the programs below.

Execute the program

Program Snippets

Getting data

Repeating

Decisions

The Mathematical operators in Python

Optional Exercises

Use of Lists/Arrays

Mathematical Operators

Lab 2: Internetworking with Linux

Configuring a computer for Networking

Connecting two PIs

Configuring a computer for Networking with a static IP address

File transfer – Create a (samba) share on each Pi and view the share

The Computer System

What is a Computer?

A computer is made up of four main components.

  1. The Central Processing Unit (CPU) or ‘brain’
  2. Some sort of input device for getting data into the CPU
  3. An output device to get any information from the processing that has gone on in the CPU
  4. Backing store, i.e. somewhere to keep your data, information, programs etc. when you shut down

The CPU itself is simple and complex at the same time. Essentially it is made up of switches, millions of them. They form components that store data and instructions and process this by performing relatively simple tasks such as addition, subtraction, comparison, incrementing and very basic decisions. To do all this work they rely on memory cells and instruction sets. The Raspberry Pi CPU instruction set is relatively small and is referred to as a Reduced Instruction Set Computer or RISC. The processor name is ARM standing for Advanced RISC Machine (originally Acorn Risk Machine).

The PC

The office workhorse.A personal computer (PC) is a general-purpose computer, whose size, capabilities and original sale price makes it useful for individuals within an organisation.It is intended to be operated directly by an end-user with no intervening ITstaff. This means individuals are often responsible for their computers without any formal IT training. It has led to small organisations not taking charge of their data, leaving it instead to the whims of the local user as to where they store their data and how they secure it. The impact this will have on a business will be considered in the units on Servers and Security.

Zero / Thin Client

The concept of the thin client is to reduce the functionality of the local PC and rely on a server to store resources and run some applications.

This was set to replace the PC because of the reduction in size and the its low power consumption.Thin-client computing was also considered a way of easily maintaining computing services at a reduced total cost of ownership.

Laptop

Portability personified. Limitations? Not as powerful as the same priced PC. Easier to break and harder to repair. If you need portability it’s a must have otherwise use a desktop.

Tablet

Portable easy to use yet no keyboard and nowhere near the power required for the average office worker. The size of the screen is also a drawback.

Smart-Phone

Loveable, fun, great for email. No keyboard and too small a screen. Not powerful at all. Easy to lose!

Lab 1: The Raspberry Pi

The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. The Pi foundation wants to see it being used by kids all over the world to learn Computer Science and programming.

Components Required for this Lab

This worksheet (9 pages), Raspberry Pi, 700mA power supply, Keyboard, Mouse, SD card with the Debian Linux operating system, HDMI cable(with adapter if required), HDMI or DVI screen, CATv cable. These should all be in your tray.

Identifying the components of a Computer System

Identify the components and add the function descriptions

Component / Description
SoC
Input Device(s)
Output Device(s)
Storage(s)
LAN

Detail of the CPU (brain) in the Pi

Broadcom BCM2835. This contains an ARM1176JZFS, with floating point, running at 700Mhz, and a Videocore 4 GPU. The GPU is capable of BluRay quality playback, using H.264 at 40MBits/s. It has a fast 3D core accessed using the supplied OpenGL ES2.0 and OpenVG libraries.

Getting the Operating System (O/S)

Using your laptop, connect to the wired or wireless network. This should give you access to the internet.

Browse to the site and look for the Downloads and find the NOOBS files and then click on the Download Zip button.

Extract the files from the Zip file and make a note of where they are.

Place the SD card into the reader and format it.

Copy the extracted files to the SD card.

Now transfer the card to your raspberry pi.

Assemble the Raspberry Pi computer.

You will need to check the power supply to ensure it can deliver more than 500 milliamps.Ideally 1 amp.

Visually check the SD card is ok.

Make sure all of the components are connected BEFORE you turn on the power.

Power up the Pi and you will see the screen below. Select the Raspbian option recommended.

The install will take around 20 minutes.

The username is Pi and the password is raspberry

Type the Username press the enter key then the Password

Note: You when you enter the Password will NOT be able to see anything on the screen

Don’t start the graphical user interface (GUI) just yet.

Note: The Linux operating system is much more sensitive to case than Windows so be careful when entering TeXt or your commands might not work. Most Linux commands are typed in lower case

Update the operating system.

On Debian Linux operating systems (O/S), for security reasons, you do not have root (administrative) permissions by default so any command you type must start with a special command sudo (all lower case). This tells the O/S you want to run the command as if you were an administrative or root user

So, to first check your system is up to date, type

sudo apt-get update

This should only take a minute or two.

Then get the latest version of the operating system

sudo apt-get upgrade

This may take a little longer say, 5 mins.

Optional

For this afternoon if you continue to use the Pi you will need a program called Samba and one called Nautilus

You can install this now by entering the following:

sudo apt-get install samba

Takes about two minutes

sudo apt-get install samba.common.bin

Takes about 3 three minutes

sudo apt-get install nautilus

Takes about five minutes

Configuration of these programs will come this afternoon.

Programming with Python

Install the Python (V3) integrated development environment (IDE) IDLE.

sudo apt-get install idle

Note: Idle is basically a text editor, a word processor without the fancy stuff like bold, italics, styles etc. It produces text suitable for a computer to understand. Writing a program as you would a letter, with something like Word would not work because of the additional hidden information embedded into your text.

Start the Graphical User Interface

This is one command that doesn’t need sudo simply type startx

startx

Launch IDLE and write one or more of the programs below.

Find the idle icon and double click. Then open a new window to type your program.

File -> New Window

# Program 1

print(“Hello World”)

Now save your program with a suitable name

File -> Save <file-name>

Execute the program

To execute (or run) the program

Run -> Run Module

It is possible to run the program from the command line by adding a string sometimes called a hashbang to the first line of your program.

#!/usr/bin/python

This tells the shell to use the python interpreter and is called from the command line with

sudo python filename.py

The filename.py is the name you gave to your program when you saved it. The .py is added automatically by the editor (Idle in this case). .py identifies the file as being a python program.

Note: Python must be installed on the computer.

Program Snippets

Getting data

Python uses the input statement to accept input from the keyboard. You can for example ask a user to enter their name.

#what’s my name

name= input("who are you")

print("Hello ",name)

Repeating

Python uses the ”for” loop/statement to provide for repeating things a fixed number of times.

The for loop steps through the items in any ordered sequence list, i.e. string, lists, tuples, the keys of dictionaries and others. The Python for loop starts with the keyword "for" followed by an arbitrary variable name, which will hold the values of the following sequence object, which is stepped through. The general syntax looks like this:

for <variable> in <sequence>:

statements

else:

statements

The sequence can be for example a list of names or a range of numbers.

# 8 times table

for x in range(1,12):

print (x,” times 8 =”,8*x)

Note: the indent is essential

Decisions

#Do I know you

name= input("who are you? ")

if name == "How":

print("Hi How")

else:

print("mmm,",name,", Do I know you?")

The Mathematical operators in Python

Operation / Meaning
strictly less than
<= / less than or equal
strictly greater than
>= / greater than or equal
== / equal
!= / not equal
Is / object identity
is not / negated object identity

You can try the optional Exercises when you have time.

Optional Exercises

Use of Lists/Arrays

(Thanks to Kieran Owen for his suggestion)

Produce a program that will offer four alternative responses when queried. This is sometimes referred to as the “Magic 8 Ball”

You will need to know how an array works

In this case An Array is a list of statements that we want to use in order to provide responses for our user.

You define the list simply by typing it

answer = [“Any time soon”, “Anything is possible”, “That’s not a good idea”, “Go for it”]

We shall use this in the program below

This gives us four answers

answer[0]=Anytime soon

answer[1]=Anything is possible

answer[2]= That’s not a good idea

answer[3]= Go for it

Note: Use square brackets [ ] with lists

You could just randomly generate an answer but to do this you need to import the random module. This module adds additional functionality to Python, in particular the ability to generate random numbers.

import random

answer = [“Any time soon”, “Anything is possible”, “That’s not a good idea”, “Go for it”]

num=random.randint(0, 3) #will generate random integers between 0 and 3 (that’s 4 choices)

To print an item from the list at a position num (where num is an integer (whole number) value)

print(answer[num])

Run the program

Mathematical Operators

Operation / Result
x + y / sum of x and y
x - y / difference of x and y
x * y / product of x and y
x / y / quotient of x and y
x // y / floored quotient of x and y
x % y / remainder of x / y
-x / x negated
+x / x unchanged
abs(x) / absolute value or magnitude of x
int(x) / x converted to integer
float(x) / x converted to floating point
complex(re, im) / a complex number with real part re, imaginary part im. im defaults to zero.
c.conjugate() / conjugate of the complex number c
divmod(x, y) / the pair (x // y, x % y)
pow(x, y) / x to the power y
x ** y / x to the power y

v 1.21|Page


Lab 2 Linux

Lab 2: Internetworking with Linux

Configuring a computer for Networking

Determine the IP addresses you want to use and note them down

Machine A
IP address / 192.168.3.34
Subnet mask / 255.255.255.0
Machine B
IP address / 192.168.3.35
Subnet mask / 255.255.255.0x

We need to add these values usinga command terminal. (This will let you type commandsdirectly to the computer)
How do we do this? On the first Pilook for and open the LXTerminal on the desktop. (Double click on the icon will do this)
Type (All in lower case):

ifconfig

Note look for the state of eth0 particularly the HWaddr (Hardware Address)

Then:

1) Stop the network interface working

sudoIfconfig eth0 down

2) Add anIP address and a netmask

sudoIfconfig eth0 192.168.3.34 netmask 255.255.255.0

3) Start the network interface working

sudoIfconfig eth0 up

Note: An IP address is a number assigned to each device which enables it to authenticate toanother computer on a network. Like a phone number for people.
The subnet maskis a logically visible subdivision of acomputer network like the area code of a phone number.

Check the IP address and Subnet mask have changed by typing:

ifconfig

Then, do it the same on the second PI. Don’t forget to put a different IP address.

Connecting two PIs

Connect both machines using CAT5 cable and a switch.

Note: A switch is a device that is used to connect computers together.

Use the ping command to ensure both are connected

sudoPing 192.168.3.34

Ctrl+C to stop Ping command.

If it works, you should see something like:

Reply from 192.168.34: bytes=32 time<1ms TTL=64

Reply from 192.168.34: bytes=32 time<1ms TTL=64

Reply from 192.168.34: bytes=32 time<1ms TTL=64

Reply from 192.168.34: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.34:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)

Under what circumstances do you think packet loss might occur?

Configuring a computer for Networking with a static IP address

Note: If you change the IP address by using terminal, this change will be not permanent.
So, to make it permanent, you have to add the IP details to the network system configuration file

Open the network configuration file using LXTerminal:

sudoleafpad /etc/network/interfaces

The document contains:

Auto lo
ifacelo inet loopback
iface eth0 inetdhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf
iface default inetdhcp

Complete and replace with:

auto lo
iface lo inet loopback
iface eth0 inetstatic
address 192.168.3.34
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam/etc/wpa_supplicant/wpa_supplicant.conf
iface default inetdhcp

Don’t forget to save the file.

Restart the devices to enable these changes.

sudo /etc/init.d/networking restart

or

sudo /etc/init.d/networking stop

sudo /etc/init.d/networking start

Do the same thing on the other PI.

Note: Why can’t you just double click leafpad? Because you must have elevated permissions

File transfer – Create a (samba) share on each Pi and view the share

1)First of all you have to change the name of each Pi because it’s the same by default.

At the terminal, type the following command to open the hosts file:

sudoleafpad /etc/hosts

Leave all of the entries alone except for the very last entry labelled 127.0.1.1 with the hostname “raspberrypi”. Replace “raspberrypi” by the name you want to use, maybe your partner’s name, and save the file

Back at the terminal, type the following command to open the hostname file:

sudoleafpad /etc/hostname

This file only contains your current hostname. Replace “raspberrypi” with the same hostname you put before and save the file

Tape on terminal “hostname” to check the new name of Pi

hostname

2)After, you have to install some software like Nautilus and Samba.

sudo apt-get install nautilus
sudo apt-get install samba
sudo apt-get install samba.common.bin

3)You have to configure samba.

Edit the samba configuration file

sudonano /etc/samba/smb.conf

Search for the section marked ##### Authentication #####

Change the text

# security = user

to

security = user

Save the edited file

Restart samba to use the new configuration file.

sudo /etc/init.d/samba restart

By default, the username pi is defined. To allow pi to be a samba user

sudosmbpasswd -a pi

You will be asked to enter pi's password twice.

4)Configure a public storage area

Create a directory to store public files with LXterminal

sudomkdir /home/shares

sudomkdir /home/shares/public

sudochown -R root:users /home/pi/shares/public

sudochmod -R ug=rwx,o=rx /home/pi/shares/public

Edit the samba configuration file

sudoleafpad /etc/samba/smb.conf

At the end of the file, add the following lines

[public]

comment = Public Storage

path = /home/pi/shares/public

valid users = @users

force group = users

create mask = 0660

directory mask = 0771

read only = no

Save the edited file

Restart samba to use the new configuration file.

sudo /etc/init.d/samba restart

5)Now try to see the shared folder:

Open a file manager
Click on “Go”
Click on “Network Driver”
You should see the 2 Pis
Enter in the other Pi
You should see the shared folder you’ve created

Linux Commands
Pwd / Show current directory / Chmod / Change permissions
Ls / List directory contents / Man cmd / Show manual page forcmd
Ls –al / List all in long format / ping host / Ping a network host
Cd dir / Change directory to dir / Wgetfile / Download file
Cd ~ / Go to home directory / Sudo / Run command as superuser
Mkdirdir / Make directory dir / Apt-get / Package handling utility
Mvfile-1 file-2 / Move file-1 to file-2 or
Rename file-1 to file-2 / Rm file / Remove file
Rm –r dir / Remove dir and its contents
Cpfile-1 file-2 / Copy file-1 to file-2 / Ctrl+C / Halt current command

v 1.21|Page