Top

A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded

FILESYSTEMS

Using

  • Virtual filesystems
    sysfs

    A virtual file system, based on ramfs. It provides a means of exporting kernel device and driver structures to userspace. It is always compiled into the kernel.

    For each kobject registered with the kernel a directory is created in sysfs. Mounted on /sys.

    If not mounted automatically on /sys at boot can do so by

     # mount -t sysfs sysfs /sys 
     $ tree -d /sys -L 1
     /sys
     |-- block
     |-- bus
     |-- class
     |-- dev
     .....
    
    
    procfs

    A pseudo filesystem that provides run time process and general information on installed devices. Mounted on /proc.

    If not mounted automatically on /proc at boot can do so by issuing the following command

      # mount -t proc proc /proc
    
    

    or via /etc/fstab file

      # <file system> <mount point>   <type>  <options>       <dump>  <pass>
      proc            /proc           proc    defaults        0       0
      .....
    
    
    devfs

    A filesystem of device or special files - mounted on /dev.

    These files provide an interface to device drivers - appearing as ordinary files under /dev. This allows software to interface with the driver using standard input and output system calls.

    There are two standard types of device files - character and block. As the names suggest, data is read/written to the device a character at a time for character devices (e.g. virtual terminals, serial modems - usually unbuffered) and as a block for block devices (e.g. CD-Roms, disks, memory). Block devices support random access to data, character devices do not.

    Pseudo devices. These are devices that are not associated with any physical device. Common pseudo devices include

    Pseudo device file Description
    /dev/null A dustbin, accepts all input, produces no output. Can use to zero/truncate files.
    /dev/full Always full device.
    /dev/loop A loop back device (block device).
    /dev/zero Outputs a continuous stream of NUL (zero value) bytes.
    /dev/random Outputs a variable-length stream of truly random numbers. (Blocking)
    /dev/urandom Outputs a variable-length stream of pseudo-random numbers. (Non-Blocking)
  • Filesystem system files

    A number of system files are used to hold filesystem configuration and status information.

    File Description
    /etc/fstab Contains static filesystem information. Used at boot to mount configured filesystems.
    /etc/mtab Built by initialisation scripts, can be dropped and symbolically linked to /proc/mounts.
    /proc/mounts Maintained by the kernel. The kernels view of what is mounted.
  • Filesystem table file
    /etc/fstab

    /etc/fstab format

    <file system> <mount point> <type> <options> <dump> <pass>
    
    Parameter Description
    <file system> Device file to mount - by name (/dev/sda1), or label, or UUID
    <mount point> Directory over which to mount
    <type> Filesystem type
    <options> Comma separated list of mount options
    <dump> 'dump' checks fstab to see which filesystems need to be dumped (backed up). Set to 0 or empty means do not backup
    <pass> Used by 'fsck -A', 1=check first, 2=check after '/' , 0=no check

    Example entries (NOT a 'real' system's) - /etc/fstab

    proc                         /proc           proc         defaults                     0       0
    UUID=89bbe552-b7f7528a81b4   /               ext3         relatime,errors=remount-ro   0       1
    /dev/sda8                    /home           ext3         relatime                     0       2
    LABEL=ubboot                 /boot           ext2         relatime                     0       2
    /dev/scd0                    /media/cdrom0   udf,iso9660  user,noauto,exec,utf8        0       0
    /dev/fd0                     /media/floppy0  auto         rw,user,noauto,exec,utf8     0       0
    /dev/hda7                    /               ext3         defaults                     1       1
    none                         /dev/pts        devpts       mode=0620                    0       0
    /dev/hda9                    /home           ext3         defaults                     1       2
    none                         /proc           proc         defaults                     0       0
    /dev/hda8                    swap            swap         defaults                     0       0
    none                         /mnt/cdrom      supermount   dev=/dev/hdc,fs=auto,ro,--,iocharset=iso8859-1,codepage=850,umask=0    0  0
    none                         /mnt/floppy     supermount   dev=/dev/fd0,fs=auto,--,iocharset=iso8859-1,sync,codepage=850,umask=0  0  0
    

    Common /etc/fstab mount options

    async               All I/O to the file system should be done asynchronously 
                        (sync synchronously).
    atime               Update inode access time for each access - default (noatime,
                        relatime).
    auto                Can be mounted with the 'mount -a' option (noauto cannot)
    defaults            Use default options: rw, suid, dev, exec, auto, nouser and
                        async.
    dev                 Interpret character or block special devices on the file
                        system (nodev do not interpret).
    exec                Permit execution of binaries (noexec denies).
    remount             Remount an already mounted fs, often used to change flags
                        on an fs i.e. ro ->rw.
    rw                  Read/write (ro read-only)
    suid                Allow set-user-identifier or set-group-identifier bits to
                        take effect (nosuid disallow).
    user                Allow a user to mount the file system (nouser forbid).
    users               Allow every user to mount and unmount the file system.
    usrquota            Allow user quotas.
    grpquota            Allow group quotas.
    

    These can also be used with the mount command's '-o' or '-O' <option list> flags.

  • Table of mounted filesystems
    /etc/mtab

    mtab format is similar to fstab and details mounted filesystems.

    Entries for Lubuntu on a laptop

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 13.04
    Release:    13.04
    Codename:   raring
    
    $ more /etc/mtab
    /dev/sda4 / ext4 rw,errors=remount-ro 0 0
    proc /proc proc rw,noexec,nosuid,nodev 0 0
    sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0
    none /sys/fs/cgroup tmpfs rw 0 0
    none /sys/fs/fuse/connections fusectl rw 0 0
    none /sys/kernel/debug debugfs rw 0 0
    none /sys/kernel/security securityfs rw 0 0
    udev /dev devtmpfs rw,mode=0755 0 0
    devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
    tmpfs /run tmpfs rw,noexec,nosuid,size=10%,mode=0755 0 0
    none /run/lock tmpfs rw,noexec,nosuid,nodev,size=5242880 0 0
    none /run/shm tmpfs rw,nosuid,nodev 0 0
    none /run/user tmpfs rw,noexec,nosuid,nodev,size=104857600,mode=0755 0 0
    /dev/sda1 /boot/efi vfat rw 0 0
    gvfsd-fuse /run/user/mark/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,user=mark 0 0
    

    Can be a symbolic link to '/proc/mounts'. If it is it could cause issues with recovery since it would report what the kernel sees not what should be mounted.

  • Kernel's view of mounted filesystems
    /proc/mounts
    $ more /proc/mounts
    rootfs / rootfs rw 0 0
    sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
    proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
    udev /dev devtmpfs rw,relatime,size=1795312k,nr_inodes=448828,mode=755 0 0
    devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
    tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=360972k,mode=755 0 0
    /dev/disk/by-uuid/89fa3458-e2a3-45bd-b246-fa5546ba2f5a / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0
    none /sys/fs/cgroup tmpfs rw,relatime,size=4k,mode=755 0 0
    none /sys/fs/fuse/connections fusectl rw,relatime 0 0
    none /sys/kernel/debug debugfs rw,relatime 0 0
    none /sys/kernel/security securityfs rw,relatime 0 0
    none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
    none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
    none /run/user tmpfs rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755 0 0
    /dev/sda1 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
    gvfsd-fuse /run/user/mark/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
    
  • Mount a filesystem
    /bin/mount

    Before a filesystem can be used it must be mounted on a mount-point (a directory). One does not really mount a device, one mounts a filesystem (of the given type) found on the device.

    When used with '-t' or '-O' greater control can be exercised over which filesystems to mount. The '-a' flag, usually given in a bootscript, causes all file systems mentioned in /etc/fstab to be mounted as indicated, except for those whose line contains the noauto keyword.

    Informational usage

    mount -V                 : print version
    mount -h                 : print this help
    mount                    : list mounted filesystems
    mount -l                 : idem, including volume labels
    

    Mounting usage

    mount [-t fstype] something somewhere
    
    mount -a [-t|-O] ...     : mount all stuff from /etc/fstab
    mount device             : mount device at the known place
    mount directory          : mount known device here
    mount -t type dev dir    : ordinary mount command
    

    Details found in '/etc/fstab' may be omitted.

    A device can be given by name, say /dev/hda1 or /dev/cdrom, or by label, using '-L' label or by uuid, using '-U' uuid .

    Other options

    [-nfFrsvw] [-o options list, .., ..] [-p passwdfd].
    
     -F       Fork, mount all filesystems simultaneously, done in undefined order so cannot use if 
              want to mount nested filesystems e.g. both /usr and /usr/spool. (Used with -a)
     -f       'fakes' mounting, useful with the -v flag to determine what the mount command is 
              trying to do. Can also be used to add entries for devices that were mounted.
     -n       Mount without writing in /etc/mtab.  Necessary when  e.g. /etc is on a readonly fs.
     -s       Tolerate sloppy mount options rather than failing. Not all fs support this option. 
              Exists for support of autofs-based automounter.
     -r       Mount the file system read-only. A synonym is '-o ro'
     -w       Mount the file system read/write. This is the default. A synonym is '-o rw'.
     -v       verbose
    

    When mounting a file system mentioned in '/etc/fstab', it suffices to give only the device or only the mount point.

    Mount all file systems listed in /etc/fstab except those of type msdos and ext

    # mount -a -t nomsdos,ext
    

    Prefixing a filesytem type with 'no' deselects it for mounting

    '-O' used in conjunction with '-a' can limit the set of filesystems to which the '-a' is applied. Similar to '-t' except it is useless unless used in conjunction with '-a'.

    Mounts all file systems in /etc/fstab except those which have the option '_netdev' specified

    # mount -a -O no_netdev
    

    '-O' used in conjunction with '-a' can limit the set of filesystems to which the '-a' is applied. Similar to '-t' except it does nothing unless used in conjunction with '-a'.

    '-O' differs from '-t' in that each option is matched exactly. A leading 'no' at the beginning of one option does not negate the rest. The '-t' and '-O' options are cumulative in effect'.

    Mount only ext2 filesystems in /etc/fstab that have the '_netdev' option specified

    # mount -a -t ext2 -O _netdev
    

    Mount ONLY ext3 filesystems in /etc/fstab that have 'relatime' set in options field

    # mount -a -t ext3 -O relatime
    

    Mount all filesystems in /etc/fstab EXCEPT ext3 that have 'norelatime' set in options field

    # mount -a -t noext3 -O norelatime
    

    Mount a windows floppy on /media/floppy directory

    # mount -t vfat /dev/fd0 /media/floppy
    

    Allow normal users to mount a cdrom

    # mount -t iso9660 /dev/scd0 /media/cdrom1 -o user,noauto
    

    Report all mounted filesystems

    $ mount
    /dev/sda4 on / type ext4 (rw,errors=remount-ro)
    proc on /proc type proc (rw,noexec,nosuid,nodev)
    sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
    .....
                                                    (or)
    $ mount -l
    /dev/sda4 on / type ext4 (rw,errors=remount-ro)
    proc on /proc type proc (rw,noexec,nosuid,nodev)
    sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
    ..... 
    

    Both commands read '/etc/mtab'.

  • Unmount a filesystem
    /bin/umount

    As with 'mount', when used with '-t' or '-O' greater control can be exercised over which filesystems to unmount.

    umount -h | -V
    umount -a [-d] [-f] [-r] [-n] [-v] [-t vfstypes] [-O opts]
    umount [-d] [-f] [-r] [-n] [-v] dir | device
    
    Options:
     -V                Print version and exit.
     -h                Print help message and exit.
     -v                Verbose mode.
     -n                Unmount without writing in /etc/mtab.
     -r                In case unmounting fails, try to remount read-only.
     -d                In case the unmounted device was a loop device, also 
                       free this loop device.
     -a                All of the file systems described in /etc/mtab are
                       unmounted.
     -t vfstype        Actions should only be taken on file systems of the 
                       specified type. More than one type may be specified in
                       a comma separated list.
     -O options        Actions should only be taken on file systems with the 
                       specified options in /etc/fstab.
     -f                Force unmount (in case of an unreachable NFS system)
     -l                Lazy unmount. Detach the filesystem from the filesystem
                       hierarchy now and cleanup all references to the 
                       filesystem as soon as it is not busy any more.
    

    Unmount the floppy mounted on /media/floppy

    # umount /media/floppy
    

    Unmount everything you are able to

    # umount -a
    

    'umount' will free any loop device associated with the mount if it finds the option 'loop=...' in '/etc/mtab' or when the '-d' option is given. Any pending loop devices can be freed using 'losetup -d'.

  • Flush file system buffers
    /bin/sync

    Flush file system buffers by forcing changed blocks to disk, update the super block.

    sync [OPTION]
    
    --help        display this help and exit
    --version     output version information and exit
    

    In the early days used to see 'sync;sync' quite alot ... If it works on ext4 extents would not be suprised to see it a lot on ext4 filesystems - what with their delayed write.

  • Automount with GNOME and nautilus
    /etc/fstab

    In GNOME 2.22, Nautilus will mount volumes listed in /etc/fstab provided that:

    • the vfs.usermount sysctl is set to 1
    • the user requesting the mount owns the mount point
    • the user requesting the mount is in the "operator" group

    Sample /etc/fstab entry

    /dev/ad0s1     /win/c       msdosfs rw,noauto      0   0
    ~~~~ 
    **Configure Nautilus to automatically mount this volume on user marcus's desktop**
    
    

    sysctl vfs.usermount=1

    chown marcus /win/c

    pw group mod operator -m marcus

    ~~~~~