Managing File Systems

Checking File System Status

The df Utility

Without arguments df will summarize the whole system

[pattyo@ponto /dev]$ df
Filesystem      1k-blocks      Used Available Use% Mounted on
/dev/sda7       101089     62455     33415  65% /
/dev/sda1       3636852   1664948   1787160  48% /usr
/dev/sda5       248895     27357    208688  12% /var
/dev/sdb1       991620       380    940868   0% /tmp
/dev/sdb3       900412     49772    804900   6% /home

You can also specify the filesystem

$ df .
Filesystem      1k-blocks      Used Available Use% Mounted on
/dev/sda7       101089     62455     33415  65% /

$ df /var
Filesystem      1k-blocks      Used Available Use% Mounted on
/dev/sda5       248895     27357    208688  12% /var

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       3.6G  3.2G  204M  95% /home

$ df -T
Filesystem    Type   1k-blocks      Used Available Use% Mounted on
/dev/hda5     ext2     2743460     42744   2561356   2% /home

The du utility

To summarize a directory structure or filesystem
# du -s /var

30577   /var
To get the contents and size of each subdirectory
# du /var

12      /var/lost+found
15954   /var/lib/rpm
2       /var/lib/games
2       /var/lib/xkb
235     /var/lib/dosemu
1       /var/lib/nfs/sm
....
1       /var/lib/ldap
19834   /var/lib
1       /var/log/uucp
6178    /var/log
1       /var/cache
6       /var/db
1       /var/local
1       /var/lock/subsys
2       /var/lock/console
4       /var/lock/samba
9       /var/lock
...
1       /var/catman/local/catn
27      /var/catman/local
97      /var/catman
1       /var/yp/binding
3       /var/yp
26249   /var

Freeing Space in a File System

Identifying core files Identifying large files with find
# find /home -size +10240k -exec ls -l {} \;
The file command

Creating New File Systems

Steps to install a new disk and the commands used

Exercise: Practise filesystem skills on the floppy drive

Filesystem and Journaling

Why use journaling?

How does journaling work? Implementations vary What happens when there is a crash? fsck Types of Journalled Filesystems
ext3
Creating a ext3 filesystem Upgrading an existing ext2 filesystem to ext3 use tunefs Mounting ext3 filesystem
mount -t ext3 /dev/xxx /mount_dir

* A cleanly unmounted ext3 filesystem can be remounted as ext2  without any other commands.
* Don't forget to update /etc/fstab with new filesystem type!

Mounting and Unmounting File Systems

The mount command

The umount command

Automating File System Mounting

The /etc/fstab configuration file

Key Settings for the Options Field

 
async Specifies that all reads and writes to the file system should be asynchronous, ie, buffered in memory to improve access speed.
auto Specifies that the file system should be automatically mounted at boot time or when the mount command is used with the -a option.
dev Designates the file system as a special device in the ./dev directory (block or character).
exec  Permits execution of binaries stored on file system.
noauto Can only be mounted explicitly, ie, the -a option will not cause the file system to  be mounted.
noexec Do not allow execution of any binaries on the mounted file system. Useful for a server's file system containing binaries for architectures other then its own.
nouser Only root can mount the file system.
ro Mount the file system read-only.
rw Mount the file system read-write.
suid Allows special user ID permissions to b used on this file system.
user Allow an ordinary user to mount the file system, ie, floppy or CDROM.
owner Owner is similar to user, with the restriction that the user must be the owner. e.g. for /dev/fd if a login script makes the console user owner of this device.
users Same as user option,  except any user can unmount the device.
defaults  Use default options: rw, suid, dev, exec, auto, nouser, and async.

Additional Points about the Options Field

