Unix 6 en

35
UNIX OS Lecture VI Simonas Kareiva Vilnius University Faculty of Mathematics and Informatics Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM- 07-K-02-070, funded by The European Social Fund Agency and the Government of Lithuania.

Transcript of Unix 6 en

Page 1: Unix 6 en

UNIX OS Lecture VI

Simonas Kareiva

Vilnius University

Faculty of Mathematics and Informatics

Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM-07-K-02-070, funded by The European Social Fund Agency and the Government of Lithuania.

Page 2: Unix 6 en

Lecture VI outline

File systems

Disks

NFS protocol

RAID arrays

2

Page 3: Unix 6 en

Part I : file systems and disks

disk's structure and terminology

file system types

Linux file systems

indexing

3

Page 4: Unix 6 en

a very typical hard disk

terms:

A) Track

B) Geometrical sector

C) Sector

D) Cluster

4

Page 5: Unix 6 en

Clusters and sectors

Sectors make clusters

Size of a sector – 512 bytes, 2048 bytes

Sectors are grouped into clusters in order to save addressing and number of disk requests.

Cluster is the smallest logical disk’s element which can store information, so:5KB file in disk uses 8KB when cluster size is 4KB

5

Page 6: Unix 6 en

FAT…

FAT… bits tell the cluster address table size:

FAT12 – maximum partition Size– 32MB Max number of clusters – 2^12-12, clusters up to 8K

FAT16 – max partition size – ??? GB (exercise)Clusters up to 64K

FAT32 - (many nice features) – max partition still 2TB

6

Page 7: Unix 6 en

More file systems:

NTFS

UFS

EXT2

EXT3

ReiserFS

HFS

7

Page 8: Unix 6 en

Disk devices (Linux):

/dev/ /dev/hda

/dev/hda1 /dev/hda2

/dev/hdb /dev/hdc /dev/sda

/dev/sda1 …

8

Page 9: Unix 6 en

Disk devices (FreeBSD)

/dev/ /dev/ad0

/dev/ad0s1 /dev/ad0s1a /dev/ad0s1b /dev/ad0s1c

/dev/ad1 /dev/ad1s1

/dev/ad1s1a /dev/da0

/dev/da0s1 /dev/da0s1a

9

Page 10: Unix 6 en

Disk devices (Solaris)

/dev/dsk/ /dev/dsk/c1

/dev/dsk/c1t0 /dev/dsk/c1t0d0

/dev/dsk/c1t0d0p0 /dev/dsk/c1t0d0s1

c – controller (control device)

t – SCSI target

d – LUN-id (mostly 0)

s – Solaris slice or p – primary partition

10

Page 11: Unix 6 en

Working with disks (Linux)

# fdisk -l /dev/hdc

Disk /dev/hdc: 64 heads, 63 sectors, 787 cylinders Units = cylinders of 4032 * 512 bytes

Device Boot Start End Blocks Id System /dev/hdc1 * 1 610 1229728+ 83 Linux /dev/hdc2 611 787 356832 5 Extended /dev/hdc5 611 787 356800+ c Win95 FAT32 (LBA)

11

Page 12: Unix 6 en

Creating a new disk

Create a partition with fdisk (RTM)

Linux:mkfs -t ext2 /dev/hdc1

or

mkfs.reiserfs /dev/hdc1

FreeBSD:newfs /dev/da0s1a

12

Page 13: Unix 6 en

Mounting

mkdir /mnt/new

mount /dev/hdc1 /mnt/new

13

Page 14: Unix 6 en

/etc/fstab

# FreeBSD fstab:# Device Mountpoint FStype Options Dump Pass#/dev/da0s1b none swap sw 0 0/dev/da0s1a / ufs rw 1 1/dev/da0s1e /tmp ufs rw 2 2/dev/da0s1f /usr ufs rw 2 2/dev/da0s1d /var ufs rw 2 2/dev/da1s1a /squid ufs rw 2 2/dev/acd0 /cdrom cd9660 ro,noauto 0 0

# Linux fstab:/dev/rootvg/lv00 / ext3 defaults 1 1/dev/rootvg/lv02 /vz ext3 defaults 1 2/dev/md0 /boot ext3 defaults 1 2tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0/dev/rootvg/lv01 swap swap defaults 0 0

14

Page 15: Unix 6 en

NFS protocol

Like Windows File Sharing, but not exactly...

Designed for intensive data exchange between servers

Easily configurable

From an OS point of view, its just another file system (partition)

15

