Sie sind auf Seite 1von 64

Linux File system

Linux File system


Super block: The superblock contains information about the filesystem as a whole, such as its size Inode block: Contains all information about a file, except its name. Also includes the number for data blocks for that block. Data block: Used to store data in the file. Directory block: A directory entry consists of a filename and the number of the inode which represents the file. Indirection block: These dynamically allocated blocks are indirect blocks; the name indicates that in order to find the data block, one has to find its number in the indirect block first.

Directories
/
etc dev home boot
/ /etc /boot /dev /usr /home /var

bin

usr

lib

- first of mount point in linux - keep linux default configuration - keep important linux booting files - keep all device files - keep all user binary and X library - keep user home directory - keeping mail, log file and printer spooling

Directories
Directory Used to organize other files into a logical tree structure Absolute pathname Pathname from the root directory to a certain file or directory Root The top level directory

Referred to using the / character

Directories
~ metacharacter Can be used to refer to the current users home directory Can be used to specify another users home directory by appending a username at the end of the ~ metacharacter Relative pathname Pathname of a target directory relative to your current directory in the tree

Shells
Shell accepts commands, interprets them and pass them to kernel.

bash Most commonly used shell. csh Syntax is very familiar to the C- proramming language ksh korn shell tcsh

Linux Basics
Navigation and searching

Navigation
ls Lists the entries of a directory ls a lists all, including system files. mkdir cd PATH
cd takes the user to its home

pwd cp file 1 file2

Navigation
mv file1 file2 moves files or rename file rm file removes a file rmdir dir removes a directory cat file prints the contents whoami man k help or --help

File types
Text files Store information in a readable text format Binary data files Store information associated with executable programs Executable program files Directory files

File types
Linked files Associated with another file Special device files Represent system devices Named pipes Identify channel that passes information between processes Socket files Allow a process on another computer to write to a local file

Displaying content of a text file


Log files File that contains past system event cat command tac command Linux command that displays a file to the screen beginning with the last line of the file and ending with the first line of the file

Displaying content of a text file


head command
By default, displays the first 10 lines (including blank lines) of a text file to the terminal screen Can also take a numeric option specifying a different number of lines to display

tail command
By default, displays the last 10 lines (including blank lines) of a text file to the terminal screen Can also take a numeric option specifying a different number of lines to display

Displaying content of a text file


more command less command
Displays a text file page-by-page on the terminal Better than more Exit with q

The more and less commands can also be used in conjunction with the output of other commands
If output is too large to fit on terminal screen, use | metacharacter, e.g. ls -l | more

Searching files
updatedb locate file find name file* find name * size +500k grep string file ls grep|new grep b.*g file

Searching files
which command Command used to locate files that exist within directories listed in the PATH variable PATH variable Lists directories on system where executable files are located Allows executable files to be run without specifying absolute or relative path

Manipulation
vi file opens a file in current directory for editing. commands:
:q :q! :w :wq / -searching string Select some text to copy it, and right click pastes it.

Manipulation
emacs Emacs is more than "just an editor" -- it provides a fully integrated user environment offering the sort of facilities outlined below.
Issue shell comands Read and send mail Read news Access the internet Write and test programs Maintain a calendar Play a game!

nano gedit

Linux Devices /etc

The /dev Directory


Device file
File representing a device Typically found in the /dev directory

Character devices
Transfer data to and from the system one data bit at a time

Block devices
Transfer to and from the system in chunks of many bits by caching the information in RAM Represented by block device files Fast data transfer

The /dev Directory


Device File /dev/fd0 /dev/fd1 /dev/hda1 Description First floppy disk on the system Second floppy disk on the system First primary partition on the first IDE hard disk drive (primary master) Block or Character Block Block Block

/dev/hdb1
/dev/hdc1 /dev/hdd1 /dev/sda1 /dev/cdrom

