Linux and GNU
Total Page:16
File Type:pdf, Size:1020Kb
Operating systems Operating systems UNIX, Linux PhD Damian Radziewicz Wrocław 2017 Unix, MINIX and GNU/Linux system basics, licensing and history devices and device drivers internal structure of the ext filesystem proc filesystem mounting other filesystems shell programming and simple Bash scripts network communications OS brief history [1st lecture reminder] 1969: work started on Unix. Space Travel game, written by Jeremy Ben for Multics, then ported to FORTRAN running on the GE635; then ported by J. Ben and Dennis Ritchie in PDP-7 assembly language. Porting the Space Travel game to the PDP-7 computer was the beginning of Unix. The date: January 1, 1970 00:00:00 UTC is the beginning of Unix Epoch and is used until now in POSIX. 1981: MS-DOS 1984: GNU project started 1989: SCO UNIX, WWW 1991: Linux kernel Source: http://en.wikipedia.org/wiki/Dennis_Ritchie 1992: Solaris; Windows 3.1 Dennis MacAlistair 1993: Windows NT 3.1; Ritchie—notable for Debian GNU/Linux developing C and for 2001: Windows XP having influence on 2008: Google Android; other programming 2009: Windows 7 languages, as well ‘UNIX is basically a simple operating system, as operating but you have to be a genius to understand systems such as the simplicity’ Multics and Unix. Source: www.meetdageeks.com Dennis Ritchie (right) with Ken Thompson Unix written in 1969 (assembler) at AT&T re-written in the C in 1973 (D. Ritchie) easier portability across hardware platforms academic world: BSD (Berkeley Software Distribution) Berkeley sockets (or BSD sockets) API for Internet communication de facto world standard until now today: mainly open-source versions: FreeBSD, NetBSD, OpenBSD, closed-source products: HP/UX, AIX, MacOS MINIX Unix-like system written by A. Tanenbaum (initially only for education) do you know him? http://www.minix3.org/ Very low hardware requirements, including embedded systems Microkernel architecture (c.a. 6000 lines of code), high reliability 1992, comp.os.minix – Tanenbaum-Torvalds debate on kernel architecture. A.T. argued that ‘monolithic Linux kernel is obsolete’ (in 2.6.x kernel there are millions of lines of code) Linux and GNU ‘How does Linux actually work? — Use the Source, Luke!’ (open sourcers joke) although many things haven’t been documented yet (i.e. are still under development), you can take a look at the source files. You can learn how things work. You can improve the code, and you are expected to do so. The idea of GNU project (1983): to develop free, complete version of Unix- compatible system Linux kernel written in 1991 by Linus Torvalds (because GNU kernel still wasn’t available at that time) LINUX ::= Linux Is Not UNIX also: Linus’ UNIX GNU ::= Gnu Not Unix 25 August 1991 „I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. This has been brewing since April, and is starting to get ready (…) …it probably never will support anything other than AT- harddisks (…)” Linus Torvalds September 1991: Linux version 0.01 was released; 10,239 lines of code. December 2003: Linux 2.6.0; 5,929,913 lines of code. 2010: 14,000,000 lines of code and counting. … won't be big and professional … Tux: Torvald’s UniX 1993: Linus Torvalds bitten by a penguin in the National Zoo & Aquarium, Canberra, Australia Permission to use and/or modify this image is granted provided you acknowledge me [email protected] and The GIMP if someone asks [Larry Ewing] Linux filesystem hierarchy ‘On a Unix/Linux system, everything is a file; if something is not a file, it is a process.’ [tldp.org] Tree structure with exactly one root directory (or / mountpoint), Everything is placed within this structure several kinds of files in Linux The structure of Debian’s root FS The most important directories /etc contains most of system configuration files; network config /dev is a placeholder for special (device) files. Devices are represented by name, and major/minor numbers; /dev/sdaX /proc represents internal kernel structures as very easy to use text files; /proc/cpuinfo /var is a place where a system and the applications typically store data and logs /var/www /usr – programs and documentation for users /usr/src/linux /sbin – system applications /sbin/halt /bin – most of system commands (executables) is stored here /bin/bash File rights and owners: the basics Each file (in Linux almost everything is a file, remember?) has an owner and group owner, represented by numbers (ids); example: /dev/pts/1 Each file has a set of bits representing rights for reading, writing or executing this file by the user who owns it, the group it belongs to or other people; Instead of using single bits (total 9 bits), ‘compact’ representation as three octal digits can be used (why octal?) see also: C language File rights and owners chmod – changes access rights for the file chown – changes owner and group owner of the file standard user cannot take ownership on files not belonging to him for non-superusers it is quite complicated to share a file with only selected users (as opposite to filesystems with ACLs). # chown root:kju file.txt -rw------- 1 root kju 0 lis 19 22:59 file.txt # chown stud file.txt -rw------- 1 stud kju 0 lis 19 22:59 file.txt File rights in examples chmod a+rx app.bin – allow all (everyone) to read and execute app.bin file chmod o-rwx file.txt – deny others to read, modify or execute the file chmod u+rx,go-rwx app.bin – grant user read and execute rights, deny group and others to read,write,execute this file $ touch file.txt ; ls -l file.txt -rw-r--r-- 1 stud stud 0 lis 19 22:59 file.txt $ chmod 500 file.txt ; ls -l file.txt -r-x------ 1 stud stud 0 lis 19 22:59 file.txt $ chmod 600 file.txt ; ls -l file.txt -rw------- 1 stud stud 0 lis 19 22:59 file.txt chmod 777 file.txt ; ls -l file.txt -rwxrwxrwx 1 stud stud 0 lis 19 22:59 file.txt Linux filesystem: mountpoints Mounting of other file systems is quite easy Transparent to user Easy to change configuration without changing the structure of filesystem Mounting filesystems (1) Mounting filesystems (2) /etc/fstab – configuration file which helps mounting (or automounting) of specified filesystems at defined mountpoints; /etc/mtab – currently mounted filesystems; special-type mounts (/sys, /proc, /dev, …) /proc filesystem History: introduced in Unix (1984, Tom Kilian, ‘Processes as Files’; File-like access to internal kernel structures and parameters; ‘Pure virtual’ files don’t exist on a hard disk; Mostly: text files; Writing to file can change internal kernel parameters, easy-to-use and portable solution. /proc filesystem History: introduced in Unix (1984, Tom Kilian, ‘Processes as Files’; File-like access to internal kernel structures and parameters; ‘Pure virtual’ files don’t exist on a hard disk; Mostly: text files; Writing to file can change internal kernel parameters, easy-to-use and portable solution. Process information # ps -ef root 1761 1757 0 14:38 tty1 00:00:01 mc # ls /proc/1761 PID (process identifier) Each process is represented by /proc/PID/ directory, containing useful information, for example: cwd – symbolic link to current working directory of a process with specified PID exe – link to process executable environ – process environment fd, fdinfo – related to open file descriptors Using /proc (1) $ cat /proc/cpuinfo In Linux, /proc is not limited only to process information, it also gives access to many kernel parameters Using /proc (2) ls /proc/sys/kernel/ctrl-alt-del -rw-r--r-- 1 root root 0 2006-03-19 18:13 ctrl-alt-del # cat ctrl-alt-del 0 # echo "1" > ctrl-alt-del ; cat ctrl-alt-del 1 Since now, pressing Ctrl+Alt+Del is like pressing hardware reset: it immediately reboots computer, without unmounting filesystems, flushing disk buffers, etc. The End.