Connect With Us

Breaking Down Your AIX Disk Usage

Find out where your disk space is hiding

On AIX, determining how much total disk space is available, how it’s being used, and how much free space is available can be a challenging task. AIX’s logical volume manager (LVM) is one of its most powerful and useful tools, but using it to determine disk usage can be complicated. In this article, I’ll show you how to break down disk space usage and determine how much space is still available. I’ll also explain each level of the LVM and how to understand disk usage at each level.

The AIX LVM has four layers: physical volumes, volume groups, logical volumes, and file systems. There are several places in the LVM where you can monitor total and available disk space. You can use LVM to determine:

  • Total space of all physical volumes (hdisks) on the system
  • Space from the physical volumes allocated to volume groups
  • Used and free space on each volume group
  • Used and free space on each file system
  • Hidden used and free space, including LVM mirroring and logical volumes without file systems

Figure 1 shows the various levels of the LVM and the places free space can exist. Our example server has 500GB of disk allocated to it, but it’s only using 200GB of this space, leaving 300GB free at the various levels of the LVM.

Physical Volumes

Physical volumes are the lowest levels of the LVM in AIX; they show up as hdisk devices. Physical volumes can be physical disks in a server or LUNs presented on a SAN. In either case, a physical volume can be a member of a single volume group. There are two ways to determine the size of a physical volume: the lspv command and the getconf command. Running the following lspv command:

  1. # lspv hdisk0

gives you the following output:

  1. PHYSICAL VOLUME:    hdisk0                   VOLUME GROUP:     rootvg
  2. PV IDENTIFIER:      00cc202e7db580dd VG IDENTIFIER     00cc202e00004c00000001397db582ca
  3. PV STATE:           active                                    
  4. STALE PARTITIONS:   0                        ALLOCATABLE:      yes
  5. PP SIZE:            32 megabyte(s)           LOGICAL VOLUMES:  11
  6. TOTAL PPs:          639 (20448 megabytes)    VG DESCRIPTORS:   2
  7. FREE PPs:           212 (6784 megabytes)     HOT SPARE:        no
  8. USED PPs:           427 (13664 megabytes)    MAX REQUEST:      256 kilobytes
  9. FREE DISTRIBUTION:  84..00..00..00..128                      
  10. USED DISTRIBUTION:  44..128..127..128..00                      
  11. MIRROR POOL:        None

The TOTAL PPs: line shows the size of the disk (in this example, 20,448MB). The lspv output also includes useful information on how much of the disk is used (USED PPs) and how much of the disk is available (FREE PPs) in relation to logical volumes. However, lspv won’t work if you try to find the size of a disk that hasn’t been assigned to a volume group:

  1. # lspv hdisk10
  2. 0516-320 : Physical volume hdisk10 is not assigned to
  3.         a volume group.

The second method for determining disk size uses the getconf command:

  1. # getconf DISK_SIZE /dev/hdisk10
  2. 256

The getconf command returns the number of megabytes of the disk and will work even if the disk isn’t assigned to a volume group.

  1. for hdisk in `lsdev -c disk | grep "Available" | awk '{print $1}'`; do printf "%-10s %-12s %-15s\n" $hdisk `getconf DISK_SIZE /dev/$hdisk` `lspv | grep "^$hdisk " | awk '{print $3}'` ; done | awk '{total+=$2} {print} END{print "------------------\nTotal:     " total " MB (" total/1024 " GB)"}'

This command can be used to determine the total amount of raw physical disk space available on an AIX server. As you can see in the following command output, the server has a total of 22.375GB of disk space available:
 

  1. hdisk0     20480        rootvg        
  2. hdisk1     128          datavg        
  3. hdisk2     256          datavg        
  4. hdisk3     256          datavg        
  5. hdisk4     256          testvg        
  6. hdisk5     256          testvg        
  7. hdisk6     256          appvg        
  8. hdisk7     256          appvg        
  9. hdisk8     256          appvg        
  10. hdisk9     256          appvg        
  11. hdisk10    256          None          
  12. ------------------
  13. Total:     22912 MB (22.375 GB)

