tabular[t]cMatko Orsag tabular tabular[t]cDamjan Mikli\81\007 tabular tabular[t](Sre\81\007ko Juri\81\007-Kavelj)

Introduction to GNU/

Ivan Marković Matko Orsag Damjan Miklić (Srećko Jurić-Kavelj)

University of Zagreb, Faculty of Electrical Engineering and Computing, Departement of Control and Computer Engineering

2012

University of Zagreb Faculty of Electrical Engineering and Computing

IM, MO, DM (FER–ZARI) GNU/Linux intro 1 / 22

1 Introduction

The GNU/Linux

• GNU (GNU’s Not ) I find it really cool to be able to dig through an open source project’s history right to the inception of the open source movement itself. Below is the original initial announcement of the GNU Project, posted by :

From CSvax:pur-ee:inuxc!ixn5c!ihnp4!houxm!mhuxi!eagle!mit-vax!mit-eddie!RMS@MIT-OZ From: RMS%MIT-OZ@mit-eddie Newsgroups: net.unix-wizards,net.usoft Subject: new Unix implementation Date: Tue, 27-Sep-83 12:35:59 EST Organization: MIT AI Lab, Cambridge, MA

Free Unix!

Starting this Thanksgiving I am going to a complete Unix-compatible system called GNU (for Gnu’s Not Unix), and give it away free(1) to everyone can use it. Contributions of , money, programs and equipment are greatly needed.

To begin with, GNU will be a kernel plus all the utilities needed to write and run C programs: editor, shell, C compiler, , assembler, and a few other things. After this we will add a text formatter, a , an Empire game, a spreadsheet, and hundreds of other things. We hope to supply, eventually, everything useful that normally comes with a Unix system, and anything else useful, including on-line and hardcopy documentation.

GNU will be able to run Unix programs, but will not be identical to Unix. We will all improvements that are convenient, based on our experience with other operating systems. In particular, we plan to have longer filenames, version numbers, a crashproof file system, filename completion perhaps, terminal-independent display support, and eventually a Lisp-based window system through

1 which several Lisp programs and ordinary Unix programs can share a screen. Both C and Lisp will be available as system programming languages. We will have network software based on MIT’s chaosnet protocol, far superior to UUCP. We may also have something compatible with UUCP.

Who Am I?

I am Richard Stallman, inventor of the original much-imitated editor, now the Artificial Intelligence Lab at MIT. I have worked extensively on compilers, editors, debuggers, command interpreters, the Incompatible Timesharing System and the Lisp Machine operating system. I pioneered terminal-independent display support in ITS. In addition I have implemented one crashproof file system and two window systems for Lisp machines.

Why I Must Write GNU

I consider that the golden rule requires that if I like a program I must share it with other people who like it. I cannot in good conscience sign a nondisclosure agreement or a agreement.

So that I can continue to use computers without violating my principles, I have decided to put together a sufficient body of so that I will be able to get along without any software that is not free.

How You Can Contribute

I am asking computer manufacturers for donations of machines and money. I’m asking individuals for donations of programs and work.

One computer manufacturer has already offered to provide a machine. But we could use . One consequence you can expect if you donate machines is that GNU will run on them at an early date. The machine had better be able to operate in a residential area, and not require sophisticated cooling or power.

Individual programmers can contribute by writing a compatible duplicate of some Unix utility and giving it to me. For most projects, such part-time distributed work would be very hard to coordinate; the independently-written parts would not work together. But for the particular task of replacing Unix, this problem is absent. Most interface specifications are fixed by Unix compatibility. If each contribution works with the rest of Unix, it will probably work with the rest of GNU.

If I get donations of money, I may be able to hire a few people full or part time. The salary won’t be high, but I’m looking for people for whom knowing they are helping humanity is as important as money. I view this as a way of enabling dedicated people to devote their full energies to working on GNU by sparing them the need to make a living in another way.

For more information, contact me. Arpanet mail: [email protected]

Usenet: ...!mit-eddie!RMS@OZ ...!mit-vax!RMS@OZ

