4. History
4
In 80’s, Microsoft’s DOS was the dominated OS for PC
Apple MAC was better, but expensive
UNIX was much better, but much, much more expensive. Only for
minicomputer for commercial applications
People were looking for a UNIX based system, which is cheaper and can run
on PC
Both DOS, MAC and UNIX were proprietary, i.e., the source code of their
kernel is protected
No modification is possible without paying high license fees
5. GNU
5
Established in 1984 by Richard Stallman, who believes that software should be free
from restrictions against copying or modification in order to make better and efficient
computer programs
GNU is a recursive acronym for “GNU's Not Unix”
Aim at developing a complete Unix-like operating system which is free for copying
and modification
Companies make their money by maintaining and distributing the software, e.g.
optimally packaging the software with different tools (Redhat, Slackware, Mandrake,
SuSE, etc)
Stallman built the first free GNU C Compiler in 1991. But still, an OS was yet to be
developed
6. Begin Linux
6
Andrew Tanenbaum developed Minix, a simplified version of UNIX that runs on
PC
In Sept 1991, Linus Torvalds, a second year student of Computer Science at the
University of Helsinki, developed the preliminary kernel of Linux, known as
Linux version 0.0.1
Soon more than a hundred people joined the Linux camp. Then thousands.
Then hundreds of thousands
It was licensed under GNU General Public License, thus ensuring that the
source codes will be free for all to copy, study and to change.
7. 7
At 25/11/2012 08:31pm, there are 118,240 users and 95,204 machines registered.
My guess at the number of Linux users: 63,195,939
World population: 7,096,950,557
Internet users: 2,478,272,151
– Taken from linuxcounter.net
8. Major Software from GNU Project
8
Gcc : c compiler
G++: C++ compiler
Gdb: source code debugger
GNU make: a version of make
Bison: a parser generator
Bash: command shell
GNU emacs: a text editor
9. Linux directory structure
9
/ - root directory
/bin – essential programs
/boot – boot information for linux
/dev – includes all devices
/mnt – storage devices are mounted
/proc – fluid data and status of kernel
/sbin – sys admin software
/etc – admin related config files and folders
/home
/lib
/tmp
/usr
/var
12. Linux continue to grow…
12
Mobile OS: Android is Linux based
Major Virtualization flavour: Base kernel is Linux
Citrix Xen
Vmware
Cloud solution - Openstack
17. Commands
17
Change the working directory – cd, cd~, cd /, cd /var/log
Display the working directory – pwd
Display a line of text – echo Hello
Execute a program – exec myprog
Time an operation – time lsof
Total execution time, user cpu time, system cpu time
Set options – environment variables
Terminate the shell
Exit
logout
18. MAN Page
18
1 Executable programs and shell commands
2 System calls provided by the kernel
3 Library calls provided by program libraries
4 Device files (usually stored in /dev)
5 File formats
6 Games
7 Miscellaneous (macro packages, conventions, and so on)
8 System administration commands (programs run mostly or exclusively
by root)
9 Kernel routines
19. Redirection
19
> : Creates a new file containing standard output. If the specified file exists, it’s
overwritten.
>> : Appends standard output to the existing file. If the specified file doesn’t exist,
it’s created.
2> : Creates a new file containing standard error. If the specified file exists, it’s
overwritten.
2>> : Appends standard error to the existing file. If the specified file doesn’t exist,
it’s created.
&> : Creates a new file containing both standard output and standard error. If the
specified file exists, it’s overwritten.
< : Sends the contents of the specified file to be used as standard input.
<< : Accepts text on the following lines as standard input.
20. Redirection continued…
20
<> : Causes the specified file to be used for both standard input and standard
output.
tee command
View the command and send the output to another file
lsmod | tee lsmod.txt
24. Package Concepts
24
Packages: collection of files
Installed file database
Dependencies
Checksums
Upgrades and uninstallation
Package naming: samba-4.0.12-24.i386.rpm
– Package name
– Version no
– Build no
– arhitecture
25. RPM Operations
25
-i : Installs a package;
-U : Installs a new package or upgrades an existing one
-F or --freshen : Upgrades a package only if an earlier version already exists
-q : Queries a package—finds if a package is installed, what files it contains, and so on
-V or --verify : Verifies a package—checks that its files are present and unchanged
since installation
-e : Uninstalls a package
26. rpm examples
26
rpm -qa -> lists all the installed packages
rpm -qc {pname} -> list configuartion file names for given package
rpm -qi {pnane} -> Give details of package
rpm -ql {pname} -> lists the files in a package
rpm -qR {pname} -> Lists package dependencies
rpm -qf filename -> List the package name of given file
rpm -qpl {pname} -> lists all the files in a package
rpm -qp {pname} -> list the package with given pname(*/?)
rpm -Va -> Verify all the installed packages
rpm -V {pname} -> Verify specify package
rpm -V -f {filename} {packagename} -> Verify a specified file in a package
31. alien
Covert packages from one format to another
Formats are:
Linux standard base
RPM
deb
stampede(.slp)
Solaris(.pkg)
Slackware(.tgz)
# alien --to-rpm --scripts ./mypkg.deb
33. Understanding the kernel
uname –n -> hostname
uname –s -> kernel name
uname –v -> kernel version
uname –r -> kernel release
uname –m -> machine option
uname –p -> Processor
uname –o -> Operating system
uname –i -> Hardware platform
uname –a -> all information
34. Process – ps output meaning(columns)
Username
Process ID
Parent Process ID
TTY – identifying terminal
Cpu time
Cpu priority
memory use
Command
35. Other Process related commands
Dynamic variant of process – top
nice : Run a program with modified scheduling priority. Priority ranges from
-20(most favorable) to +19(least favorable)
renice : alter priority of running processes
kill
nohup
killall
37. Hardware
BIOS – resides on the motherboard in ROM – EEPROM/Flash memory
When computer is turned on- BIOS performs POST and initializes hardware and
then load boot loader
IRQ - An interrupt request (IRQ), or interrupt, is a signal sent to the CPU instructing
it to suspend its current activity and to handle some external event such as
keyboard input. /proc/interrupts
I/O addresses (also referred to as I/O ports) are unique locations in memory that
are reserved for communications between the CPU and specific physical hardware
devices. Like IRQs, These are commonly associated with specific devices and
should not ordinarily be shared.
DMA Addresses - Direct memory addressing (DMA) is an alternative method of
communication to I/O ports. Rather than have the CPU mediate the transfer of data
between a device and memory, DMA permits the device to transfer data directly,
without the CPU’s attention. The result can be lower CPU requirements for I/O
activity, which can improve overall system performance.
/proc/dma
39. Coldplug and Hotplug devices
Colplug devices – Components internal to the computer such as memory, CPU, pci
cards etc. resides on the motherboard in ROM – EEPROM/Flash memory
Hotplug devices – Devices which can be added/removed when the system is in
running state.
42. Configuring USB devices
USB basics
USB 1.0 and USB 1.1 : 12Mbps
USB 2.0 : 48Mbps
USB 3.0 : 3.2 Gbps
USB devices: Scanner, printer, mice, digital camera, keyboard, speakers etc.
lsusb
/proc/bus/usb
usbmgr
/etc/usbmgr/usbmgr.conf
43. Systems Run Levels
0: Halt
1: single User mode
2: Multi user mode without NFS
3: Full multi user mode
4: unused
5: X11
6: reboot
48. Inode table
Owner of the file
Group of the file
File type
File access permission
Date and time of last access
Date and time of last modification
Number of links to the file
Size of the file
Addresses of blocks where the file is physically present
49. Surrogate super block and Inode table
Super block – state of the file system
Size
No of files it can accommodate
How many mores can be created
sync
55. File Access
Changing file permission: chmod
$ ls -l test
-rwxr-xr-x 1 rodsmith users 111 Apr 13 13:48 test
– “-” -> file
– d -> firectory
– l -> symbolic link
– p -> Named pipe
– s -> Socket
– b -> Block device
– c -> Character device
SUID
SGID
Sticky bit
56. Setting the default mode and group
Default permissions are configurable and defined by user mask.(umask)
• Umask Created Files Created Directories
• 000 666 (rw-rw-rw-) 777 (rwxrwxrwx)
• 002 664 (rw-rw-r--) 775 (rwxrwxr-x)
• 022 644 (rw-r--r--) 755 (rwxr-xr-x)
• 027 640 (rw-r-----) 750 (rwxr-x---)
• 077 600 (rw-------) 700 (rwx------)
• 277 400 (r--------) 500 (r-x------)
57. Managing Disk Quotas
Enabling Quota Support
Kernel 2.4.x – quota v1 support
Kernel 2.6.x – quota v2 support
/etc/fstab
/dev/hdc5 /home ext3 usrquota,grpquota 1 1
chkconfig quota on
Setting quota for users, edquota raghu
59. Regular Expressions
59
Bracket Expressions: d[aeiou]g => dag, deg, dig, dog, dug
Range Expression : a[1-5] => a1, a2, a3, a4, a5
Any single character except new line: .
Start and end of line: ^ and $
Repetition operators: * -> 0 and more), + -> 1 and more, ? -> 0 and 1
Any single character except new line: .
Multiple possible strings: Linux | Windows
Escaping: backslash
61. Sed(stream editor)
61
Modifies the contents of files
• sed [options] -f script-file [input-file]
• sed [options] script-text [input-file]
$ sed ‘s/2009/2010/’ cal-2009.txt > cal-2010.txt
62. awk
62
Print list of all processes of all the users
ps -ef | awk '{print $1"=>" $8}‘
Print all the child process of PPID 1.
ps -ef | grep -w 1 | grep -v /1 | awk '{print $2"=>"$3"=>"$8}‘
Display and create all the loaded module details in a file
lsmod | awk '{print $1}'| xargs modinfo | tee mod.txt
63. File Systems
63
Ext2/3: Native file system
Reiserfs : Suitable for small files – less than 1K
Vfat : 32bit file system compatible with win
XFS : Journaling file systems –handle large files
JFS : Handles power down and crashes
Swap: virtual memory
Iso9660 : cdfs, dvd
68. LILO – Linux Loader
Configuration file: /etc/lilo.conf
Boot loader location: boot=/dev/hda
Default: default os to boot
Boot Prompt
Boot Timeout
Linux root partition, root=/dev/hda4
Boot in read-only mode
Linux boot image: image=/kernelimage
RAM disk: initrd=oskernel imahe
Extra kernel option: mem=2048
Lilo –c – testing purpose
Lilo –v – output in verpose
69. LILO prompt
Boot: linux 1 -> To boot in single user mode 1/S/s/single can be typed
If suppose init program is corrupted
Boot: linux init=/bin/sh can be used
71. LILO and GRUB
Confidential71
LILO GRUB
/dev/hda (hd0)
/dev/hda1 (hd0,0)
/dev/hdb (hd1)
/etc/lilo.conf /boot/grub/menu.lst
lilo /etc/lilo.conf grub-install /dev/hda
72. Linux Boot Process
• System Power on-> CPU executes BIOS code->BIOS(Post, check and configure
hardware)->Boot loader kicks off->OS kernel is loaded(initialize devices, mount
boot partition, init program starts->init selects run level from /etc/inittab and default
level run level loads
Inittab entry
• id:runlevels:action:process
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
73. Linux Boot Process contd..
inittab file
id:3:initdefault:
5:2345:respawn:/sbin/mingetty tty5
chkconfig : updates and queries run level information for system services.
runlevel : Find the current and previous run level
init : parent of all the processes
telinit: tell init to switch to specified runlevel
shutdown
74. Life cycle of a process
fork and exec
init – process id 1
getty
login
sh
Who or grep or any command running on shell
kill
75. Linux installation and designing hard disk layout
/ : default root partition
/var : logs related entries
/home: User home directory
/opt: Optional packages
Swap space: typically double of RAM
77. usermod
Usermod –l [newlogin] [login]
Usermod –c [comment login]
Usermod –f [no of days] [login] => no of days password to expire
Usermod –L [login] -> lock the password and suspend the user
Usermod –U [login] -> unlock the password
Usermod –e [yyyy-mm-dd] [login] -> change the expiration date
78. Tuning User and System Environments
Global Configuration file
/etc/profile
/etc/bash.bashrc
User Configuration file
~/.profile
~/.bashrc
Configuartion file for added user’s fefault environment setting
/etc/skel
Kernel Parameter
/etc/sysctl.conf
sysctl
79. Automate system administration tasks by scheduling jobs
Manage cron and at jobs
Configure user access to cron and at services
The following is a partial list of the used files, terms, and utilities:
/etc/cron.{d,daily,hourly,monthly,weekly}
/etc/crontab
crontab –e
80. Cron job Definition
80
* * * * * Command
Minute(0-59)
Hour(0-23)
Day of month(0-31)
Month(1-12)
Day of week(1-7)
82. Systems Monitoring
Process
ps
top
Disk space
df
du
Bandwidth
tcpdump
netstat
Memory
pmap
ps
free
other commands
lsof
83. Systems Monitoring contd…
uptime: Load average is average no of processes waiting to run in 1min, 5min, and
15 mins. Ideally it should be <1.
tload is graphical presentation of uptime.
vmstat-Virtual memory usage
pmap -x pid: mapping of processes with memory resources
scsiinfo
hdparam
84. Perform security administration tasks
Audit system to find files with the suid/sgid bit set.
Set or change user passwords and password aging information.
Discovering open ports on a system: nmap, netstat
Setting up limits on user logins, processes and memory usage
ulimit
Basic sudo configuration and usage
/etc/sudoers
85. Linux Kernel
Module components in source tree: /usr/src/linux
Module components at runtime: /lib/modules/<kernelversion>/kernel.
Download latest stable kernel from www.kernel.org
Unpack the kernel
Compiling a kernel:
make config/menuconifg/xconfig
make dep
make bzImage
make modules
make modules_install
make install
Installing the kernel image using boot loader: /boot/grub/grub.conf
Reboot the system and new kernel should be up
86. Shell Scripting
Variables – strings, numbers, environment and paramter
Conditions: shell booleans
Control Structures: if, elif, for, while, until, case
Lists
Functions
Commands built into shell
Getting the result of a command
Here documents
89. Control Structures
If
if condition
then
Statements
else
Statements
fi
elif
if condition
then
Statements
elif
then
statements
else
Statements
fi
90. Control Structures contd..
for
for variable in values
do
statements
done
while
while condition do
statements
done
until
until condition
do
statements
done
91. Control Structures contd..
Case
Case variable in
pattern1 statements;;
pattern2 statements;;
pattern3 statements;;
esac
95. Basic Network Configuration
Manually and automatically configure network interfaces
Basic TCP/IP host configuration
The following is a partial list of the used files, terms, and utilities:
/etc/hostname
/etc/hosts
/etc/resolv.conf
/etc/nsswitch.conf
ifconfig
98. Network Port numbers
• Port Number TCP or UDP Purpose Example Linux Servers
20 TCP File Transfer Protocol ProFTPd, vsftpd
21 TCP FTP ProFTPd, vsftpd
22 TCP Secure Shell (SSH) OpenSSH, Dropbear
23 TCP Telnet in.telnetd
25 TCP Simple Mail Transfer Protocol (SMTP)Sendmail, Postfix,
53 TCP and UDP Domain Name System (DNS) BIND;
101. Linux Server
Web Server – Apache
Database Server – mysql, oracle
ftp server – proftp, vsftp
File server - samba
Mail server – sendmail, postfix
102. Linux Firewall
#iptables -t filter -A INPUT -p tcp --dport 22 -j DROP
#iptables -t filter -A INPUT -p udp --dport 22 -j DROP
#iptables -t filter -A INPUT -p tcp --dport 23 -j DROP
#iptables -t filter -A INPUT -p udp --dport 23 -j DROP
#iptables -t filter -P OUPUT DROP
#iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
#iptables -t filter -A OUTPUT -p udp --dport 80 -j ACCEPT
#iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
#iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
# service iptables save
#service iptables restart
103. Exercise
How long the server is running and no of users who are using the system.
Create a user with your name, create a group name training, validity
period, home directory, assign training group
Search for files with specific pattern
Display line no 10 to line no 20 , from a file having 30 lines.
print file in reverse
Command to check if the all the file on given directory does not contain a
given word[e.g error]
Sort the content of a file and copy only unique entries to the new file
List files having links.
105. Exercise(Answers)
• How long the server is running and no of users who are using the system.
uptime
• Search for files ending with .log
find ./ -name “*.log”
• Display line no 10 to line no 20 , from a file having 30+ lines.
sed –n 11,20 [filename]
• Display last 10 lines
tail –n 10 [filename]
• print file in reverse
tac [filename]
106. Exercise(Answers)
• Command to check if the all the file on given directory does not contain a
given word[e.g error]
grep –vi error *.txt
• Sort the content of a file and copy only unique entries to the new file
sort a.txt | uniq > b.txt
• List files having links.
ls –l | grep “^l”
Notes de l'éditeur
Minix is for class teaching only. No intention for commercial use