CS197U: A Hands on Introduction to Unix Lecture 4: My First Linux System J.D. DeVaughn-Brown University of Massachusetts Amherst Department of Computer Science jddevaughn@cs.umass.edu 1
Reminders After today we are done half of the lectures Assignment 2 was due before class Assignment 3 has been up Please START EARLY so there is time to resolve any problems As always, let me know if you are skipping an assignment If you have questions, email me. 2
Outline Last class... Learned what an OS does Multi-tasking, resource management, and security Overview of Linux file system structure File permissions 3
File permissions Control access for the user, group, or world (everyone else) group means everyone in the user s group (excluding the user) Abbreviation to use with chmod: g world means everyone who is not in the user s group Abbreviation to use with chmod: o all means everyone Abbreviation to use with chmod: a chmod - R a+x <dir> Recursively change permissions for all the files + dirs in <dir> a o g u 5
Be careful when you run this command What s the most dangerous command you can run? elnux3> rm rf * Removes everything in the current directory, including subdirectories Without asking you for confirmation! (- f flag) Depends on where you run this command Run in home directory? Contents of home directory are GONE! DON T do these things! Run in root /? Almost everything on the hard disk will be GONE! To remove everything you would have to run the command with sudo We will learn about sudo in this lecture 6
Outline This class: Linux distributions Using virtualization to run Linux on your own computer Installing software in Linux 7
What OS is most popular? Web users" source: http://www.w3schools.com (Dec 2011) Web Servers" source: http://news.netcraft.com (spring 2010) Win7 Vista Win XP Linux Mac Windows Linux 5% 9% 19% 47% 34% 5% 81% 8
Linux distributions You don t really install Linux like you would Windows Vista There is one linux kernel... but lots of different linux distributions A distribution is: A linux kernel (the core OS) A collection of pre-packaged applications Sometimes: a window manager with graphical interface 9
Top distributions Ubuntu - rose to popularity due to ease of use Debian - Ubuntu s parent RedHat, Fedora, CentOS Slackware - known for simplicity Gentoo FreeBSD... hundreds more 10
Distribution Popularity Mint is based on Ubuntu Avg Hits / day Data biased towards desktop users source: http://distrowatch.com/stats.php (fall 2011) 11
Ubuntu 2004: Made it easy to install Linux (nice installer, single CD) Provided helpful forums and wiki Pretty revolutionary compared to previous approaches... Multiple CDs for Redhat Gentoo compiles the entire system from scratch Mainly designed for personal use, not for running servers 12
Window Managers: Gnome vs KDE Underneath, all Linux distros are very similar Same Linux kernel, general libraries, basic utilities Graphically, may look very different depending on the window manager Gnome and KDE are the most popular window managers Some software requires a specific window manager generally if it starts with a G or a K... 13
Outline This class: Linux distributions Using virtualization to run Linux on your own computer Installing software in Linux 14
Running multiple operating systems Dual Boot - install two operating systems on one computer Need either two hard disks, or two disk partitions If you do this, be careful Install Windows first, then Linux Linux will setup a boot loader to let you switch between OSes at startup Virtualization - run a second operating system inside the first The second OS is run as a Virtual Machine (VM) VM tricks OS running inside it into thinking it owns the full machine Can run multiple VMs at once 15
Virtualization Several different virtualization methods Full Virtualization: A control program produces virtual machines Used for: Sharing a system between multiple users Isolating users/systems Full Virtualization App 1 App 2 Windows or Linux Virtualization Platform 16
Virtualization Hosted virtualization: Operating system runs the virtualization software Used for: Running apps for a different OS than you use Testing possibly unstable applications or OS We will use this It s easy and free Hosted Virtualization VMs App 1 App 1 App 2 Windows or Linux App 2 Windows 17
Virtualization platforms VMware - biggest virtualization company Makes both hosted and full virtualization platforms Has several free versions Xen - started as open source project, now part commercial Runs under Linux only Virtualbox - sort of open source Runs in Windows, Linux, or OS X Can host Windows or Linux VMs KVM - for Linux only Parallels - for Macs only 18
Using Virtualbox It will ask you to register." You can just cancel Available on Edlab machines in Linux only Or you can install it on your own computer: http://www.virtualbox.org/ The VirtualBox control program lets you Create new virtual machines Start / Stop VMs Adjust configuration Amount of RAM Disk size Network settings 19
Your first Ubuntu virtual machine We will create a basic Ubuntu VM for you to start with To create the VM, choose Import Appliance from the File menu If you do this on your own system, you will have to download our template Start the new VM, and watch it boot up Clicking inside VM display window captures the mouse / keyboard Press [right ctrl] key to release (varies by host operating system) Setting up VM is part of next HW 20
Virtualbox DEMO 21
Starting with Ubuntu Log in with user/pass: cs197u / cs197u First things first: Change the account password: type passwd in a terminal Don t forget the new one! Resources: http://www.ubuntupocketguide.com/ - free guide (no pictures) https://help.ubuntu.com/9.04/index.html http://library.gnome.org/users/user-guide/stable/index.html.en 22
Outline This class: Linux distributions Using virtualization to run Linux on your own computer Installing software in Linux 23
Administration: being a super user In the Edlab you are a basic user Limited permissions Can t write outside your home directory Can t install new software Inside your VM, YOU are in control Try not to break things... but if you do, it s easy to restore! The root user Root is a special account for the most powerful administrator If you are root you can do anything 24
Becoming root Don t want to use root as main account Only switch to root when needed Use su - switch user command su root can be used with any username: su Will ask for password! <username> Ubuntu: Don t have to create a root account Helps reduce security issues 25
sudo - safely acting as root Lets you run a command as if you were root Does not require a root account to exist You must be on the sudoers list to use sudo Usage: sudo command Will probably ask you for your password 26
Getting software How to install software? In Windows or OS X, basic OS is always the same Easy to add new software because dependencies are known but two Linux systems may have very different configurations, drivers, libraries, etc! Software repositories You could build all applications from source code A lot easier to use distro specific repositories yum, RPM, apt-get, portage, etc 27
Manual Installation Fetch source/binaries and install by hand Advantage: customizable Advantage: no limitations to what can be installed Disadvantage: must manage everything Disadvantage: tedious First step: get the source code, usually stored as a tar ball compressed file.tar.gz or file.tgz extract using tar -xzf file.tar.gz 28
make - installing from source make is a tool to help compile complex software Typical steps to build application from source code./configure - verifies that you have proper libraries, sets configuration make - compiles all of the source code in a temporary directory will use things like gcc, g++, javac, etc make install - copies the compiled executables and libraries to their proper homes Do only the last step as root! otherwise bugs in the build process could corrupt important files in general, don t do something as root unless it is required 29
Package Managers Ubuntu/Debian: apt-get FreeBSD: addpkg, Redhat: rpm, Centos/Fedora: yum Database of packages, requirements, etc Install/update/uninstall programs fetch, install, update, and delete packages Advantage: easier and faster than manual installation or compiling Disadvantage: packages are usually not compiled on-site Disadvantage: package database doesn t have everything Disadvantage: doesn t allow customization 30
apt-get - using a package manager apt- get can install, remove, and provide information about software To use, you must either be logged in as root, or use sudo ubuntu> apt- get install firefox E: Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? ubuntu> sudo apt- get install firefox Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed:... 31
Ports Collections FreeBSD, Gentoo Linux, Mac Ports Database of supported software for the OS Ports system fetches, compiles, and installs programs Automatically manages dependencies and updates Advantage: Compiled and optimized for current machine Advantage: More easily customizable Disadvantage: Takes time, space to compile 32
Lecture 4 Review There are lots and lots of Linux distributions We will use Ubuntu... because it s easy to use Virtualization is an easy way to run multiple OSes on one computer We will use Virtualbox... because it is free and already on the Edlab The Super User root is all powerful on Linux systems Ubuntu uses sudo instead of creating a root user 33