Volume Groups and Logical Volumes

Moving up from physical disks, the next two levels in LVM are volume groups and logical volumes. Volume groups are made up of one or more physical volumes. The total available space in a volume group is the sum of all of the physical volumes that make up the volume group. To view the total size of the volume group and the amount of used and free space, use the lsvg command:

  1. # lsvg rootvg

to get the following output:

  1. VOLUME GROUP:       rootvg                   VG IDENTIFIER:  00cc202e00004c00000001397db582ca
  2. VG STATE:           active                   PP SIZE:        32 megabyte(s)
  3. VG PERMISSION:      read/write               TOTAL PPs:      639 (20448 megabytes)
  4. MAX LVs:            256                      FREE PPs:       212 (6784 megabytes)
  5. LVs:                11                       USED PPs:       427 (13664 megabytes)
  6. OPEN LVs:           10                       QUORUM:         2 (Enabled)
  7. TOTAL PVs:          1                        VG DESCRIPTORS: 2
  8. STALE PVs:          0                        STALE PPs:      0
  9. ACTIVE PVs:         1                        AUTO ON:        yes
  10. MAX PPs per VG:     32512                                    
  11. MAX PPs per PV:     1016                     MAX PVs:        32
  12. LTG size (Dynamic): 256 kilobyte(s)          AUTO SYNC:      no
  13. HOT SPARE:          no                       BB POLICY:      relocatable
  14. PV RESTRICTION:     none                     INFINITE RETRY: no

The used space shows how much of the volume group has been allocated to logical volumes. Most logical volumes have file systems on them. Note that the used/free space listed in “lsvg” doesn't take into account how much is used on a file system—it’s simply the size that has been allocated to the logical volume (i.e., the total size of the file system).

To view a summary of all the volume groups on a server, including the total size, free space, and used space, run the following command:

  1. printf "Volume Group      Total(MB)  Free(MB)   Used(MB)\n"; for vg in `lsvg -o`; do printf "%-18s" $vg; lsvg $vg | perl -nle 'printf "%-11s", $2 if /.*(TOTAL|FREE|USED) PPs:\s+\d+\s+\((\d+) meg.*/'; echo; done | awk '{total+=$2; free+=$3; used+=$4} {print} END{printf "---------\nTotals:           %-10s %-10s %-10s\n", total, free, used}'

Running the above command results in the following output:

  1. Volume Group      Total(MB)  Free(MB)   Used(MB)
  2. appvg             736        132        604      
  3. datavg            424        52         372      
  4. testvg            368        4          364      
  5. rootvg            20448      6784       13664    
  6. ---------
  7. Totals:           21976      6972       15004

File Systems

The next level of the LVM contains the file systems. File systems are created on top of logical volumes, and the file system capacity is the size of the logical volume. The df-tm command can be used to see a report on the size of each file system, the used space, and the free space:

  1. # df -tm

The output from the df -tm command is:

  1. File system    MB blocks      Free %Used    Iused %Iused Mounted on
  2. /dev/hd4         320.00    115.60   64%    10786    23% /
  3. /dev/hd2        2432.00    279.45   89%    48929    38% /usr
  4. /dev/hd9var      544.00    171.51   69%     8590    16% /var
  5. /dev/hd3        8192.00   3577.39   57%      228     1% /tmp
  6. /dev/hd1          32.00     31.62    2%       11     1% /home
  7. /dev/hd11admin    128.00    127.63    1%        5     1% /admin
  8. /proc                 -         -    -         -     -  /proc
  9. /dev/hd10opt     544.00    338.55   38%     8954    10% /opt
  10. /dev/livedump    256.00    255.64    1%        4     1% /var/adm/ras/livedump
  11. /dev/fslv00       16.00      0.67   96%        5     3% /data1
  12. /dev/fslv01      352.00    222.62   37%        5     1% /data2
  13. /dev/fslv02      260.00    109.63   58%        5     1% /test1
  14. /dev/fslv03      100.00     29.66   71%        5     1% /test2
  15. /dev/fslv04      300.00     97.63   68%        5     1% /app1
  16. /dev/fslv05      100.00     30.66   70%        5     1% /app2
  17. /dev/fslv06      200.00      0.64  100%        5     3% /app3

