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

Logical Volumes

  • Logical Volume Manager (LVM)
    • A LVM provides greater flexibility in administrating storage devices.
    • Storage volumes created under the control of the logical volume manager can be resized and moved around almost at will.
    • LVM configuration file is /etc/lvm/lvm.conf which contains configuration information on how commands will behave.
  • Place physical volumes under LVM management
    /sbin/pvcreate
    • Place disks or partitions (physical volumes) under LVM management.
    • If the disk already has a partition table on it, not even --force option will make 'pvcreate' run.
    • Will also complain if partition type is not 0x8e, change if required.
    pvcreate [options] physicalvolume [physicalvolume ...]
    

    Destroy partition table on a disk and initialise it for LVM

    # dd if=/dev/zero of=/dev/sda bs=1k count =1
    # blockdev --rereadpt /dev/sda
    # pvcreate  /dev/sda7
    
  • Create a new volume group
    /sbin/vgcreate
    • uses the block special device(s) which have been previously configured for LVM with pvcreate
    • a volume group consists of one or more physical disks or partitions - physical volumes.
    vgcreate [options] VGname device1 [device? ...]
    

    Create volume on /dev/sda7

    # vgcreate FedoraVG /dev/sda7
    
  • Create a new logical volume
    /sbin/lvcreate
    • allocates logical extents from the free physical extent pool of a volume group.
    • the resulting LV can then be used to contain a filesystem.
    • under LVM more than one filesystem can reside on a single physical partition.
    lvcreate [options] VGname
    
    Common options:
     -L size                 Size can be postfixed with K, M, G, T(terabytes), default is M.
     -l size                 In logical extents (# vgdisplay shows number of extents in VG)
                             can be more accurate to work with than M, K, ...
     -n lvname               LV name, defaults to "lvol#" where # is the LVM internal.
    

    Create a 1.41GB logical volume named optLV in FedoraVG volume group

    # lvcreate -L 1.41G -n optLV FedoraVG
    
  • Display attributes of a physical volume
    /sbin/pvdisplay
    pvdisplay [options] device [device ...]
    
    Options:
     -c | --colon             Colon separated output for easier parsing in scripts or programs
     -s | --short             Only display the size of the given physical volumes
     -m | --maps              Display the mapping of physical extents to logical volumes and
                              logical extents
    

    Display attributes of /dev/sda7

    # pvdisplay -c /dev/sda7
    /dev/sda7:FedoraVG:51391872:-1:8:8:-1:32768:784:19:765:gaW3J4-q8tI-GHGc-GubJ-dl3g-mjL8-eEWwhY
    
    # pvdisplay /dev/sda7
     --- Physical volume ---
      PV Name               /dev/sda7
      VG Name               FedoraVG
      PV Size               24.51 GB / not usable 5.69 MB
      Allocatable           yes
      PE Size (KByte)       32768
      Total PE              784
      Free PE               19
      Allocated PE          765
      PV UUID               gaW3J4-q8tI-GHGc-GubJ-dl3g-mjL8-eEWwhY
    
  • Report information about physical volumes
    /sbin/pvs

    Provides greater control over the format of the output than 'pvdisplay'.

    pvs [options] [device ...]
    
    Some options:
     --aligned               Use with --separator to align the output columns.
     --noheadings            Suppress the headings line - normally the first line of output,
                             useful if 'grepping'
     --nosuffix              Suppress the suffix on output sizes.  Use with --units (except
                             h and H) if processing the output.
    

    Display attributes of a physical volume

    # pvs
      PV         VG       Fmt  Attr PSize  PFree
      /dev/sda7  FedoraVG lvm2 a-   24.50G 608.00M
    
  • Display attributes of volume groups
    /sbin/vgdisplay
    vgdisplay [options] [VGname ...]
    
    Some options:
     -A | --activevolumegroups            Only select the active volume groups.
     -c | --colon                         Generate colon separated output.
     -s | --short                         Short listing showing the existence of volume groups.
     -v | --verbose                       Display verbose information.
    

    Display attributes of a Volume Group

    # vgdisplay FedoraVG
     --- Volume group ---
      VG Name               FedoraVG
      System ID
      Format                lvm2
      .....
      VG Size               24.50 GB
      PE Size               32.00 MB
      Total PE              784
      Alloc PE / Size       765 / 23.91 GB
      Free  PE / Size       19 / 608.00 MB
      VG UUID               7Phmek-xgrT-SesT-KVQo-4AZ8-z8Yr-0lhB9t
    
    # vgdisplay -v FedoraVG | grep "LV Name"
        Using volume group(s) on command line
        Finding volume group "FedoraVG"
      LV Name                /dev/FedoraVG/optLV
      LV Name                /dev/FedoraVG/tmpLV
      LV Name                /dev/FedoraVG/homeLV
      LV Name                /dev/FedoraVG/usrLV
      LV Name                /dev/FedoraVG/varLV
      LV Name                /dev/FedoraVG/shareLV
    
    # vgdisplay -s FedoraVG
      "FedoraVG" 24.50 GB  [23.91 GB  used / 608.00 MB free]
    
  • Report information about volume groups
    /sbin/vgs

    Provides reater control over the format of the output than 'vgdisplay'.

    vgs [options] [device ...]
    
    Some options:
     --aligned               Use with --separator to align the output columns.
     --noheadings            Suppress the headings line.
     --nosuffix              Suppress the suffix on output sizes.
    

    Display attributes of a Volume Group

    # vgs
      VG       #PV #LV #SN Attr   VSize  VFree
      FedoraVG   1   6   0 wz--n- 24.50G 608.00M
    
  • Display attributes of a logical volume
    /sbin/lvdisplay
    lvdisplay [options] LVname [LVname ...]
    
    Some options:
     -c | --colon            Colon separated output for easier parsing in scripts or programs.
     -m | --maps             Display the mapping of physical extents to logical volumes and
                             logical extents.
    

    Display attributes of a Logical Volume

    # lvdisplay /dev/FedoraVG/optLV
     --- Logical volume ---
      LV Name                /dev/FedoraVG/optLV
      VG Name                FedoraVG
      LV UUID                qVldo5-Y9Zm-QlNj-CMFo-JN8J-A7Ii-Q4143Y
      LV Write Access        read/write
      LV Status              available
      # open                 1
      LV Size                1.41 GB
      Current LE             45
      Segments               1
      Allocation             inherit
      Read ahead sectors     0
      Block device           253:0
    
  • Report information about logical volumes
    /sbin/lvs

    Provides greater control over the format of the output than 'lvdisplay'.

    lvs [options] [device ...]
    
    Some options:
     --aligned               Use with --separator to align the output columns.
     --noheadings            Suppress the headings line.
     --nosuffix              Suppress the suffix on output sizes..
    

    Display information about a Logical Volume

    # lvs
      LV      VG       Attr   LSize  Origin Snap%  Move Log Copy%
      homeLV  FedoraVG -wi-ao  8.00G
      optLV   FedoraVG -wi-ao  1.41G
      shareLV FedoraVG -wi-ao  1.50G
      tmpLV   FedoraVG -wi-ao  1.00G
      usrLV   FedoraVG -wi-ao 10.00G
      varLV   FedoraVG -wi-ao  2.00G
    
  • Scan all disks for physical volumes
    /sbin/pvscan
    pvscan [options]
    
    Some options:
     -n | --novolumegroup          Only show physical volumes not belonging to any volume group
     -e | --exported               Only show physical volumes belonging to exported volume groups
     -s | --short                  Short listing format
     -u | --uuid                   Show UUIDs (Uniform Unique Identifiers) in addition to device
                                   special names
    

    Scan all disks for PVs

    # pvscan
      PV /dev/sda7   VG FedoraVG   lvm2 [24.50 GB / 608.00 MB free]
      Total: 1 [24.50 GB] / in use: 1 [24.50 GB] / in no VG: 0 [0   ]
    
    # pvscan -n
      WARNING: only considering physical volumes in no volume group
      No matching physical volumes found
    
  • Moves physical extents
    /sbin/pvmove

    If no destination PV or LV then the moved physical extents are distributed using the normal allocation rules of the volume group.

    pvmove [options] 
           sourcepv[:PE[-PE]] 
           [destinationpv[:PE[-PE]]
    
    Some options:
     -n | --name  LogicalVolume        Move only the extents belonging to LogicalVolume from
                                       SourcePhysicalVolume instead of all allocated extents to
                                       the destination physical volume(s)
     -t | --test
     -v                                Verbose
      [:PE[-PE]]                       Physical extent range
    

    The following examples are from here

    Move all logical extents of any logical volumes on /dev/hda4 to free physical extents elsewhere in the volume group

    pvmove -v /dev/hda4
    

    Move three logical extents (3, 5 and 11) of logical volume my_lv to free ones on /dev/hdb3

    pvmove -n my_lv:3:5:11 /dev/sdb6 /dev/hdb3 
    
  • Add physical volumes to a volume group
    /sbin/vgextend
    vgextend [options] 
             VGname physicaldevice [physicaldevice ...]
    
    Some options:
     -a | --autobackup <y|n>
     -t | --test
    

    Add /dev/sda5 and /dev/sdc1 to volume group foo_vg

    vgextend foo_vg /dev/sda5 /dev/sdc1
    
  • Remove a physical volume(s) from a volume group
    /sbin/vgreduce
    vgreduce VGname physicalvolume [physicalvolume ...]
    
    Some options:
     -a | --all               Removes all empty physical volumes if none are given on command line
     -t | --test
     --removemissing          Removes all missing physical volumes from the volume group and makes
                              the volume group consistent again. Run this option with '--test' first
                              to find out what it would remove before running it for real.
    

    Remove /dev/sda5 and /dev/sdc1 to volume group foo_vg

    vgremove foo_vg /dev/sda5 /dev/sdc1
    
  • Reduce the size of a logical volume
    /sbin/lvreduce
    lvreduce [options] LogicalVolume[Path]
    
    Options:
     -A | --autobackup             y/n
     -d | --debug
     -f | --force
     -h | -? | --help
     -l | --extents [-]LogicalExtentsNumber[%{VG|LV|FREE}]
     -L | --size [-]LogicalVolumeSize[kKmMgGtT]
     -t | --test
     -v | --verbose
    

    Reduce size of lv01 in vg foo_vg by 3 extents

    lvreduce -l -3 /dev/foo_vg/lv01
    

    Safe way to shrink a Logicial volume

    • shrink the FileSystem a bit more than required
    • then shrink the LV
    • then resize the FileSystem to fit LV completely
    # resize2fs /dev/FedoraVG/optLV 1.35G           (shrink filesystem to 1.35GB)
    
    # lvreduce -L 1.41G /dev/FedoraVG/optLV         (reduce the logical volume)
    
    # resize2fs /dev/FedoraVG/optLV                 (resize the filesystem to fit)
    
  • Extend the size of a logical volume
    /sbin/lvextend
    lvextend [options] LVpath [physicalvolume ...]
    
    Some options:
     -l | --extents [+]LogicalExtentsNumber[%{VG|LV|FREE}]
                    Extend or set the logical volume size in units of logical extents
                    + => add to the actual size of the logical volume, without + => absolute value
                    %VG => a percentage of the total space in the Volume Group
                    %LV => relative to the existing size of the Logical Volume
                    %FREE => percentage of the remaining free space in the Volume Group
    
     -L | --size [+]LogicalVolumeSize[kKmMgGtTpPeE]
                    Extend or set the logical volume size in units of megabytes
                    M=megabytes, G=gigabytes, T=terabytes, P=petabytes, E=exabytes
                    + sign the value is added to the actual size of the logical volume
                    without a + the value is taken as an absolute one
     -t | --test
    

    Increase size of a filesystem by 200MB

    # lvextend -L +200M /dev/FedoraVG/optLV            (increase LV first)
    
    # resize2fs /dev/FedoraVG/optLV                    (resize the fs to fill the LV)
    
  • Remove a volume group
    /sbin/vgremove
    • The volume group(s) must not have any logical volumes allocated
    • the volume group needs to be made unavailable (varyoff) first
    vgremove [options] VolumeGroupName [...]
    
    Options:
     -d | --debug
     -h ! -? | --help
     -t | --test
     -v | --verbose
    

    Remove volume group foo_vg

    vgchange -a n foo_vg            (varyoff the VG first)
    
    vgremove foo_vg
    
  • Remove a logical volume
    /sbin/lvremove

    All data will be lost.

    lvremove [options] LVpath [LVpath ...]
    
    Some options:
     -A | --autobackup y|n
     -f | --force                   Remove active lvs without confirmation
     -t | --test                    Report what would happen, do not do the removal
    

    Test removal of logical volume optLV

    lvremove --test /dev/FedoraVG/optLV
    
  • Change a Volume Group's attributes
    /sbin/vgchange
    vgchange [options] VGname
    
    Some options:
     -a [n|y]                             Deactivate, activate a VG (varyon, varyoff)
     -l | --logicalvolume int             Change the maximum logical volume number of an
                                          existing inactive volume group.
     -p | --maxphysicalvolumes int        Change the maximum number of physical volumes that
                                          can belong to this volume group.
    

    Varyoff then varyon volume group FedoraVG

    vgchange -a n FedoraVG 
    vgchange -a y FedoraVG 
    
  • Scan all disks for volume groups and rebuild caches
    /sbin/vgscan

    Can define a filter in lvm.conf.

    vgscan [options]
    
    

    Scan all VGs

    # vgscan -v
    Wiping cache of LVM-capable devices
    Wiping internal VG cache
    Reading all physical volumes.  This may take a while...
    Finding all volume groups
    Finding volume group "FedoraVG"
    Found volume group "FedoraVG" using metadata type lvm2
    
  • Logical volume snapshot

    A LV can be frozen while still being used, a backup can be made of the frozen copy.

    Create a snapshot

    # lvcreate -L 100M -s -n lv_backup /dev/FedoraVG/optLV
    

    Creates a snapshot of optLV in a 100M logical volume named lv_backup.

    Remove a snapshot

    # lvremove /dev/VGname/lv_backup
    

    Usually after it has been backed up.

  • Convert a logical volume
    /sbin/lvconvert

    Converts from linear to mirror or snapshot. Also used to add and remove disk logs from mirror devices.

    lvconvert -m LV[Path] [PV[Path] ...]
    
    Options:
     -m | --mirrors Mirrors                  Number of mirror copies (-m 1 creates a single mirror)
     --corelog                               Have mirror copy use a memory-based as opposed to disk
                                             (persistent) based log.
     -R | --regionsize MirrorLogRegionSize   A mirror is divided into regions of this size(MB).
                                             The mirror log uses this granularity to track which 
                                             regions are in sync.
     -A | --alloc AllocationPolicy
    
    lvconvert -s | --snapshot OriginalLV[Path] SnapshotLV[Path]
    
    Options:
     -s | --snapshot                         Create a snapshot from existing logical volume using
                                             another existing logical volume as its origin.
     -c | --chunksize ChunkSize              Power of 2 chunk size for the snapshot logical volume
                                             between 4k and 512k
     -Z | --zero y/n                         Controls zeroing of the first KB of data in the snapshot.
                                             If volume is read-only the snapshot will not be zeroed.
    

    Man page examples:

    Convert the linear logical volume "vg00/lvol1" to a mirror logical volume

    # lvconvert -m1 vg00/lvol1
    

    Convert a two-way mirror with a disk log to a two-way mirror with an in-memory log

    # lvconvert -m1 --corelog vg00/lvol1
    

    Convert a mirror logical volume to a linear logical volume

    # lvconvert -m0 vg00/lvol1
    

    Convert logical volume "vg00/lvol2" to snapshot of original volume "vg00/lvol1"

    # lvconvert -s vg00/lvol1 vg00/lvol2