First primary partition on the second IDE hard disk drive (primary slave)
First primary partition on the third IDE hard disk drive (secondary master) First primary partition on the fourth IDE hard disk drive (secondary slave) First primary partition on the first SCSI hard disk drive Default CD-ROM/DVD-ROM drive

Block
Block Block Block Block

Common device files

The /dev Directory


Major number
Used by the kernel to identify what device driver to call to interact properly with a given category of hardware

Minor number
Used by the kernel to identify which specific hardware device, within a given category, to use a driver to communicate with

The /dev Directory


Device file type (block or character), major number, and minor number make up a device files unique characteristics
lrwxrwxrwx brw-rw---brw-rw---1 root 1 root 1 root root disk disk 3, 3, 8 May 2 11:33 cdrom -> /dev/hdc 0 Feb 23 2004 hda 1 Feb 23 2004 hda1

mknod command
Can be used to re-create a corrupted device file Must know file type, major, and minor numbers

Filesystem Types
Filesystem Description bfs Boot File Systema small bootable filesystem used to hold the files necessary for system startup; it is commonly used on UNIX systems Compact disc filesystemused to view all tracks and data on a CD-ROM as normal files Second extended filesystemcurrently the most common filesystem used on Linux, it supports Access Control Lists (individual user permissions). It retains its name from being the new version of the original extended filesystem, based on the Minix filesystem Third extended filesystem; a variation on ext2 that allows for journaling and thus has a faster startup and recovery time

cdfs ext2

ext3

Common Linux filesystems

Filesystem Types
Filesystem hfs Description Hierarchical File Systema filesystem native to Apple Macintosh computers

hpfs

iso9660

minix msdos vfat

High Performance File Systeman IBM-proprietary OS/2 filesystem that provides long file name support and is optimized to manipulate data on large disk volumes The CD-ROM filesystemoriginated from the International Standards Organization recommendation 9660 and used to access data stored on CD-ROMs The MINIX filesystemfilesystem used by Linus Torvalds in the early days of Linux development
The DOS FAT filesystem The DOS FAT filesystem with long file name support

Common Linux filesystems

Filesystem Types
Filesystem ntfs Description New Technology File Systema Microsoft-proprietary filesystem developed for its NT4 and Windows 2000 operating systems, currently available as a read-only filesystem under Linux The REISERFS filesystema journaling filesystem similar to ext3 more suited for use with databases The Universal Disk Format filesystemA filesystem used by software systems that write to a CD-R, CD-RW or DVD

reiserfs udf

vxfs

The Veritas filesystema journaling filesystem that offers large file support, supports Access Control Lists (individual user permissions), and is commonly used by major versions of UNIX

Common Linux filesystems

Mounting
Mounting
Making a device accessible to users via the logical directory tree Term originated in the 1960s, when information was stored on large tape reels that had to be mounted on computers to make the data available

Mount point
Directory in a file structure to which a device is attached
Any existing directory can be a mount point

Mounting
/ mnt root data etc home

floppy

cdrom

mary

bob

sue

The filesystem prior to mounting

Mounting
/ mnt root data etc home

mary

bob

sue

/mnt

The directory structure after mounting a floppy device

Mounting
/ mnt root data etc home

mary cdrom

bob

sue

floppy

/mnt/floppy

The directory structure after mounting a floppy device correctly

Mounting
When the Linux filesystem is first turned on, a filesystem present on the hard drive is mounted to the / directory Root filesystem
Filesystem that contains files that start up the operating system Should have enough free space to prevent errors and slow performance

Mounting
mount command
Used to mount devices to mount point directories With no options or arguments, lists currently mounted filesystems

umount command
Used to unmount devices from mount point directories

Working with Floppy Disks


When transferring small amounts of information from computer to computer, it is commonplace to use floppy disk removable media to store the files
However, floppy disks must be prepared before they are used in Linux Each disk device must be formatted with a filesystem prior to being used to store files

Working with Floppy Disks