The df -tm command is useful, but it doesn't show the entire picture, because it doesn't include some things that take up space (e.g., unmounted file systems, paging space, JFS logs, raw logical volumes). It also doesn't take into account additional space used by mirrored logical volumes.

Estimating Used Space

To estimate the amount of used space in the LVM, add up:

  • The amount of file system space used in each logical volume that contains mounted file systems
  • The total size of each logical volume that doesn't contain a file system (e.g., JFS log, paging space, raw logical volumes)
  • The total size of unmounted file systems (remember that you can only determine file system usage for mounted file systems)

We’ll factor in logical volume mirroring when calculating the used space. For example, if a file system is using 70MB but is on a logical volume that's mirrored, the used space will be reported as 140MB. The script in Listing 1 accomplishes the task of estimating used space.

  1. #!/usr/bin/ksh
  2.  
  3. grandtotal=0
  4. for vg in `lsvg -o`; do
  5.   vgused=0
  6.   echo $vg
  7.   ppsize=`lsvg $vg | perl -nle 'print $1 if /.*PP SIZE:\s+(\d+) meg.*/'`
  8.   lsvg -l $vg | sed -e '1,2d' | while read line; do
  9.     lvname=`echo $line | awk '{print $1}'`
  10.     type=`echo $line | awk '{print $2}'`
  11.     lps=`echo $line | awk '{print $3}'`
  12.     pps=`echo $line | awk '{print $4}'`
  13.     status=`echo $line | awk '{print $6}'`
  14.     fs=`echo $line | awk '{print $7}'`
  15.     let factor="$pps / $lps"
  16.     mirror="unmirrored"
  17.     if [ "$factor" -gt "1" ]; then mirror="mirrored * $factor"; fi
  18.  
  19.     if [ "$status" = "open/syncd" -a \( "$type" = "jfs" -o "$type" = "jfs2" \) ]; then
  20.       size=`df -tm $fs | sed -e '1d' | awk '{print $3}'`
  21.       tsize=`echo "scale=2; $size * $factor" | bc`
  22.       printf "  %-22s using   %-10s MB    Mounted Filesystem   - $mirror\n" $fs $tsize
  23.     else
  24.       let tsize="pps * ppsize"
  25.       d="$lvname/$type"
  26.       if [ "$type" = "jfs" -o "$type" = "jfs2" ]; then
  27.         printf "  %-22s using   %-10s MB    Unmounted Filesystem - $mirror\n" $fs $tsize
  28.       else
  29.         printf "  %-22s using   %-10s MB    Other LV             - $mirror\n" $d $tsize
  30.       fi
  31.   fi
  32.   vgused=`echo "scale=2; $vgused + $tsize" | bc`
  33. done
  34.   printf "                         Total:  %-10s MB\n" $vgused
  35.   grandtotal=`echo "scale=2; $vgused + $grandtotal" | bc`
  36.  
  37. done
  38. echo "----------------------------------------------"
  39. printf " Total used space for all VG's:  %-10s MB\n" $grandtotal

Listing 1: Calculate Estimated Disk Usage

