| 0 comments ]

Volume (Partition) Management Commands

The following commands are for systems with uniquely setup LVMS defining each partition inside of a volume group (typically named 'rootvg').

Global Client ID Registration

Viewing Physical Volumes (PV) and Volume Groups (VG)

A few methods to look at the system:

1. Use df ( or df -h) command to view the partitions

Example Print Out From an LME RHEL5 Workstation
Filesystem 1K-blocks Used Available Use% Mounted on Comments (not shown with command)
/dev/sda3 497861 293249 178908 63% /
  • the root '/' partition (Logical Volume) is of about 500MB in size with 63% of it consumed with data.
/dev/sda1 147766 23940 116197 18% /boot
  • the 'boot' partition (LV) , which contains Grub boot loader etc. is 150MB and only 18% full
/dev/rootvg/home 495844 8398 461846 2% /home
  • the 'home' LV, which contains users info., under the volume group 'rootvg' is about 500MB and only 2% full
/dev/rootvg/tmp 10079084 1083500 8483584 12% /tmp
  • the 'tmp' LV under rootvg is 10GB and 12% consumed.
/dev/rootvg/usr 7559332 5993284 1182048 84% /usr
  • the 'usr' LV under rootvg is small but almost full
/dev/rootvg/cache 4031680 2788232 1038648 73% /usr/vice/cache
  • this identifies as the cache for the AFS filesytem
/dev/rootvg/var 1511856 203352 1231704 15% /var
  • the 'var' LV filesystem under rootvg is only 15% consumed
/dev/rootvg/opt 6121280 2509148 3301248 44% /opt
  • the 'opt' Logical Volume (LV) is 44% full

2. Use *pvdisplay* to list details of Volume:

pvdisplay /dev/sda2


Creating a logical volume with lvcreate

Creating a logical volume with lvcreate

This document describes how to create a logical volume into an existing volume group. Logical volumes can be considered 'partitions' such as /usr/ or /etc/ or /data. This example creates a /data partition of type ext3 and mounts it as a part of the rootvg volume group.

Quick Steps:

# pvscan                                - scan for space
# vgscan - scan for vg name
# lvcreate -L xG -n name rootvg - create a vg
# mke2fs -j /dev/rootvg/data - format partition
# mkdir /data - make a mount point
# mount /dev/rootvg/data /data - mount partition
# chmod -R 7777 /data - set rights
(modify fstab)


Process in more detail:


Check for available space with the pvscan command (i.e. 44GB free):

Physical Volume Scan will return the active volumes, their size, and how much available space there is. In this case there is a "SCSI" or "Serial" drive called 'sda2' that is 136GB in size and has 44GB of available space left on it. It also shows that the entire VG is consuming the parition, this is good since we simply want to add a partition to that vol group, and there is free space to do so.

# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE PV "/dev/sda2" of VG "rootvg" [136.58 GB / 44.25 GB free]
pvscan -- total: 1 [136.58 GB] / in use: 1 [136.58 GB] / in no VG: 0 [0]

Scan the volume group for the proper name (i.e. rootvg)

Volume Group scan looks for any active volume groups and returns their name(s). In this case, there is only one Volume group called "rootvg".

# vgscan
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- found active volume group "rootvg"
vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
vgscan -- WARNING: This program does not do a VGDA backup of your volume group

Create a new partition of some size (i.e. 40 GBytes):

Logical Volume create command will allow users to create partitions and of particular size. In the case below, lvcreate is creating a 40G partition called 'data'.

# lvcreate -L 40G -n data rootvg
lvcreate -- doing automatic backup of "rootvg"
lvcreate -- logical volume "/dev/rootvg/data" successfully created

Warning! Be sure that the mount point directory does not already exist on the filesystem.

Create the ext3 filesystem with mke2fs command.

Format the partition with the following command:

# mke2fs -j /dev/rootvg/data
mke2fs 1.32 (09-Nov-2002)
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Writing inode tables: done
Creating journal (8192 blocks): done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Create a mount point:

In this case we are creating a /data mount point

# mkdir /data

Mount the volume to the newly create mount point.

In this case we are mounting the data lv to the /data mount point

# mount /dev/rootvg/data /data

Set the rights on the mounted partition

In this case users are able to create folders on this partition and all sub-folders.

# chmod -R 7777 /data

Then add the command to the /etc/fstab folder (using 'data' in this example):

this will allow this partition to mount on boot. As a test, users could add the value to fstab, then unmount data with 'umount /data', then type mount -a. Then confirm that it has mounted correctly (cd /data or type df).