mkfs (make filesystem) command
Used to format a disk with a filesystem t option: Specifies filesystem type
Default is ext2 filesystem

To mount or unmount floppies, must ensure that no user is currently using the mount point directory

Working with Floppy Disks


fuser command
With the u option, lists users using a directory

Most (almost all) floppy disks today come preformatted with the DOS FAT filesystem
Will work just fine for Linux when mounted correctly (Work on Macs as well)

Working with Floppy Disks


Command mkfs mkfs.msdos mkdosfs mkfs.vfat mkfs.ext2 mke2fs mkfs.ext3 mke2fs -j mkisofs mkfs.reiserfs mkreiserfs Description Used to create filesystems of most types Used to create a DOS FAT filesystem

Used to create an ext2 filesystem Used to create an ext3 filesystem (j = journaling) Used to create a CD-ROM filesystem Used to create a REISERFS filesystem

Commands used to create filesystems

Working with Floppy Disks


/etc/fstab file
Used to mount devices at boot time Also consulted when users do not specify enough mount command arguments Six fields: Device to mount, mount point, type, mount options, dump#, fsck#

Working with Floppy Disks


Command mount mount -t <type> <device> <mount point> Description Displays mounted filesystems Mounts a <device> of a certain <type> to a <mount point> directory Displays the users using a particular directory

fuser -u <directory>

umount <mount point> or umount <device>

Unmounts a <device> from its <mount point> directory

Useful commands when mounting and unmounting filesystems

Working with Floppy Disks


Mounting a floppy device using a GUI environment

Working with Floppy Disks


Unmounting a floppy device in a GUI environment

Working with CD-ROMs


CD-ROMs are normally mounted as /dev/cdrom despite occupying one of the hard drive block device designations Typically use iso9660 filesystem type and are not writable
Mount with r (read-only) option

Cannot be ejected until properly unmounted

Working with CD-ROMs


Viewing the contents of a CD-ROM device in a GUI environment

Working with CD-ROMs


Unmounting a CD-ROM device in a GUI environment

Working with Hard Disks


IDE hard disk drives attach to the mainboard with an IDE cable and must be configured on one of four configurations, each of which has a different device file:
Primary master (/dev/hda) Primary slave (/dev/hdb) Secondary master (/dev/hdc) Secondary slave (/dev/hdd)

Working with Hard Disks


SCSI hard disks well-suited to Linux servers
Faster access speed Multiple hard drives can be attached to a controller

Associated with different device files


First SCSI HDD (/dev/sda) Second SCSI HDD (/dev/sdb) Third SCSI HDD (/dev/sdc) and so on.

Hard Disk Partitioning


As disk size increases, organization becomes more difficult and chance of error increases Partition
A physical division of a hard disk drive Can have its own filesystem

Hard Disk Partitioning


It is good practice to use more than just two partitions
Segregates different types of data
Allows for use of multiple filesystem types on one HDD

Reduces the chance the filesystem corruption will render a system unusable Speeds up access to stored data by keeping filesystems as small as possible

Hard Disk Partitioning


Tracks
Area on a hard disk that form a concentric circle of sectors

Sector
Smallest unit of data storage on a hard disk

Block
Unit of data commonly used by filesystem commands

Hard Disk Partitioning


Cylinder
Series of tracks on a hard disk that are written to simultaneously by the magnetic heads in a hard disk drive Partition definitions stored in first readable sector of the hard disk
Master Boot Record (MBR) or master boot block (MBB)

Hard Disk Partitioning


The physical areas of a hard drive

Track Sector

Block

Hard Disk Partitioning


Partition 1st primary partition IDE Device Name (assuming /dev/hda1) /dev/hda1 SCSI Device Name (assuming /dev/sda1) /dev/sda1

2nd primary partition


3rd primary partition

/dev/hda2
/dev/hda3

/dev/sda2
/dev/sda3

4th primary partition