The output from the script in Listing 1 is:

  1. appvg
  2.   loglv02/jfs2log        using   4          MB    Other LV             - unmirrored
  3.   /app1                  using   202.37     MB    Mounted File system   - unmirrored
  4.   /app2                  using   69.34      MB    Mounted File system   - unmirrored
  5.   /app3                  using   199.36     MB    Mounted File system   - unmirrored
  6.   loglv03/jfslog         using   4          MB    Other LV             - unmirrored
  7.   /app4                  using   3.30       MB    Mounted File system   - unmirrored
  8.                          Total:  482.37     MB
  9. datavg
  10.   loglv00/jfs2log        using   4          MB    Other LV             - unmirrored
  11.   /data1                 using   30.66      MB    Mounted File system   - mirrored * 2
  12.   /data2                 using   352        MB    Unmounted File system - unmirrored
  13.                          Total:  386.66     MB
  14. testvg
  15.   loglv01/jfs2log        using   4          MB    Other LV             - unmirrored
  16.   /test1                 using   150.37     MB    Mounted File system   - unmirrored
  17.   /test2                 using   100        MB    Unmounted File system - unmirrored
  18.                          Total:  254.37     MB
  19. rootvg
  20.   hd5/boot               using   32         MB    Other LV             - unmirrored
  21.   hd6/paging             using   1152       MB    Other LV             - unmirrored
  22.   hd8/jfs2log            using   32         MB    Other LV             - unmirrored
  23.   /                      using   204.10     MB    Mounted File system   - unmirrored
  24.   /usr                   using   2152.55    MB    Mounted File system   - unmirrored
  25.   /var                   using   373.07     MB    Mounted File system   - unmirrored
  26.   /tmp                   using   4614.61    MB    Mounted File system   - unmirrored
  27.   /home                  using   .38        MB    Mounted File system   - unmirrored
  28.   /opt                   using   205.45     MB    Mounted File system   - unmirrored
  29.   /admin                 using   .37        MB    Mounted File system   - unmirrored
  30.   /var/adm/ras/livedump  using   .36        MB    Mounted File system   - unmirrored
  31.   /application           using   211.02     MB    Mounted File system   - mirrored * 3
  32.                          Total:  8977.91    MB
  33.  
  34. ----------------------------------------------
  35.  
  36.  Total used space for all VG's:  10101.31   MB

Put Your Knowledge to Work

In this article, we examined how to look at total space, used space, and available space at each level of the LVM: physical volumes, volume groups, logical volumes, and file systems. Equipped with this knowledge, you should now be able to better manage available disk space on your AIX systems.

Please or Register to post comments.

AIX User-Related Commands

Download AIX User-Related Commands (Infographic) today! This quick guide highlights differences between user administration commands on AIX and other UNIX-derived operating systems.


POWER IT Pro Blogs
LPI Exam Objective 101.3: Runlevels, Shutdown, and Reboot
May 13, 2013
blog

LPI Exam Objective 101.3: Runlevels, Shutdown, and Reboot

This entry in the LPI certification exam blog series discusses the third objective in the System Architecture topic of the exam: Linux runlevels, and shutdown and reboot procedures....More
May 13, 2013
blog

Feedback Loop

I had more feedback from readers to my article, "The Forgotten", than practically anything I have written before. If you missed it, it told the story of a conversation I had with the financial director a mid-sized British food retailer....More
May 13, 2013
blog

COMMON Europe Cancels Flagship Conference

COMMON Europe has cancelled its flagship annual conference, due to be held next month in Annecy, south-eastern France....More
eBooks & Training
Secrets of an AIX Administrator by Christian Pruett
Dec. 13, 2012
Datasheet

Secrets of an AIX Administrator  

Download this Tech Advisor from POWER IT Pro and learn practical, real-world information about AIX administration. Christian Pruett shares all the things he wishes he had known about AIX before becoming an admin in his ebook Secrets of an AIX Administrator....More
Dec. 3, 2012
Datasheet

AIX Security  

IBM i has extremely robust intrinsic security, and Linux, although much less secure than either AIX or IBM i, has many more eyes watching for problems. But AIX has some significant corner cases where security can be breached if you're not careful....More