Download pdf - LPI 101 Ch12 File Systems

Transcript
  • 8/9/2019 LPI 101 Ch12 File Systems

    1/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Chapter 12

    File Systems

  • 8/9/2019 LPI 101 Ch12 File Systems

    2/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Objectives

    To understand the Linux file system concepts

    Define and identify different file system structures

    and types

    Describe and mount file systems including MS

    Windows partitions

    Define and manage disk quotas

    Create different file systems

    Describe the /proc file system

  • 8/9/2019 LPI 101 Ch12 File Systems

    3/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System Structure

    Almost everything in Linux is treated as a file, including

    commands, most hardware devices, processes, and network

    connections

    File systems on device must be mount into tree structurebefore accessing :

    A diskpartition can be mounted onto any directory

    Directory, in this case, is referred to as mount point

    File permission used to control user access to the systems

  • 8/9/2019 LPI 101 Ch12 File Systems

    4/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System Structure

    File system defines how a disk is structured, and different

    disks can be formatted with different file systems. However,

    all file systems have a special blockthat contains disk

    information

    The superblock contains information about the file system,

    including the locations of its inode tables, free block list, and

    root directory.

    In general, if the superblock becomes corrupt, the file systemwill become unusable. Therefore, extra copies of the

    superblock are scattered in predetermined location across the

    file system, Linux do this automatically

  • 8/9/2019 LPI 101 Ch12 File Systems

    5/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System Structure

    Under UNIX, all information about a file (meta-data) is

    stored in an its inode except the file's name, including :

    Type

    Ownership and associated group Permissions

    Time stamps: mtime (modification time), ctime (inode

    change time), atime (access time)

    Link (hard) count

    Pointers to direct and indirect data blocks (where the

    contents are stored)

  • 8/9/2019 LPI 101 Ch12 File Systems

    6/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System Structure

    Specific file systems may include other information such as

    the ext2 attributes (see the lsatter and chatter man pages for

    details) or access control lists (ACLs) and extended attributes

    (EAs).

  • 8/9/2019 LPI 101 Ch12 File Systems

    7/37

  • 8/9/2019 LPI 101 Ch12 File Systems

    8/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Making a File System

    The mkfs command is used to create file systems on a disk or

    disk partition

    When creating a new file system, you will need to specify the

    raw disk device, disk size as well as some other parameters,mkfs creates the superblock and inode list. Keep in mind that

    the inode list isfixedin size and cannot be extendedon many

    file system types

    Examples:# mkfs -t ext2 /dev/hda5 102400

    # mkfs -t msdos /dev/fd0

  • 8/9/2019 LPI 101 Ch12 File Systems

    9/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Making a File System

    Use the default number of inodes unless you expect to create a

    lot of very small files or a few very big ones. A larger block

    size (2,048) will give better disk performance but will waste

    more space due to partially filled blocks at the end of files.

    Smaller block sizes (512) use less space, but disk performance

    is worse

    You do not have to make the file system the same size as the

    disk or partition, but by not doing so, the unused space will bewasted

  • 8/9/2019 LPI 101 Ch12 File Systems

    10/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Making a File System

    Options for mkfs Command:

    -c Check the device for bad blocks (mke2fs and mkdosfs)

    -L label Set the volume label for the files system (mke2fs)

    -n label Set the 11-character volume label for the file system(mke2fs)

    -t fstype Specifies the type of file system to be built. If notspecified, the default file system type (currently ext2)

    is used

    -v Verbose mode

  • 8/9/2019 LPI 101 Ch12 File Systems

    11/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Mounting a File System

    In Linux, file systems must be mounted in order to access

    them. Mounting can occur via the command line or by

    including an entry in /etc/fstab

  • 8/9/2019 LPI 101 Ch12 File Systems

    12/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Command Line Mounting

    Command format:

    mount t o

    Examples:

    # mount -t ext2 /dev/fd0 /nmt/floppy# mount -t iso9660 /dev/cdrom /mnt/cdrom

    # mount -t nfs 10.0.1.1:/usr/local/stuff

    /usr/local/stuff

    ( Refer to mount man pages for more details )

  • 8/9/2019 LPI 101 Ch12 File Systems

    13/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Mounting with /etc/fstab

    The /etc/fstab file is read at boot time. Any file systems listed

    within this file are loaded by default. Each line has the form:

    LABEL=/ / ext3 defaults 1 1

    /dev/hda1 /windows vfat defaults 0 0

    /dev/fd0 /mnt/floppy msdos noauto 0 0/dev/cdrom /mnt/cdrom iso9660 noauto,ro 0 0

    none /proc proc defaults 0 0

    /dev/hda6 /swap swap defaults 0 0

  • 8/9/2019 LPI 101 Ch12 File Systems

    14/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Mounting a File System

    The commands mount, cat /etc/mtab ,and cat /proc/mounts will

    display the file systems that arecurrently mounted

  • 8/9/2019 LPI 101 Ch12 File Systems

    15/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Unmounting a File System

    To unmount a file system, simply use the umount command

    in format:

    umount

    Or :umount

    Example:

    # umount /mnt/cdrom

  • 8/9/2019 LPI 101 Ch12 File Systems

    16/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Two Way To Fix Device busy Error

    To list the PIDs first:

    fuser -m

    And then: stop processes with kill command (safely)

    Stop all processes that are keeping a file system busy, use :fuser k -m

  • 8/9/2019 LPI 101 Ch12 File Systems

    17/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Unmounting a File System

    The eject command will attempt to unmount the file systemand then unmount the CD-ROM tray

    Be sure to unmount a floppy drive prior to removal of the

    floppy disk. Serious file system errors, and loss of data tothe disk can occur if it is not unmounted

    File systems must be unmounted depth first

  • 8/9/2019 LPI 101 Ch12 File Systems

    18/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Mounting Microsoft (MS-DOS) Partitions

    Linux has the ability to mount MS-DOS and MS Windows9x partitions. This allows MS files to be read and written to

    while in the Linux environment

    The mount command and /etc/fstab allow two MS-DOS filesystem type options: msdos and vfat. It is safest to use the

    msdos option when mounting a true MS-DOS partition, and

    vfat when mounting an MS Windows partition

  • 8/9/2019 LPI 101 Ch12 File Systems

    19/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Checking File Systems

    Power failures, failing hardware and operator error candamage the file system.

    e2fsck Check a Linux ext2 or ext3 file system

    tune2fs Adjusts file system parameters such as the maximal mountcount, maximum time between checks, and the number ofblocks reserved for root.

    It can also add a journal to an existing ext2 partition tomake it an ext3 partition:

    tune2fs -j /dev/hda1

    debugfs A fairly dangerous file system debugger

    ext2ed An editor for the second extended file system

    dumpe2fs Shows information about an ext2 or ext3 file system mostly from the superblock

  • 8/9/2019 LPI 101 Ch12 File Systems

    20/37

  • 8/9/2019 LPI 101 Ch12 File Systems

    21/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Managing File Systems

    Kernel File Cache

  • 8/9/2019 LPI 101 Ch12 File Systems

    22/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Kernel File Cache

    The Linux kernel caches its blockdata in memory. Thisimproves performance by reducing data accesses to disk, as

    the kernel will frequently find the data it wants in the cache

    in memory. The sync command is used to manually flush

    the cache to disk.

    A very old method of closing down Linux system was to

    issue the commands:

    $ sync; sync ; halt The newer journaling file systems, such as ext3fs, maintain

    file system integrity even if the system crashes. Journaling

    file systems recover automatically on mount

  • 8/9/2019 LPI 101 Ch12 File Systems

    23/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    The lost+found Directory

    This directory contains links to lost files in a corrupted filesystem

    The file system check programs, such as e2fsck, log entries

    into the lost and found directory. Lost files stored in

    lost+found directory with thefilename stored as an inode

    number. To identify the types of recovered files, use the file,

    more, or less command

  • 8/9/2019 LPI 101 Ch12 File Systems

    24/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Corrupt File Systems

    If a system crashes or is shutdown improperly, you will needto repair the file system, fsck and e2fsck is best suited for

    repairing ext2 partitions. Repaired file systems are modified

    to return everything to a consistent state

    Some damaged files can be completely lost and the data

    unrecoverable. Recoverable files or partial files will be

    placed in the lost+found directory

  • 8/9/2019 LPI 101 Ch12 File Systems

    25/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Utilities

    Free disk : to find out how much free disk space is availableon a mounted file system use df command

    Options: -k Reports the size in KB (default)

    -m Reports the size in MB-t Selects a specific file system type

    -a Shows all mount points

  • 8/9/2019 LPI 101 Ch12 File Systems

    26/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Utilities

    DiskUsage :Use du command to list only directory size

    Options: -s Summarize for named files

    -c Compute a grand total

    -h Human readable format-a Detail all files

  • 8/9/2019 LPI 101 Ch12 File Systems

    27/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Utilities

    Quota :

    The quota command checks a user's disk usage and limit.

    Some Linux administrators choose not to enable quota

    checking; it is compiled into the kerneland activatedby the

    system administrator

  • 8/9/2019 LPI 101 Ch12 File Systems

    28/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    User Disk Quota

    The idea behind quota is to make users stay within their disk

    consumption limit. The quota system on Linux allows an

    administrator to set the number of inodes a user or a group of

    users may possess and the number of disk blocks that may be

    allocated to a user or a group of users

    Quota are not always appropriate for dedicated servers and

    single user workstations. Quota are especially useful for

    multi-user machines such as ISP style servers, MAILservers,

  • 8/9/2019 LPI 101 Ch12 File Systems

    29/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    User Disk Quota

    Quota have two levels: "soft" and "hard" :

    The soft limit can be exceeded, but only for a certain time;

    failure to reduce the allocated space before the timer

    expires will trigger the quota

    Hard limits apply immediately.Users exceeding their quota

    on a disk will be advised that they have run out of space (

    maybe confused with afull disk)

  • 8/9/2019 LPI 101 Ch12 File Systems

    30/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Getting a Report on a User's Quota Status

    The quota command displays disk usage and limits for a givenuser. By default, quota will display the current user's diskquota information. If logged in as root, use the commandquota -u to view a particular user's disk quota

    information

  • 8/9/2019 LPI 101 Ch12 File Systems

    31/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Turning on Quota at Boot Time

    Add or uncomment these lines in /etc/rc.d/rc.sysinit :

    if [ -x /usr/sbin/quotacheck ]; then

    echo "Checking quota. This may take some time.

    /usr/sbin/quotacheck -avug echo Done.fi

    if [ -x /usr/sbin/quotaon ]; then

    echo Turning on quota.

    /usr/sbin/quotaon -auvg

    fi

  • 8/9/2019 LPI 101 Ch12 File Systems

    32/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Turning on Quota at Boot Time

    Add "usrquota" to the fourth field containing the worddefaults (man fstab for details):

    /dev/hda1 / ext3 defaults 1 1

    /dev/hda2 /usr ext3 defaults,usrquota 1 1

    If group quota support on a file system is required, replace

    "usrquota" with "grpquota"

  • 8/9/2019 LPI 101 Ch12 File Systems

    33/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Maintaining Quota

    The system administrator will need to create two quotarecord files, quota.user and quota.group in the top-level

    directory of the file system. They should be owned by root,

    and permissions set to read-write for root only

  • 8/9/2019 LPI 101 Ch12 File Systems

    34/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Maintaining Quota

    As root, go to the partition where quota should be enabled.Use these commands:

    quotaon, quotaoff : turn the file system quota on and off.

    edquota u : is the quota editor. One or moreusers or groups may be specified on the command line.

    Only root may edit quota

  • 8/9/2019 LPI 101 Ch12 File Systems

    35/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    The /proc File System

    The /proc file system is a virtual file system (no actual diskspace is used) that contains very useful information about the

    status of the system

    The files and directories under /proc change over time as the

    kernel provides system statistics and process information.

    Commands such as ps, top, dmesg, use /proc to obtain their

    information

  • 8/9/2019 LPI 101 Ch12 File Systems

    36/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Summary

    To understand the Linux file system concepts

    Define and identify different file system structures and types

    Describe and mount file systems including MS Windows

    partitions Define and manage disk quotas

    Create different file systems

    Describe the /proc file system

  • 8/9/2019 LPI 101 Ch12 File Systems

    37/37

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Free-Radius

    Openldap Qmail-ldap

    Samba

    Purefpt

    Bind hay DJB