Creating a logical volume with lvcreat
/dev/rootvg/root / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
/dev/rootvg/home /home ext3 defaults 1 2
/dev/rootvg/opt /opt ext3 defaults 1 2
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/rootvg/tmp /tmp ext3 defaults 1 2
/dev/rootvg/usr /usr ext3 defaults 1 2
/dev/rootvg/cache /usr/vice/cache ext2 defaults 1 2
/dev/rootvg/var /var ext3 defaults 1 2
=> /dev/rootvg/data /data ext3 defaults 1 2
/dev/rootvg/swap swap swap defaults 0 0
/dev/fd0 /mnt/win/floppy auto noauto,user,rw\t0 0
/dev/sda1 /mnt/win/removable auto noauto,user,rw\t0 0
/dev/hde1 /mnt/win/microdrive auto noauto,user,rw\t0 0
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0



Creating Extra swap file(s)

Creating Extra swap file(s)

Adding Swap space to a system after adding a new Drive. However, this document can be generally applied to adding swap space on any type of system.

  1. Add the drive, boot the system
  2. Create a swap partition on the new drive
  3. Use fdisk to find the drive and partition
    (type fdisk /dev/device_name)
    (then type 'p' to print the partitions)
    # fdisk /dev/sdb

    Command (m for help): p
    Disk /dev/sdb: 120.0 GB, 120034123776 bytes
    Device Boot Start End Blocks Id System
    /dev/sdb1 1 1460 11727418+ 82 Linux swap
    /dev/sdb2 1461 14593 105490822+ 83 Linux
  4. Label the partition (if not already):
    # mkswap -L SWAP-sdb1 /dev/sdb1
    Setting up swapspace version 1, size = 12008869 kB
  5. Add the following to /etc/fstab (change your label for the label you had created):
    LABEL=SWAP-sdb1         swap                    swap    defaults        0 0
  6. Turn on the swap with swapon -a (which runs config in fstab):
    # swapon -a



  7. Confirm that the swap file is now in use with swapon -s :
    # swapon -s

    Filename Type Size Used Priority
    /dev/sda2 partition 1044216 0 -1
    /dev/sdb1 partition 11727408 0 -2



Resizing LVM Swap Partition

Resizing LVM Swap Partition

  1. Use fstab to find swap mount point
    vi /etc/fstab


  2. Stop swapping on the swap space (use caution)
    swapoff -v /dev/rootvg/swap
    swapoff on /dev/rootvg/swap


  3. Resize partition with the lvextend command:
    lvextend -L +2G /dev/rootvg/swap

    lvextend -- extending logical volume "/dev/rootvg/swap" to 3.95 GB
    lvextend -- doing automatic backup of volume group "rootvg"
    lvextend -- logical volume "/dev/rootvg/swap" successfully extended

    This example increased the swap by 2 GigaBytes by using the +2G option. To reduce by 2Gig, use -2G.

  4. Tun the MakeSwap command mkswap
    mkswap /dev/rootvg/swap

    Setting up swapspace version 1, size = 4244631 kB


    #Turn the swap back on and confirm it's working

    swapon -va

    swapon on /dev/rootvg/swap


  5. Show the new swap space with swapon command:
    swapon -s

    Filename Type Size Used Priority
    /dev/rootvg/swap partition 4145144 0 -2

    - using proc -

    cat /proc/swaps

    Filename Type Size Used Priority
    /dev/rootvg/swap partition 4145144 0 -2



Reducing or Removing a Logical Volume on a system.

Reducing or Removing a Logical Volume on a system

Reducing Logical Volumes (LVMs)


Reducing a Logical Volume:

  1. Figure out the full partition name by typing the df command:
    df
    $ df
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/hda3 495404 334050 135776 72% /
    /dev/hda1 148345 15477 125209 12% /boot
    /dev/rootvg/home 495844 8240 462004 2% /home
    /dev/rootvg/opt 3023760 2024560 845600 71% /opt
    none 1859780 0 1859780 0% /dev/shm
    /dev/rootvg/tmp 10079084 917976 8649108 10% /tmp
    /dev/rootvg/usr 7559332 4718700 2456632 66% /usr
    /dev/rootvg/cache 4031680 47740 3779140 2% /usr/vice/cache
    /dev/rootvg/var 1511856 272436 1162620 19% /var
    AFS 9000000 0 9000000 0% /afs
  2. Unmount the filesystem with :
    umount /homevol

    -or-

    umount /dev/myvg/homevol/dev/myvg/homevol


    • Troubleshooting and unmounting 'busy' partitions (note: some can only be umounted in singlemode)
      • Use fuser command to display users and services using the partition:
        fuser -m /dev/myvg/homevol
      • To force users/services off a partition use the following command with caution
        fuser -km /dev/myvg/homevol


  3. Reduce the size by X GigaBytes with the following command:
    e2fsadm -L-xG /dev/myvg/homevol

    ( x being 1,2,3 ... )

  4. Run fsck against the drive with:
    e2fsck -f /dev/rootvg/home
  5. Re-Mount the partition quickly with mount -a
    or you can type: mount /dev/myvg/homevol /home

  6. Confirm that the partition is functional using the df command.