The loopback block device Example:  initrd * You can use `uname -r` to find the running kernel's version.
# cp /boot/initrd-x.y.z.img /tmp
# mkdir /tmp/image
 
  • uncompress/unzip the image file
  •    

    # cat /tmp/initrd-x.y.z.img | gunzip > /tmp/initrd.img
     

  • mount the uncompressed image file with the loop option
  •  

    # mount -o loop /tmp/initrd.img /tmp/image
    # cd /tmp/image

    # ls -l
    total 6
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 bin
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 dev
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 etc
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 lib
    -rwxr-xr-x    1 root     root    441 Oct 31 12:26 linuxrc
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 loopfs
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 proc
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 sbin
    drwxr-xr-x    2 root     root   1024 Oct 31 12:26 sysroot

    File System Types Supported by Linux

     
    ext2 The native Linux file system type.
    msdos File system used by DOS and older Windows systems. This is also called the FAT file system.
    hpfs THe High Performance file system used by OS/2.
    iso9660 File system used on CD-ROMs.
    nfs The Network File system, used to allow networked computers to access remote hard disks as part of a local directory structure.
    smbfs File system used to mount SMB network devices such as networked Windows computers. This FS is part of the Samba suite.
    vfat File system used by Windows 98; also known as FAT32 file system. Provides long filename support.
    ntfs File system used  by Windows NT. 
    sysv A standard UNIX System V file system.
    ext3 New Journaled filesytem provided with RedHat 7.2
    Reiserfs  Journaled filesystem
    ufs A UNIX file system type used by Solaris.
    xfs High performance journaled file system. 

    The /proc Filesystem

    Interesting files in the /proc filesystem: Modifying information in /proc Why do you think the files are listed as being of zero length in /proc?
    You can get detailed information about processes KDE Control Center
    $ kcontrol


    Swap Space

    Special file system type used by the Linux kernel for virtual memory

    Creating a Swap File

    When do you create a swap file? Exercise      $ ls -l /tmp/newswap
        -rw-r--r--  1 root root  2097152 Apr 15 10:37  /tmp/newswap
                                  ^^^^^^^
    # mkswap /tmp/newswap
    Setting up swapspace version 1, size = 2093056 bytes
     
  • Enable the swap space
  • # swapon /tmp/newswap

  • check to see if it worked
  • $ cat /proc/swaps
    Filename              Type      Size   Used Priority
    /dev/sdb5             partition 168640 35832 1
    /dev/sda5             partition 168640 35648 1
    /tmp/newswap          file      2040   0    -3
    ^^^^^^^^^^^^
    $ swapon -s

  • Disable the swap file
  • # swapoff /tmp/newswap
    $ swapon -s
    Filename   Type  Size Used Priority
    /dev/sdb5               partition 168640 35832 1
    /dev/sda5               partition 168640 35648 1
     

  • To have this swap file active after a reboot you would add it to your /etc/fstab file
  • /path-to-swap/swapfile swap swap defaults 0 0

    Managing Swap Space

    Use the swapon or free command to view status of swap space (or virtual memory)

    $ swapon -s
    Filename    Type      Size   Used  Priority
    /dev/sdb5   partition 168640 42524 1
    /dev/sda5   partition 168640 0     1

    $ free
            total       used       free     shared   buffers     cached
    Mem:        158928     151392       7536        744       4852      80432
    -/+ buffers/cache:      66108      92820
    Swap:       337280      42524     294756

    $ cat /proc/swaps
    Filename   Type      Size  Used   Priority
    /dev/sdb5  partition 168640 42524 1
    /dev/sda5  partition 168640 0     1

    $ cat /proc/meminfo | head -3
            total:    used:    free:     shared: buffers:  cached:
    Mem:  162742272 155033600  7708672   761856  4972544 109076480
    Swap: 345374720 43544576 301830144

    Use the vmstat command to see detailed information about how swap space is used

    Straight out of the man page:

    FIELD DESCRIPTIONS
       Procs
           r: The number of processes waiting for run time.
           b: The number of processes in uninterruptable sleep.
           w: The number of processes swapped out but otherwise runnable.  This
              field is calculated, but Linux never desperation swaps.

       Memory
           swpd: the amount of virtual memory used (kB).
           free: the amount of idle memory (kB).
           buff: the amount of memory used as buffers (kB).
           cache: amount of memory cached for frequently used file structures, etc

       Swap
           si: Amount of memory swapped in from disk (kB/s).
           so: Amount of memory swapped to disk (kB/s).

       IO
           bi: Blocks sent to a block device (blocks/s).
           bo: Blocks received from a block device (blocks/s).

       System
           in: The number of interrupts per second, including the clock.
           cs: The number of context switches per second.

       CPU
           These are percentages of total CPU time.
           us: user time
           sy: system time
           id: idle time

    Reasons for Monitoring Swap Space

    Quotas

    # rpm -q quota
    # mount -o remount /home
    # cd /home
    # touch quota.group; chmod 600 quota.group
    # edquota -g users
    # reboot
    # edquota -g users
    Quotas for group users:
    /dev/hda6: blocks in use: 55, limits (soft = 512000, hard = 0)
    inodes in use: 200, limits (soft = 0, hard = 0)
    # edquota -t
    # edquota -u joe
    # edquota -p joe `awk -F: '$3 > 499 {print $1}' /etc/passwd`
    # quotacheck /home
    # quotaon /home
    # quotaoff /home

    File Attributes Review

    setuid and setgid bits setuid   ---s--x--x    1 root  root  80764 Jul 23 2001 /usr/bin/sudo
        ^^^

    setgid

    The Infamous Sticky Bit
    Files

    Changing Ownership and Group

    chown
    # chown someuser /home/someuser
    chgrp Change both at the same time Recursive Changes