CS 173: Introduction to Computer Science
Lab 1: Dual booting your laptop
Notes:
-
Read the lab carefully.
-
This lab is due 48 hours from the start of your lab section.
-
Turnin: for this lab you will send me and email from your new Linux account
installed on your laptop. Instructions for this are contained in one of
the steps below.
Objective:
This class will use the Linux environment. This lab is designed to get
you started using Linux on your laptop.
Background:
An operating system (OS) is the software that manages the resources
on your computer. Examples of operating systems include Windows, MacOS
and UNIX. Linux is an extremely popular variant of the UNIX operating
system. A brief history of Linux is described in this excerpt
from www.linux.org:
Linux is an operating system that was initially created as a hobby by a young
student, Linus Torvalds, at the University of Helsinki in Finland. Linus had an
interest in Minix, a small UNIX system, and decided to develop a system that
exceeded the Minix standards. He began his work in 1991 when he released
version 0.02 and worked steadily until 1994 when version 1.0 of the Linux
Kernel was released. The kernel, at the heart of all Linux systems, is
developed and released under the GNU General Public License and its source code
is freely available to everyone. It is this kernel that forms the base around
which a Linux operating system is developed. There are now literally hundreds
of companies and organizations and an equal number of individuals that have
released their own versions of operating systems based on the Linux kernel.
...
Apart from the fact that it's freely distributed, Linux's functionality,
adaptability and robustness, has made it the main alternative for proprietary
Unix and Microsoft operating systems. IBM, Hewlett-Packard and other giants of
the computing world have embraced Linux and support its ongoing development.
More than a decade after its initial release, Linux is being adopted worldwide
as a server platform primarily. Its use as a home and office desktop operating
system is also on the rise. The operating system can also be incorporated
directly into microchips in a process called "embedding" and is increasingly
being used this way in appliances and devices.
Lab: This lab has two parts. The first part is to set
up your laptop to boot both the Windows XP and Linux operating systems.
The second part is to begin becoming familiar with the Linux environment.
Before you start you'll need to have the Ubuntu Linux CD.
Part 1: Dual booting Linux/Windows
Initially, hard drives are just a place to store a bunch of 0s and 1s.
Partitioning a hard drive places information on it about where
the data
can be stored. Writing a filesystem on the partition further structures
the hard drive and also determines how the information is stored.
Your hard drive currently has some partitions and filesystems on it.
We will be changing the partitions and filesystems on your laptop
to prepare to install Linux.
Note: Computing Services does not
support Linux. If you have questions about it ask me or a TA. If there
is ever a problem with your Windows system Computing Services may have
to re-image your hard drive. This will render your Linux system unusable
and you will have to reinstall Linux, so you'll want to keep backups
of your work under Linux. To do this, obtain a rewritable CD (CD-RW)
and periodically write your home directory to the CD. You can get help
on this from me, Chelsey or members of the ACM.
- Note: any errors made during this process can destroy all information
on your current hard drive. Before you begin, backup *all* files onto your
R: drive or burn it to CD. This is, of course, a wise thing to do anyway.
Now remove the data in your D: drive, or at least make sure you have more
than 10 GB of space available.
- Plug in your power cord and network cable.
- Start, or restart, your machine (read the next step first, though,
since it comes up quickly).
- Your machine is configured to automatically boot from the internal
hard drive. For now you need to boot the CD. During one part of startup
there is a small window of time that you can press F12 (while the white bar
is filling from left to right). Hold down the F12 key, then when you get the
menu of boot devices, place the Ubuntu Linux CD in the CD drive and select
the boot device "CD/DVD/CD-RW Drive".
- Select "English"
- Select "Install Ubuntu". The magic begins.
- Click "Forward" to choose English as your laptop's language.
- Click "Forward" to choose your time zone location.
- Click "Forward" to choose USA English for your keybord.
- Answer the questions (I recommend using your ursinus login and password).
- Select "Manual" and Click "Forward".
- Accept the name for your laptop and click "Forward".
- At this point ask for help from me, Chelsey or an ACM member. We'll
set the size of the partitions for your Linux installation.
- At "Migrate Documents and Settings", just click "Forward".
- Click "Install".
- Installation will now continue with the Ubuntu base system.
- Discuss Life, the Universe and Everything while the system is installed.
- Hit "Restart now".
- When rebooting, this time arrow down to Windows and make sure you
haven't hosed your Windows installation. It's probably fine, but just
make sure things look ok on your D: drive.
- If everything is lovely, reboot your machine and then select
Ubuntu to boot.
- Installation will continue until you get a login screen. Login.
Congratulations - you've now got two Operating Systems on one machine
to work with! Now what do you do? Read on...
Part 2
When you log in you are in the Gnome desktop environment. There are
many directions you can go from here. For this lab you are going to
make a change to your system that will increase your network performance,
install a couple of software packages, set up email,
get to know the basics of getting around in Linux and learn to create,
compile and run a program. Although
Gnome provides a graphical interface to the system, many users find
it faster to work primarily in the shell environment, so that's where
we'll start. Throughout the course you will learn more about the system
so you can customize it however you see fit.
The shell is a textual environment for interacting with the system.
At a shell prompt, something like "user@host:dir $", you enter
commands that execute programs or change your environment.
The shell is also provides a programming language that can be used to
write short, very powerful and useful programs.
To make the network performance enhancement, do the following:
- In Gnome you have two different desktops you can use
and switch among. Hold down Control-Alt and hit the left and right
arrows and you will move among the desktops. Icons in the bottom
right of the screen show which screen is currently displayed.
- Now set up another desktop to work with this intro by going to
a new desktop (Ctrl-Alt-Right Arrow), then left
click on Applications->Accessories, then RIGHT click on
Terminal and select "Add this launcher to panel". An icon for the
Terminal program should now appear next to your other icons. Click on
it to start a terminal. You can move back and forth between the browser
and the terminal.
- In the terminal, enter this line:
sudo gedit /etc/sysctl.conf
- Cut and paste the following three lines at the bottom of the text
file you're editing and save and exit the editor:
net.ipv4.tcp_window_scaling=0
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_sack=0
- Cut the following line and paste it into your terminal at the prompt:
sudo sysctl -w net.ipv4.tcp_{window_scaling,timestamps,sack}=0
- You'll be prompted for your password. Enter it.
- You'll see the same three lines from above. (You can ignore them.)
To install some additional software packages:
- You're probably being told that there are some updates, so click
on the "updates" icon and then "Install Updates". This may
take a while. (Hopefully not as long as the installation took.)
- Restart your computer and come back to this point to continue.
- Next, there are tons of great, free programs available.
Start up the Synaptic Package Manager by selecting
System->Administration->Synaptic Package Manager; close the
intro screen
- Right click on the following packages and select "Mark for installation"
(and mark the other packages the system wants to install):
- You can add any other packages that look interesting later, but
keep an eye on your hard drive space.
- Hit the "Apply" button.
- When completed, close the Synaptic window.
To set up email, do the following:
- Select Applications->Internet->Evolution Mail. The following
are the changes you'll need to make in the Evolution Setup Assistant.
- Enter the Required information (Name, Email Address).
- For receiving email, choose a server type of IMAP;
for the server use the hostname "students2k.ursinus.edu"; under
Authentication Type choose "Password" and check "Remember Password".
- For Receiving Options, just hit "Forward".
- For sending email, choose a server type of SMTP, and enter the same
hostname as above.
- In Account Management, enter Ursinus as the account name.
- Click on New York in the Timezone picture.
- Choose "Apply". Evolution will start up. Select the account name
you entered above, and the Inbox and you should now be able
to send and receive email.
Next you'll need to set up a directory for your work. Then you'll
create a source file and compile and execute it.
- Open a terminal.
- Now we're going to use some of the basic UNIX commands to create
some directories and files, and move around and begin examining the
system. All commands will be entered at the shell prompt. First enter
"ls". You should only see "Desktop" and "Examples". "Desktop" is a
directory that is currently
empty. Now enter "ls -l". The "-l" is a flag given to the ls command
that causes ls to print more information, although the information
won't make a lot of sense... yet.
- Enter the command "date". You should see a string that represents the
current date and time. Now enter "date > newfile". Nothing happened... or
did it? Enter "ls" and you will see that there's now a file called newfile.
What's in the file? Enter "cat newfile" to see the contents. The output
from the date command was redirected into the new file called "newfile".
- If you do "date > newfile" and "cat newfile" again (or just arrow up
to get your previous commands), you'll see that
the old file was wiped out and a new one created with the output from
the new execution of the date command. To add information to a file
rather than wiping out the original, use two greater-than signs. Enter
"date >> newfile" and "cat newfile" and you'll see two lines with
different times. The second one was appended to the file with ">>".
- You can always get information about commands by reading the
"man" pages. Enter "man date". There's a lot of information about
the date command. You can page through by hitting space. You
don't have to read it all, but it's there whenever you need it.
Hit "q" to get out of the man page. What would you do to find
out more about the man command? You guessed it: "man man".
- Ok, let's move around in the system. The filesystem is organized in
a hierarchical tree structure. The root of the tree is denoted by "/".
Elements in the tree are generally either directories or files. Files
can only be leaves in the tree. After the root, each element is named
and separated by a slash "/". Go to the root of the filesystem by
entering "cd /". Cd is short for change directory. Now enter "ls" and
you'll see a number of directories. Enter "cd bin", then "ls". In
this directory are a number of basic commands. Hey look... there's
the "date" command you executed earlier!
- Each user has a home directory, which is where you created
newfile. You can cd directly to your home directory with
"cd /home/username" (fill in your own username). How do you know
you're in your home directory? Do "ls" and you'll see the Desktop
directory and newfile. You can also just enter "cd" and you will
automatically be taken to your home directory.
- Let's create a place to work for this class. Enter "mkdir cs173".
An "ls" shows the new directory. Change to this directory with "cd cs173".
- Now we're going to edit, compile and run a program. Start a text
editor (for example, Applications->Accessories->Text Editor will
start up a basic text editor). Enter the following
into the text editor. (One easy way to do this is to find this lab
using your browser, highlight the following and paste it into your
editing window. You may need to reformat it a bit. Note that in this
environment you can just highlight it and then simply right click to
paste it where the cursor is.)
#include <iostream>
using namespace std;
int main()
{
cout << "hello world!" << endl;
return 0;
}
- Now save the file as lab1.cpp into the cs173 directory you just
created and exit the editor. Doing "ls" in this directory shows lab1.cpp.
- Compile it by entering "g++ lab1.cpp". If all is well, a file called
"a.out" is automatically created. You can run it by entering "./a.out".
Just entering "a.out" alone doesn't work --- eventually we'll see why
that is the case.
- Hmmm. If you create all your files for this class in the same
directory things could eventually get messy. In the cs173 directory
create another directory called lab1. Now move the files you
just created into that directory with "mv lab1.cpp a.out lab1". Doing
"man mv" tells you a bit about the mv command, but at the bottom
it tells you to get more information by entering "info coreutils mv".
You can do this and then get out of it by just hitting "q".
- Go back to your home directory (enter "cd").
Verify the current directory by entering "pwd" (print working directory).
- Now enter "ls -R > outfile". Enter "cat out" and hit TAB. The
shell recognizes the filename and completes it for you, saving keystrokes
(Nice shell... thanks!). Hit enter to see the contents of outfile.
- Here's where you turn in something for this lab: enter the
following lines verbatim, one at a time:
date >> outfile
id >> outfile
- Now email "outfile" to me. Start the Evolution mail program
and create a new mail message with me as the recipient (rliston@ursinus.edu).
Attach outfile, then send the message.
I will respond to
you when I receive it. If you don't receive an acknowledgement from
me within a day, let me know so I can try to figure out what happened.
- You don't need to keep newfile or outfile around, so you can
remove them by entering "rm newfile outfile". Verify that this worked
with "ls".
You've now completed this lab. What's left? Plenty! The following are
things you should be doing before the next lab.
- Spend some time becoming very familiar with your editor. For
example, start up emacs (Applications->Programming->Emacs) and
click on Help->Emacs Tutorial and go through the tutorial.
Being familiar with this editor will be very helpful along the way.
The basic commands you need to know are:
- C-f and C-b (forwards and backwards one character)
- C-n and C-p (next and previous line)
- C-n and C-p (next and previous line)
- Esc-< and Esc-> (top and bottom of buffer)
- C-v and Esc-v (next page and previous page)
- C-x C-s (save buffer)
- C-x C-c (save any unsaved buffers and exit emacs)
- Spend time getting to know Linux and the bash shell. If you
Google for "Linux tutorials" you'll find many excellent Linux
introductions and tutorials available on the Web. A couple I've
found are:
Richard Liston