Removing Logical Volumes

Reducing a Logical Volume:

  1. Figure out the full partition name by typing the df command:
    df
    $ df
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/hda3 495404 334050 135776 72% /
    /dev/hda1 148345 15477 125209 12% /boot
    /dev/rootvg/home 495844 8240 462004 2% /home
    /dev/rootvg/opt 3023760 2024560 845600 71% /opt
    none 1859780 0 1859780 0% /dev/shm
    /dev/rootvg/tmp 10079084 917976 8649108 10% /tmp
    /dev/rootvg/usr 7559332 4718700 2456632 66% /usr
    /dev/rootvg/cache 4031680 47740 3779140 2% /usr/vice/cache
    /dev/rootvg/var 1511856 272436 1162620 19% /var
    AFS 9000000 0 9000000 0% /afs
  2. Unmount the filesystem with :
    umount /homevol

    -or-

    umount /dev/myvg/homevol/dev/myvg/homevol


    • Troubleshooting and unmounting 'busy' partitions (note: some can only be umounted in singlemode)
      • Use fuser command to display users and services using the partition:
        fuser -m /dev/myvg/homevol
      • To force users/services off a partition use the following command with caution
        fuser -km /dev/myvg/homevol


  3. Use the lvremove command to delete the partition
    lvremove /dev/myvg/homevol
    lvremove -- do you really want to remove "/dev/myvg/homevol"? \[y/n\]: y
    lvremove -- doing automatic backup of volume group "myvg"
    lvremove -- logical volume "/dev/myvg/homevol" successfully removed

  4. Confirm what is remaining with by typing mount command (with no options)

Extending Logical Volumes (LVMs)

Extending Logical Volumes (LVMs)

Linux Open Client partitions can not be resized very easily, re-install the Open Client if LINUX partitions need to be re-sized. Of course be sure to backup data to TSM or some other media before doing any major changes to the system. Also never attempt to resize Linux partitions with Partition magic as it currently is unable to properly allow the system to boot after changes are made. The rest of this document covers the manipulating Logical Volumes which are basically partitions created within a volume group usually named rootvg. This document does not cover how to concerning Volume Groups. Basic Linux Open Client installs do not use volume groups, only some of the custom "server" installs. To check a user can simply type the 'df' command.

Logical Volume Manager - LVM systems can have their sizes altered.

LVM is a Logical Volume Manager implemented by Heinz Mauelshagen for the Linux operating system. As of kernel version 2.4, LVM is incorporated in the main kernel source tree.


Commands issued:

Unmounting the partition(s)

  • Unmount the logical volume with:
    umount /dev/myvg/homevol
  • Troubleshooting and unmounting 'busy' partitions (note: some can only be umounted in singlemode)
    • Use fuser to display users and services using the partition:
      fuser -m /dev/myvg/homevol
    • To force users/services off a partition use the following command with caution
      fuser -km /dev/myvg/homevol

Extend the Logical volume with lvextend

  • lvextend by some size in GigBytes (x being 1,2,3..etc)
    lvextend -L+xG /dev/myvg/homevol

Run checkdisk on partition

e2fsck -f /dev/rootvg/home

Run resize2fs

resize2fs /dev/myvg/homevol

Remount the partition(s)

mount -a



Basic Steps

1. Unmount volume

umount /dev/myvg/homevol/dev/myvg/homevol
-or-
umount /homevol

2. Resize the logical volume

Example: (extend /dev/myvg/homevol to 12 Gigabytes)

lvextend -L12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended

Example: (extend /dev/myvg/homevol BY 12 Gigabytes)

lvextend -L+12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended

3. Run disk check (fsck)
e2fsck -f /dev/rootvg/home

4. Resize2fs command
resize2fs /dev/myvg/homevol


5. Re-Mount Logical partition
mount /dev/myvg/homevol /home - or - mount -a



Troubleshooting umount

Use lsof to see which files are locking the partition:

lsof /dev/rootvg/tmp

You will see services connected to X11 and font server.
switch to runlevel 3 with 'init 3'
make sure xfs isn't running -> service xfs stop
re-run lsof and kill as needed.

0 comments

Post a Comment