Page 16: Unix 6 en

What you’ll need:

FreeBSD:nfsd – daemon, processing user requestsmountd – daemon, responsible for FS mounting rpcbind – additional service used for chatting within

the network

/etc/exports:Format:

/folder/which/shared –paremeters client1 client2…

16

Page 17: Unix 6 en

/etc/exports:

/cdrom -ro host1 host2 host3/home -alldands 10.0.0.2 10.0.0.3 10.0.0.4/a -maproot=root host.example.com box.example.org/usr/src /usr/ports host4

Then we execute:

# rpcbind # nfsd -u -t -n 4 # mountd -r

17

Page 18: Unix 6 en

Or use:# showmount -e serverExports list on server:/usr 10.10.10.0/a 10.10.10.0

# mkdand /mnt/a

# mount server:/a /mnt/a# df -F nfs Filesystem Type blocks use avail %use Mounted on server:/a nfs 68510 55804 12706 81% /mnt/a

18

Page 19: Unix 6 en

Practical uses

Most OS’s support installation through NFS, its enough to have 1 DVD which is shared via NFS on LAN.

By using NFS you can create a couple of HTTP servers with the same content and distribute traffic between them by using the round-robin load balancing algorithm.

In large networks, it is useful to keep /home folders on NFS, so that user’s files are saved centrally.

Exercise: think of more practical NFS uses!

19

Page 20: Unix 6 en

RAID

terms:RAID – Redundant array of Inexpensive Disks JBOD – Just a bunch of … ?Hot spare – reserve playerStripe – data distribution in multiple devicesMirror – data backup in multiple devices Parity – protection from errors system (XOR):

0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0 Dedicated parity – data in separate disk

20

Page 21: Unix 6 en

RAID types

RAID0, RAID1, RAID2, RAID3, RAID4, RAID5, RAID6

RAID0+1, RAID1+0, RAID0+3, RAID51, …

21

Page 22: Unix 6 en

Say,

We have four disks:Three 200GB disksOne 300GB disk

22

Page 23: Unix 6 en

RAID0

Size = n * min ( 200GB, 300GB ) = 800GB

Advantages:Fast readingFast writingLots of space

Disadvantages:Totally unreliable (if one of the disks

breaks down, the entire RAID stops)

23

Page 24: Unix 6 en

RAID1

Size= min ( 200GB, 300GB ) = 200GB

Advantages:Fast readingReliability and security

Disadvantages:Expensive writing (to both disks)

24

Page 25: Unix 6 en

RAID5

Size= n-1 * min ( 200GB, 300GB ) = 200GB

Advantages:Fast readingFast writingReliability and security (parity)

Disadvantages:Requires at least 3 disks, often requires +1

additionalSlow, when at least stripe size is being written

25

Page 26: Unix 6 en

Parity

disk #1: -------- (Data)disk #2: -------- (Data)disk #3: -------- (Data)disk #4: -------- (Data)disk #5: -------- (Hot Spare)disk #6: -------- (Parity)

26

Page 27: Unix 6 en

Parity

disk #1: 00101010 (Data)disk #2: 10001110 (Data)disk #3: 11110111 (Data)disk #4: 10110101 (Data)disk #5: -------- (Hot Spare)disk #6: -------- (Parity)

00101010 XOR 10001110 XOR 11110111 XOR 10110101 = 11100110

D1 XOR D2 XOR D3 XOR D4 = ( (D1 XOR D2) XOR D3) XOR D4

27

Page 28: Unix 6 en

Parity

disk #1: 00101010 (Data)disk #2: 10001110 (Data)disk #3: 11110111 (Data)disk #4: 10110101 (Data)disk #5: -------- (Hot Spare)disk #6: 11100110 (Parity)

28

Page 29: Unix 6 en

Parity

disk #1: 00101010 (Data)disk #2: 10001110 (Data)disk #3: --Dead-- (Data)disk #4: 10110101 (Data)disk #5: 11110111 (Hot Spare)disk #6: 11100110 (Parity)

00101010 XOR 10001110 XOR 11100110 XOR 10110101 = 11110111

29

Page 30: Unix 6 en

RAID2, RAID3

30

Page 31: Unix 6 en

31

Page 32: Unix 6 en

RAID derivatives32

Page 33: Unix 6 en

Yo, dawg, I heard you like RAID…

… so we put more RAID into your RAID so that you can have more RAID!

33

Page 34: Unix 6 en

34

Page 35: Unix 6 en

Cheat-sheet of RAID configurations

35