1st logical drive in the extended partition 2nd logical drive in the extended partition 3rd logical drive in the extended partition 4th logical drive in the extended partition 5th logical drive in the extended partition nth logical drive in the extended partition

/dev/hda4
/dev/hda5 /dev/hda6 /dev/hda7 /dev/hda8 /dev/hda9 /dev/hdan

/dev/sda4
/dev/sda5 /dev/sda6 /dev/sda7 /dev/sda8 /dev/sda9 /dev/sdan

Common hard disk partition device files for /dev/hda and /dev/sda

Hard Disk Partitioning


hda1
primary Free space swap 1GB / (Linux) 9GB hda5 + free space = extended

hda2

hda5
logical

MBR
(MBB)

A sample Linux partitioning strategy

Hard Disk Partitioning


hda1
primary
C:\win98 4GB Free space Swap 1GB / (Linux) 9GB /home 5GB hda5 + hd6 + hd7 + free space= hda2 (extended)

hda5
logical

hda7
logical

hda6
logical

MBR
(MBB)

A sample dual-boot Linux partitioning strategy

Working with Hard Disk Partitions


Disk Druid is an easy-to-use partitioning tool used with Red Hat Linux, specifically designed for installation only fdisk command
Used to create partitions after installation Specify hard disk partition as an argument

Working with Hard Disk Partitions


tune2fs command
Create a journal file on the filesystem Convert ext2 to ext3

Edit /etc/fstab file to allow system to mount new filesystems automatically at boot time

Monitoring Filesystems
Check mounted filesystems periodically
Errors Disk Space usage Inode usage

Disk Usage
Using more filesystems typically results in less hard disk space per filesystem
Errors when filesystems fill up with data
e.g., free space on / filesystem falls below 10%

df (disk free space) command


Monitor free space used by mounted filesystems h option: More user friendly

Disk Usage
du (directory usage) command
View size of a directory and contents in Kilobytes s option: Summarizes output

dumpe2fs command
View total number of inodes and free inodes for ext2 or ext3 filesystem Use h option

Filesystem corruption

Checking Filesystems for Errors

Errors in a filesystem structure that prevent the retrieval of stored data Commonly occurs due to improper system shutdown

Syncing
Process of writing data stored in RAM to the HDD

Bad blocks
Unusable areas of a disk Cannot hold a magnetic charge

Checking Filesystems for Errors


fsck (filesystem check) command
Check a filesystem for errors Filesystem must be unmounted f option used to perform full check

e2fsck command
Check ext2 and ext3 filesystems

reiserfsck
Check reiserfs filesystems

Checking Filesystems for Errors Option Description


-f -a -A -Cf -AR -V Performs a full filesystem check Allows fsck to repair any errors automatically Checks all filesystems in /etc/fstab that have a 1 or 2 in the sixth field Performs a full filesystem check and displays a progress line Checks all filesystems in /etc/fstab that have a 1 or 2 in the sixth but skips field the / filesystem Displays verbose output

Common options to the fsck command

Hard Disk Quotas


If several users on a system, must be enough hard disk space for each users files Hard disk quotas
User limits on filesystem usage Restrict number of files/directories or total disk space usage

Soft limits
Limit imposed that can be exceeded for a certain period of time

Hard limit
Limit imposed that cannot be exceeded

Hard Disk Quotas (continued)


quotaon and quotaoff commands
Toggle quotas on and off

edquota command
Edit user quotas

repquota command
Report user quotas

quota command
Allows regular users to view quotas and current usage

Checking Filesystems for Errors Option Description


-f -a -A -Cf -AR -V Performs a full filesystem check Allows fsck to repair any errors automatically Checks all filesystems in /etc/fstab that have a 1 or 2 in the sixth field Performs a full filesystem check and displays a progress line Checks all filesystems in /etc/fstab that have a 1 or 2 in the sixth but skips field the / filesystem Displays verbose output

Common options to the fsck command

Das könnte Ihnen auch gefallen