US Snail: Richard Stallman 166 Prospect St Cambridge, MA 02139

• Linux Similarly, we can trace the inception of Linux:

Path: gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!wupost!uunet!mcsun!news.funet.fi!hydra!klaava!torvalds From: [email protected] (Linus Benedict Torvalds) Newsgroups: comp.os.minix Subject: What would you like to see most in minix? Summary: small poll for my new operating system Keywords: 386, preferences Date: 25 Aug 91 20:57:08 GMT Organization: University of Helsinki

Hello everybody out there using minix -

I’m doing a (free) operating system (just a hobby, won’t be big and professional like ) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I’d like any feedback on things people like/dislike in minix, as my OS resembles it somewhat (same physical layout of the file-system (due to practical reasons) among other things).

I’ve currently ported (1.08) and gcc(1.40), and things seem to work. This implies that I’ll get something practical within a few months, and I’d like to know what features most people would want. Any suggestions are welcome, but I won’t promise I’ll implement them :-)

2 (a) Full Ubuntu installation on a dedicated partition

(b) Open Virtualization Archive with (c) Windows Ubuntu installer (depre- ROS fuerte on Ubuntu 12.04.1 LTS cated)

Figure 1: GNU/Linux (Ubuntu) installation alternatives

Linus ([email protected])

PS. Yes - it’s free of any minix code, and it has a multi-threaded fs. It is NOT protable (uses 386 task switching etc), and it probably never will support anything other than AT-harddisks, as that’s all I have :-(.

and related projects You will most likely get a GNU/Linux operating system in a form of distribution. See http://distrowatch.com/ for a comprehensive list of distributions. At the time of writing (October 1, 2012), these are the five most popular distributions according to DistroWatch: Mint, Mageia, Ubuntu, Fedora and openSUSE.

Installation alternatives Installation alternatives for Ubuntu are shown in Fig. ??

1.1 Ubuntu Installing Ubuntu by itself shouldn’t be a problem. Things can get a bit more complicated if you want to install Ubuntu alongside Windows. Then you have to consider and a boot manager. Ubuntu’s installer even pro- vides an option to automatically resize an existing Windows partition (which is probably the most common scenario). In case of a more complicated parti- tion setup this can be done manually. GNU parted and it’s Gnome frontend, GParted are included on Ubuntu install/live . The version included in the latest 12.04.1 LTS can resize/move fat16/32 and ntfs partitions. Preparation activities (a.k.a. backup) are recommended! Full guide is available on Ubuntu community documentation, HowtoResizeWindowsPartitions. Events like Linux InstallFest at KSET may be helpful.

1.2 Open Virtualization Archive NooTriX provides an OVA with ROS fuerte preinstalled on Ubuntu 12.04.1 LTS. Open Virtualization Format is an open standard and is supported by wide variety of virtualization software. E.g. you can use VirtualBox. The installation of this OVA using VirtualBox is described in detail in a blog post at NooTrix.

3 /

bin home media root sbin var usr ...

cdrom0 Storage bin include ... share

DC44B9E244B9BF96

1.3 Windows Ubuntu installer This method is deprecated starting from Ubuntu 13.10, and is not recommended for older distributions either, due to its sensitivity to forced shutdowns.

2 Basic usage

Note on Notation

• $ sign signifies a regular user prompt • # sign signifies a superuser prompt

• Text in "monospace" font is to be entered literally, e.g. user@host:~$ /tmp/

• Pair of matching /greater than signs (<>) denotes a "variable": $ cd /home/

• Pair of matching brackets denote an optional entry: $ [-l]

Files and directories

• Where are we? user@host:/tmp$

• What’s inside? user@host:/tmp$ ls

• Additional options user@host:/tmp$ ls -la

• How to move/navigate? user@host:/tmp$ cd test

• How to create a file? user@host:/tmp/test$ nano newfile.txt

• How to delete a file? user@host:/tmp/test$ newfile.txt

Filesystem Hierarchy Standard http://www.pathname.com/fhs/

4 Filesystem permissions $ rm -rf /root • Remove the root user home directory rm: cannot remove `/root/.bashrc’: Permission denied ... $ ls -ld /root • Every file/directory has permissions drwxr-xr-x 34 root root 4096 2012-09-21 17:00 /root set for three roles: owner, group and all others. • Tools that manipulate ownership and permissions: , and .

Superuser (root) • Login disabled for root • Multiple users can be designated as superusers using sudo (/etc/sudoers) user@host:~$ • Gaining a root shell sudo -i root@host:~#

Help • Almost all programs/commands have inbuilt help $ ls --help

• For in–depth help use info... $ info mkdir

• ...or man pages. $ man mkdir

Input/output redirection stdin, stdout (1) and stderr (2) streams. • Pass a long output of a command to less using pipe | $ ls -la /usr/lib | less

• Redirect the output of a command to a file $ ls -la /usr/lib >[>] out.txt

• Redirecting stderr to stdout (useful for piping) $ ls -la /usr/lib 2>&1 | less

• Redirect all output of a command to a file $ ls -la /usr/lib &> out.txt

Process management • Starting an app in background $ evince document.pdf &

• Bringing an app to foreground $ fg %1 • Stopping an app with Ctrl+Z • Moving an app to background $ bg %1

• Killing an app $ [-9] %1 or Ctrl+C while the app is in the foreground. • List all processes $ [aux]

• Monitor processes $ top

5 Searching

$ which top • Locate a command /usr/bin/top

• Searching for files $ locate PATTERN

locate searches a local file index, usually located at /var/lib/mlocate/mlocate.db. This index is regenerated daily using . mlocate script in /etc/cron.daily: On systems that don’t run continuously, n-day period tasks are usually run by anacron. Anacron itself, since it’s not a daemon, will be run at startup, on APM power status change, or by cron.

• Examining file contents $ PATTERN[FILE] $ grep -i "max_\?range" $( . -iname "*.cc" \ e.g. a variable specifying max range in a source tree -o -iname "*.h") finds e.g. max_range and maxRange variables in .cc and .h files. In addition to using ignore case options (-i for grep and -iname for find), previous example employs regular expressions. This particular example, uses a simple concept of matching the underscore character (_) zero or one time. This is specified with ? meta-character, or in grep basic notation \?. find produces a list of files in the current subtree (.), that have filenames ending in .cc or (-o) .h. The output of find is substituted in the com- mand line of grep using $(command). Command substitution can also be accomplished using backticks (`command`).

Environment variables

• List all environment variables $ env

• See the contents of a specific variable $ $PATH

• Set an $ [export] PATH=$HOME/scripts:$PATH

3 Installing and removing software (package man- agement)

Advanced Packaging Tool

• Library with various front-ends:

– apt-get – aptitude – Synaptics

• Software repositories in /etc/apt/sources.list.d

6 $ apt-cache search vector graphics $ apt-cache show inkscape • Packages are signed and have extensive metadata $ apt-get install inkscape $ sudo !!

In the above command I used bang-bang (!!) on purpose. This is a simple trick employing one of bash history capabilities. The !! gets replaced with the last executed command, apt-get install inkscape in this case. This is very handy for repeating commands that require superuser privileges. You can find this and many more examples in a blog post titled Advancing in the Bash Shell.

Adding a package source

$ sudo sh -c \ ’echo "deb http://packages.ros.org/ros/ubuntu \ • Add a source, e.g. ROS for Ubuntu 12.04 (precise) precise main" > \ /etc/apt/sources.list.d/ros-latest.list’

$ http://packages.ros.org/ros.key -O - | \ • Get the signing key (establish trust) sudo apt-key add -

• Update package sources cache $ sudo apt-get update dpkg

• List installed packages $ dpkg-query -l

$ dpkg-query -S /boot/config-2.6.32-43-generic • Find a package owning file linux-image-2.6.32-43-generic: /boot/config-2.6.32-43-generic

• List all files from a package $ dpkg-query -L linux-image-2.6.32-43-generic

• List package control files $ dpkg-query -c linux-image-2.6.32-43-generic

Installing packages from source Chordii — autotools example Autotools is also known as GNU build system. It’s used by developers to make their source code distributed software accessible on wide variety of systems. From end-user perspective, it’s a configure script that, if all prerequisites are satisfied, generates a Makefile for building the software. All packages employing autotools should have README and INSTALL files describing the installation procedure in greater detail.

$ wget "http://downloads.sourceforge.net/project/chor"\ • Grab and unpack the source "dii/chordii/4.3/chordii-4.3.tar.gz" $ tar xzf chordii-4.3.tar.gz

7 Figure 2: Chordii illustration

Figure 3: PDF Presenter Console screenshot

$ cd chordii-4.3 • Configure the source for building $ ./configure

$ make • Build and install locally $ sudo make install To build packages from source, you’ll need the compiler for the language the software is written in, at least. Ubuntu 12.04 LTS base install comes with all prerequisites to build Chordii from source.

Installing packages from source Pdf Presenter Console — CMake example CMake is a true cross-platform build system. CMake works in conjuction with platforms native build system, e.g. make for *nix, Visual Studio for Windows, Xcode for OS X and iOS...

8 Figure 4: NetworkManager applet for Gnome

$ wget "https://github.com/downloads/davvil/pdfpc/"\ • Grab and unpack the source "pdfpc-3.1.1.tgz" $ tar xzf pdfpc-3.1.1.tgz

$ cd pdfpc-3.1.1 $ mkdir build • Configure the source for building $ cd build $ cmake ..

$ make • Build and install locally $ sudo make install CMake is not part of Ubuntu 12.04 (precise) base install. You should get it separately: $ sudo apt-get install cmake

As PDF Presenter Console has some prerequisites, you’ll need to get those $ sudo apt-get install libpoppler-glib-dev librsvg2-dev \ too: libgee-dev These are not all pdfpc prerequisites, but they get pulled as dependencies of the three packages listed above.

4 Basic networking

Network configuration

• Desktop oriented distributions use NetworkManager As shown in Fig. ??, NetworkManager provides an intuitive user interface for network connectivity configuration. User can create different wired net- work profiles, which is very useful on laptops. Available wireless networks are listed, and can be easily configured. Mobile broadband connections can be configured using NetworkManager, also. VPN is also integrated.

9 • ifupdown suite Although there are command line frontends to NetworkManager, it seems that ifupdown suite is more prevalent on e.g. embedded systems. Network interfaces are described in /etc/network/interfaces file. For more information, you can consult interfaces(5) . E.g. this is the /etc/network/interfaces file from a Husky A200 robot:

1 auto lo 2 auto eth0 3 auto eth0.10 4 5 iface lo inet loopback 6 7 iface eth0 inet static 8 address 192.168.1.1 9 netmask 255.255.255.0 10 11 iface eth0.10 inet dhcp 12 vlan-raw-device eth0

Remote access

• Login to a remote computer $ ssh @

• Copy a file to remote computer $ scp @: The file gets copied to /home// on remote com- puter.

• Copy a file from remote computer $ scp @:/

/

• scp uses similar options as , e.g. -

Username/password based authentication for ssh is not the only existing/supported method. Asymmetric cryptography method can be used. Chances are that you already have your private/public keypair (˜/.ssh/id_rsa[.pub]). If not, you can generate one with ssh-keygen. You can install your public key on the re- mote computer with $ ssh-copy-id @

You can find an in-depth explanation in article titled SSH with authentica- tion key instead of password. In addition to scp, sshfs can be very convenient for remote file access. Extensive tutorial is available at Ubuntu community documentation (sshfs).

Summary

• Filesystem • Users • Shell • Package management • Networking

10 Useful links

• Basic Use of Linux Operating System at UniZg FER • Linux for Engineering at Rutgers University • Ubuntu documentation (official and community wiki)

• Ask Ubuntu (part of StackExchange network)

11