12
System Administration – Part 2

System Administration – Part 2

  • Upload
    crevan

  • View
    27

  • Download
    2

Embed Size (px)

DESCRIPTION

System Administration – Part 2. Devices in UNIX. Devices in UNIX are files: A device can be accessed with different file names All device files are stored in /dev or its sub-directories Device files can be grouped in to 2 main categories: - PowerPoint PPT Presentation

Citation preview

Page 1: System Administration – Part 2

System Administration – Part 2

Page 2: System Administration – Part 2

• Devices in UNIX are files:• A device can be accessed with different file names• All device files are stored in /dev or its sub-directories• Device files can be grouped in to 2 main categories:

b (block devices) include floppy, CD-ROM, disk drives, DVD

All data is read & written in blocks an uses a buffer cache.

Example file listing: brw-rw-rw- fd0 c (character devices) include terminals, printers and tape

drives. Also known as raw devices.

Example file listing: crw-rw-rw- tty1A • Device file do not contain any data.

Devices in UNIX

Page 3: System Administration – Part 2

How the UNIX File System Is Organized on Disk Drives

• Each drive is organized in the form of a directory structure with own sub-root

• Each disk must have at least 1 file system on it• UNIX usually resides on multiple file systems. Mounting

combines them into one logical system• Root File System: Contains bare-bones UNIX - /root,

/bin, /etc, /dev, /lib• UNIX often has a swap file system where the kernel temporarily

moves processes out of memory while it is waiting, e.g., I/O transfers, to swap in once process is ready to run again.

Page 4: System Administration – Part 2

Secondary Disk drives must be mounted to be known to the kernel: When a new file system is created, root does not know of it. mount attaches all secondary file systems to the root file system.

Enables root to be main file system with the root directory the directory of a unified file system.

Example: mount –F ufs /dev/dsk/ct08d0s1 /oracle mount command by it self lists all mounted drives. A mount point is the location in the operating system's

directory structure where a mounted file system appears by the name provided, i.e., a child directory of root.

Example: /oracle is the device’s mount-point in the above

Mounting Disk Drives in UNIX

Page 5: System Administration – Part 2

Unmounting Disk Drives in UNIX

• The umount (note spelling!) command disassociates and detaches a

secondary file system . Example (system-dependent, like mount):

umount /oracle # linux

umount /dev/hda3 /oracle # linux

umount /dev/dsk/ct08d0s1 # solaris

o If a mounted file system is being used by a user, i.e., the user has cd’ to /oracle, the umount command will fail.

# umount: /oracle busy o To use umount, the user must be in a directory closer to root

than the file system being detached.

Page 6: System Administration – Part 2

What’s in a UNIX File System?

Boot block: Referred to as Master Boot Record (MBR). Contains

small boot program and the partition table.

Superblock: Contains global info about the file sytem, includes

a list of free inodes and data blocks.

inode blocks: Contains the inode value for each file of the file system.

When file is created, its inode entry is allocated here.

Contains array of disk block addresses.

Data blocks: Contains all user created data and programs. Although

disk blocks are numbered consecutively, the file’s data

may be arranged in non-contiguous blocks on the drive.

Note: Blocks are usually 512 bytes (or 1024 bytes in Linux).

Page 7: System Administration – Part 2

When Good File Systems Go Bad

• Every 30 seconds the update daemon writes copies of the superblock to disk using sync. But what happens if power is lost before a sync is performed?

• The file system can lose its integrity in ways like: two inodes can claim the same disk blocka used block is marked freea free block is not listed in the superblock

• There is a periodic need to check (and sometimes repair) a file system that may have gone bad.

Page 8: System Administration – Part 2

Checking the File Systemfsck – File System Consistency Check

• Used if file system fails to mount. Checks and repairs damaged file system (dirty, not clean) .

• Damage often occurs from abnormal shutdown due to hardware failure, power failure or switching off without proper shutdown. 

• If cannot be repaired, then reinstallation of system may be required.

Example: # fsck /dev/da0s1a

** phase 1 - Check Blocks and Sizes ** phase 2 - Check Pathnames ** phase 3 - Check Connectivity ** phase 4 - Check Reference Counts ** phase 5 - Check Free List # (checks out ok, otherwise answer questions to fix)

Page 9: System Administration – Part 2

Monitoring Free Disk Space

df - reports amount of free space for each file system (separately).

$ df -k Filesystem 1024-blocks Free %Used Iused %Iused Mounted on /dev/hd4 32768 16016 52% 2271 14% / /dev/hd2 4587520 1889420 59% 37791 4% /usr /dev/hd9var 65536 12032 82% 518 4% /var /dev/hd3 819200 637832 23% 1829 1% /tmp /dev/hd1 524288 395848 25% 421 1% /home /proc - - - - - /proc /dev/hd10opt 65536 26004 61% 654 4% /opt

Page 10: System Administration – Part 2

Monitoring Disk Space Useddu - reports used disk space for each subordinate directory (separately).

• Example: directory usage listed in kilobytes:$ du -k * 152304 ./junk11856548 ./junk2• Example: directory usage in human-readable format:$ du -h * 149M ./junk11.8G ./junk21.3K ./junk3• Example: report usage of all subdirectories and files including hidden files, sorted by filesize :$ du -k .[A-z]* * | sort -n

Page 11: System Administration – Part 2

Backing Up Files Using tar

tar – backup and restore files (tape archive, but other devices are OK too)

Example: # cd /home

# tar –cvf /dev/rdsk/f0q18dt ./rick

-c creates a new archive

-v displays the progress of the backup (verbose mode)

-f use the specified backup device

The files being backed up are specified using a relative pathname

so they can be restored in a different directory if needed.

Page 12: System Administration – Part 2

Restoring Files Using tar

Use the –t option to display the table of contents. Use –x to restore the files. Example: Create an incremental backup and then restore it.

# tar –cvf /dev/rct0 `find /home/rick –newer .lt –print`# touch .lt# tar –tvf /dev/rct0rw-r--r-- 203/50 470 Jun 4 09:35 2010 ./gradesrwxr-xr-x 203/50 470 Jun 4 10:46 2010 ./test.shrwxr-xr-x 203/50 470 Jun 3 02:35 2010 ./a.out# tar –xvf /dev/rct0x /home/rick/grades 169 bytes, 1 tape blocksx /home/rick/test.sh 4855 bytes, 10 tape blocksx /home/rick/a.out 7505 bytes, 15 tape blocks