LINUX
LINUX
LINUX Basic
• What is it
• Architecture
• Distributions
• SUSE Linux Enterprise
Server
• Remote administration
– TCP/IP, IP tunneling
– CLI basic commands
2025-02-27 2
What is it
• Open Source Operating System based on UNIX
• Kernel + Libraries + Utilities + Applications
• Multiplatform
• Community - Internet development
• Free Licenses: GPL, LGPL, BSD Like ...
• History (1991 by Linus Torvalds)
• Supercomputers, servers, embedded ... desktop
2025-02-27
Distributions
• Community or Company
• Debian/Ubuntu, Opensuse/Novell,
Fedora/Red Hat, Mandriva, live DVD
distributions (Knoppix)
• Support and Certificates
• Development
• Packaging (build service)
• Updates
2025-02-27 6
GUI
• X Server
• Truetype Fonts support (DejaVu), UTF8
• Video Drivers (ATI, Nvidia, Intel)
• Window Manager
• Composite Manager
• GNOME GUI
• Firefox browser
2025-02-27 7
Your system:OpenSUSE+GNOME
• Novell
• 6 month release cycle
• 11.4
• Installation
• dvd/docu
• http://www.opensuse.org/
2025-02-27 8
GUI
2025-02-27 9
Operating System
• Abstraction to HW by common API
• Resource management
– Memory management
– Process management
– I/O and device management
• Filesystem
• Boot
• Security
• GUI
2025-02-27 11
Memory management 1
• Virtual and Physical
memory
• Page = smallest
contiguous block of
memory (4 kB)
• Page table =
translation table from
VM to PHM
2025-02-27 12
Memory management 2
• Interprocess Protection (segmentation fault)
• Demand Paging (mmap), Swap (file, partition)
• Cache and Buffers
• Out of memory (64 GB, for x86 32 bit with PAE)
• ;-) “640 k ought to be enough for anyone”, Bill
Gates, 1981
skyims1:~ # free -m
total used free shared buffers cached
Mem: 3898 1888 2010 0 305 719
-/+ buffers/cache: 863 3035
Swap: 4086 0 4086
2025-02-27 13
Process management 1
• Multi CPU / Core effective support
• Multi Processes / Threads support
• Preemption = interruption of running process
• Scheduling:
– Real Time => Lowest Latency
– Fair => Biggest Data flow
• Real multitasking
• Ring-level 0
2025-02-27 14
Process management 2
• Tick = Max count of context switch per second
(100, 250, 1000)
• Time Slice = Period of time for which a process is
allowed to run
• Scheduling Priorities (nice level)
– 20 most favorable process
– 9 least favorable process
• Synchronization: Semaphores, Mutual exlusions
• Dead Lock Problem
2025-02-27 15
Process management 3
2025-02-27 16
Devices
• /dev/sda, /dev/sdb – hard discs
– /dev/sda1, /dev/sda2, ... - disc partitions
– /dev/md0, /dev/md1 – RAID devices
• /dev/ttyS0 – serial port (COM1)
• /dev/ttyUSB0 – USB device as serial port
• /dev/zero
• /dev/random
2025-02-27 18
Drivers
• Modularity
• Common API
• On line change
• Stability and Reliability
• OSS and Third-party
• “Weakness”
• Kernel and User space drivers
2025-02-27 19
Filesystem 1
• Ext2-3, FAT, NTFS, ISO-9660 ...
• Journaling (Writeback, Ordered, Data)
• Fragmentation
• Ext3 metadata – inodes, files, dirs, links
• Fsck – automatic / manual data checking
• Limits and Block size
2025-02-27 20
Filesystem 2
2025-02-27 21
Filesystem 3
• Directory separator “/” instead of Windows “\”
• No concept of disk drives (A:, C:, ...)
• All disks mapped (mounted) to directories
under /
• DVD, USB flash: /media/XXX
• Mount, umount command
• Automount of DVD and USB flash
2025-02-27 22
Directory Structure
Root /
/boot ... Boot images for kernel and startup modules
/dev ... Device access names
/etc ... Configuration
/lib ... Kernel modules and basic libraries
/usr ... Applications
/tmp ... Temporary files
/home ... User data (protected between users)
/opt ... Third-party applications (SKY-IMS)
/var ... Running applications information, postgresql database
/media ... Removable devices access
/drbd ... Cluster mirrored data
/proc … Information about the system
2025-02-27 23
pwd
show current working directory
skyims1:/opt # pwd
/opt
skyims1:/opt #
2025-02-27 25
rmdir directory
removes directory
skyims1:/opt # rmdir test
skyims1:/opt #
2025-02-27 26
less file
simple show file content with paging
tail file
simple show file end
head file
simple show file start
2025-02-27 27
mv -v source dest
move source file or directory (-r) to destination
skyims1:/opt # mv -v testfile /root
`testfile' -> `/root/testfile'
removed `testfile'
rm -rv file
remove file or directory (-r)
skyims1:/opt # rm -v testfile
removed `testfile'
2025-02-27 29
Midnight Commander
mc
2025-02-27 34
Security
• Users, Groups, Admin: root (passwd, shadows)
• File/device access rwx-rwx-rwx
• Firewall, Public IP
• Updates
• Secure shell (ssh, putty.exe)
• Cryptography (keys, truecrypt)
• HTTPS
• No virus yet!
2025-02-27 35
Boot
• BIOS => POST
• Grub Loader loads Kernel and Modules images
• Kernel and Modules initialization
• Init process => runlevels (default 5, 0 – halt, 6 -
reboot)
• Background Services
• GUI Login (autologin for user ims)
• Applications
2025-02-27 36
TCP/IP
• Data link layer: ethernet (MAC), serial, modem
• Network layer: IP, ARP, ICMP
• Transport layer: UDP, TCP
• Application layer: FTP, HTTP, IMAP, POP3 ...
• Socket – address and port, DNS
• Forwarding, tunneling, VPN
• Gateway
• NAT, public, private, local IP (10.10.; 127.0.0.1)
2025-02-27 37
kill pid
stop process by ID; also killall process_name
reboot
halt
2025-02-27 47
df -h
show free disk space
2025-02-27 48
mount
show mounted devices; also mount or umount devices
2025-02-27 49
hwclock
show current local hw clock date and time
2025-02-27 50
insserv -r service_name
insert or remove (-r) service
2025-02-27 51
dmesg
show kernel messages
2025-02-27 52
Database commands
• Database is running only on main computer
• su – postgres
• psql -d ims
• \dt
• select * from messages2 where id > 1 limit 1;
2025-02-27 53
RAID
• Linux software RAID
• RAID1 – mirror
– Data replication for
better reliability a data
lost prevention
– Better read speed
• HDD hot plug feature
with AHCI
2025-02-27 55
Heartbeat
• Linux high-availability and Hot/Warm
failover solution
• Locked into memory and soft realtime for
minimal latency
• Two nodes (Main / Stand-by)
• Network (crosslink) and serial
communication cable
• Automatic resource monitoring and takeover
2025-02-27 56
Heartbeat
2025-02-27 57
DRBD
2025-02-27 58
DRBD
• Distributed Replicated
Block Device
• Automatic
synchronization via
high speed LAN
• Integrated with
heartbeat and SKY-IMS
2025-02-27 59
DRBD
cat /proc/drbd
shows DRBD status
/etc/init.d/drbd start
starts drbd
2025-02-27 60
DRBD
/etc/init.d/drbd stop
stops drbd
drbdadm adjust all
forced quick synchronization, consumes CPU
DRBD Configuration:
/etc/drbd.conf
2025-02-27 61
Troubleshooting:RAID1 Rescue
Failure of one disc results in failure of the PC.
• Boot from OpenSUSE DVD and choose “Rescue”
• Login as root
• Mount raid by command: mount /dev/md0/mnt
• Mount dev: mount -o bind /dev /mnt/dev
• Change root directory: chroot /mnt
• Type command “cat /proc/mdstat” - bad disc is marked as “F:”
• Install Master Boot Record on the correct disc (let it be /dev/sdb)
grub
device (hd0) /dev/sdb
root (hd0,1)
setup (hd0)
Quit
• Reboot
2025-02-27 62
Troubleshooting:RAID1 Rescue 2
If the system does not boot, both disks are corrupted -> reinstallation.
If system reboots, shutdown, change the bad disc, boot PC.
Let /dev/sdb is OK disc and /dev/sda wrong one.
Read MBR from /dev/sdb to file: sfdisk -d /dev/sdb > /tmp/mbr
Write MBR from file to MBR: sfdisk /dev/sda < /tmp/mbr
Add the new disc to raid: mdadm /dev/md0 -a /dev/sda2
Write grub to sda:
grub
device (hd0) /dev/sda
root (hd0,1)
setup (hd0)
quit
We can verify by command “cat /proc/mdstat”, if the disc is added and
synchronizes.
2025-02-27 63
Disk partitioning:
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a6017
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 6410 51383902+ fd Linux raid autodetect
/dev/sda3 6411 19457 104800027+ fd Linux raid autodetect
2025-02-27 64
• Clients:
– No special IP-adresses need. Need only to be in the network 192.168.155.0
• MOXA NPORT
– IP of 8 nport in rack = 192.168.155.99
• PRINTER HP
– IP address is 192.168.155.98
2025-02-27 65
Router starting:
1. All LAN LEDs ligthing, PWR/SYS LED blinking ~ 25 sec
2. All LEDs off ~ 2 sec
3. Only PWR is on and LAN is blinking and DSL is blinking ~ 30
sec
4. DSL LED is on and PPP/ACT LED blinking = connected