LPI 101 Ch12 File Systems

  • View
    219

  • Download
    0

Embed Size (px)

Text of LPI 101 Ch12 File Systems

  • 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, l