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


Disk partitions

  • IDE and SCSI partitions
    • Partitions are numbered 1 - 63 depending on the kernel driver being used. Older driver versions will probably only support 1 - 15 partitions. - - Partition numbers 1 - 4 are reserved for Primary and Extended partitions.
    • Each hard disk can have a maximum of four Primary or three Primary and one Extended partitions.
    • An Extended partition can contain up to 59 logical partitions - dependent on the driver.
    Device naming

    Letters represent the physical disk, numbers the partitions on the disk.

    /dev/sda1    Refers to the first partition on first disk
    /dev/sdb2    Refers to the second partition on second disk

    ATA and SATA disks use SCSI emulation drivers and are named as SCSI.

    /dev/hda, hdb, hdc, ...  IDE
    /dev/sda, sdb, sdc, ...  SCSI
  • View partition block allocation information via procfs
    $ cat /proc/partitions
    major minor  #blocks  name
       8        0  160836480 sda
       8        1   30716248 sda1
       8        2     289170 sda2
       8        3          1 sda3
       8       10    1951866 sda10
       8       11    2931831 sda11
       8       12   14651248 sda12
       8       16    7897088 sdb
       8       17    6835626 sdb1
       8       18    1060290 sdb2

    The minor number represents the logical partitioning of a device. The major number refers to the device type in '/proc/devices'.

    View mapping of device major numbers to device types via procfs

    $ grep -E '(  8|253)' /proc/devices
    253 usbmon
      8 sd
    253 pktcdvd
  • Disk layout considerations

    A disk's layout is dependent upon a number of factors

    • The size of disk.
    • The size of the system and it's usage i.e. minimalist, development, server, desktop, single or multi-user, applications.
    • Backup strategy i.e. what will be backed up and how (granularity - file, directory, filesystem, logical volume, disk).
    • Recovery and maintenance. Can be easier to implement if installation is more modular/granular, less impact.
    • Amount of free space. The greater the amount of free space in a filesystem, the less likelihood of corruption. Keep 40-30% free.

    Primary Filesystems layout recommendations

    Filesystem Layout recommendations
    / Keep as simple as possible by mounting other portions of the directory tree (/var, /home, /log etc.) on other partitions.
    /boot Have a small separate partition. For older BIOSes locate within the first 1024 cylinders. Formatting as ext2 fs is sufficient.
    /var Ensure it is large enough to contain all generated logs and still have some slack.
    /tmp It is large enough to handle required usage by ALL applications on the system, including user's.
    /usr It is large enough to handle kernel building. If on a separate partition can be shared via NFS as read-only - if desired.
    /home It is large enough to cater for ALL user requirements. Always a good idea to keep separate from / filesystem.

    The minimum number of partitions is 2 - one for the swap partition and one for the root filesystem.

    Primary Filesystems sizing recommendations

    Mount point Sizing recommendations
    swap 2 x RAM
    / 500MB-1GB minimum depending on distribution, number of partitions/filesystems being configured. If mounting all filesystems in a single partition, not ideal, a typical desktop will need 2 - 4GB.
    /boot Can be as small as 50MB, if building/testing kernels will be larger, keep kernel within 1024 cylinders
    /var 2GB. Volatile data. Large enough to handle application and system logs based on log rotation scheme in use
    /tmp 1-2GB. System and application temporary/working files. Large enough to accommodate
    /usr 4GB. If on a separate partition it can be exported via NFS. Large enough to contain application binaries/executables. Static data, will grow as more applications are installed.
    /home User home directories, as large as needed, dependent on number of users and their workload
  • Partition table manipulator
    /sbin/fdisk, parted

    A command driven interactive interface to display and alter a disk's partition table. Other tools e.g. 'gparted', 'cfdisk' (a curses based fdisk).

    parted [options] [device [command [options...]...]]
    fdisk  [options] device
    fdisk common options:
     -l                    List the partition tables for the specified devices and then exit
     -s <partition>        Size of the partition (in blocks) is printed on the standard output

    Print first SCSI disk's partition table

    # fdisk -l /dev/sda
    Disk /dev/sda: 81.9 GB, 81964302336 bytes
    255 heads, 63 sectors/track, 9964 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x000e9974
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          73      586341   83  Linux
    /dev/sda2              74        7052    56058817+   5  Extended
    /dev/sda3            7053        9963    23382607+   c  W95 FAT32 (LBA)
    /dev/sda5              74         559     3903763+  83  Linux
    /dev/sda9            4208        4389     1461883+  82  Linux swap / Solaris
    /dev/sda14           6445        7052     4883728+  83  Linux

    Try it on a more modern system

    $ sudo fdisk -l /dev/sda
    WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk \
    doesn't support GPT. Use GNU Parted.

    'fdisk' and no doubt 'cfdisk' do not support the more modern GUID Partition Table (GPT).

    Use [g]parted for GPTs

    $ sudo parted -l /dev/sda
    [sudo] password for mark: 
    Model: ATA ST1000LM024 HN-M (scsi)
    Disk /dev/sda: 1000GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Number  Start   End     Size    File system     Name                          Flags
     7      17.4kB  1018kB  1000kB
     1      1049kB  106MB   105MB   fat32           EFI system partition          boot
     2      106MB   240MB   134MB                   Microsoft reserved partition  msftres
     3      240MB   116GB   116GB   ntfs            Basic data partition
     4      116GB   217GB   101GB   ext4
     5      217GB   233GB   16.0GB  linux-swap(v1)
     6      233GB   248GB   15.2GB  ext4
     8      248GB   398GB   150GB   ext4
     9      398GB   409GB   10.5GB  ext3
    $ sudo parted /dev/sda print
    Model: ATA ST1000LM024 HN-M (scsi)
    Disk /dev/sda: 1000GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Number  Start   End     Size    File system     Name                          Flags
     7      17.4kB  1018kB  1000kB
     1      1049kB  106MB   105MB   fat32           EFI system partition          boot

    Print size (in blocks) of partition, also size of disk /dev/sda

    # fdisk -s /dev/sda3

    Edit disk partition in interactive mode

    # fdisk /dev/sda
    Command (m for help): a           (Toggle/set boot flag)
    Command (m for help): d           (Delete a partition)
    Command (m for help): l           (List partition type/id)
    Command (m for help): n           (Add a new partition)
    Command (m for help): p           (Print partition table)
    Command (m for help): t           (Change partition type/id)
    Command (m for help): w           (Write/save changes)
    Command (m for help): q           (Quit, write/save any changes first else changes discarded)
    $ sudo parted /dev/sda
    GNU Parted 2.3
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) help                                                             
      align-check TYPE N                        check partition N for TYPE(min|opt) alignment
      check NUMBER                             do a simple check on the file system
      cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
    (parted) q

    gparted is the gnome gui front-end to parted.

  • Swap partition
    • Partition type/id must be set to hex 82 - linux swap.
    • There are two styles of swap, old and new style. Old has SWAP_SPACE, new has SWAPSPACE2 as signatures.

    A memory bound system will try to free up memory by swapping memory pages to disk. The amount of disk space to use for swap is dependent upon the amount of RAM.

    A rule of thumb is swap = 2 x RAM. It should always be (at the very least) greater than the amount of RAM though this is dependent on use:

    • low memory systems - swap > 2 x RAM, tune kernel parameters to favour swapping
    • high memory systems - swap can be < 2 x RAM, tune kernel parameters to not favour swapping
  • Make a swap file

    Set up a Linux swap area on a device or in a file. As of kernel 2.4.11 max number of swap partitions = 32.

    mkswap  [options]  device
     -c                Check the device (if it is a block device) for bad blocks before
                       creating the swap area.  If any are found, the count is printed
     -f                Force - go ahead even if the command is stupid.
     -p PSZ            Set the page size
     -L label          Specify a label, to allow swapon by label. 
                       (Only for new style swap areas)
     -vN               N=0       Create an old style swap area
                       N=1       Create a new style swap area

    Create an initialise a 64MB a swap file

    # dd if=/dev/zero of=swapfile bs=1024 count=65536
    # mkswap swapfile
  • Setup a swap partition

    Create the partition as you would any other then change the partition type/id to 82 (hex). With 'fdisk' the 't' command changes the type/id of a partition.

    A type 82 swap partition

    Device Boot      Start         End      Blocks   Id  System
    /dev/sda9         4208        4389     1461883+  82  Linux swap / Solaris

    Initialise the swap partition /dev/sda9

    # mkswap /dev/sda9

    Although 'parted' can be used to create linux filesystems it is recommended to use file-system-specific packages like 'e2fsprogs'.

  • Enable a swap partition
    /sbin/swapon, swapoff

    Commands are used to specify devices on which paging and swapping are to take place.

    The device or file used is given by the specialfile param. It may be of the form '-L label' or '-U uuid' to indicate a device by label or uuid.

    Get info - usage summary, help Version:
    swapon -s [-h] [-V]
    swapon [-d] [-f] [-p priority] [-v] specialfile...
    swapoff [-v] specialfile...
    Enable/disable all devices marked as swap in /etc/fstab:
    swapon -a [-e] [-f] [-v]
    swapoff -a [-v]
     swapon [options] [<spec>]
     -a, --all              enable all swaps from /etc/fstab
     -d, --discard          discard freed pages before they are reused
     -e, --ifexists         silently skip devices that do not exist
     -f, --fixpgsz          reinitialise the swap space if necessary
     -h, --help             display help and exit
     -p, --priority <prio>  specify the priority of the swap device.
     -s, --summary          display summary about used swap devices and exit
     -v, --verbose          verbose mode
     -V, --version          display version and exit
    The <spec> parameter:
     -L <label>             LABEL of device to be used
     -U <uuid>              UUID of device to be used
     LABEL=<label>          LABEL of device to be used
     UUID=<uuid>            UUID of device to be used
     <device>               name of device to be used
     <file>                 name of file to be used

    Activate all swap spaces, can have more than one. Run during boot

    # swapon -a

    Display swap device status

    # swapon -s /dev/sda6
    Filename    Type       Size      Used    Priority
    /dev/sda6   partition  1172704   40320  -1

    Is equivalent to 'cat /proc/swaps'.

  • Incorrect swap partition UUID

    When no swap devices can be found and a UUID error is returned when an attempt is made to try and enable them then there is a 'mismatch' in UUIDs between the /etc/fstab entry and the partition uuid.

    No swap devices returned

    $ cat /proc/swaps
    Filename                Type        Size    Used    Priority
    $ swapon -s
    Filename                Type        Size    Used    Priority

    Error on enabling swap

    $ swapon -a
    swapon: cannot find the device for UUID=6ad527a1-0344-4e7c-bc4c-c995684a4e1e

    Check /etc/fstab entry is looking on the correct device

    $ grep swap /etc/fstab
    # swap was on /dev/sda5 during installation
    UUID=6ad527a1-0344-4e7c-bc4c-c995684a4e1e none            swap    sw              0       0
    $ sudo parted /dev/sda print 5
    [sudo] password for mark: 
    Minor: 5
    File System: linux-swap(v1)
    Size:         16.0GB (1.60%)
    Minimum size: 4096B (0.00%)
    Maximum size: 1000GB (100%)

    swap partition is /dev/sda5 - but there is no UUID associated with it.

    Add, change UUID for swap area

    $ sudo swaplabel -U 6ad527a1-0344-4e7c-bc4c-c995684a4e1e /dev/sda5
    $ swapon -a
    $ swapon -s
    Filename                Type        Size    Used    Priority
    /dev/sda5                               partition   15626236    0   -1
    $ cat /proc/swaps
    Filename                Type        Size    Used    Priority
    /dev/sda5                               partition   15626236    0   -1