TopL TopM TopR
MiddleL

How to List File Systems by Volume Group

Sometimes it's useful to be able to run a command just for the file systems in one volume group. You might want to do a file system backup or maybe check disk space for some file systems using df or du. Perhaps you'd like to search just for files that are in a data volume group, and you want to skip the OS file systems in rootvg. So, how do you go about getting the list of file systems you want?

You have a few options. You could:

  • - list the volume group's logical volumes with lsvg -l vgname, and then exclude paging space devices, log devices, system dump devices, and boot devices
  • - run df and capture the last column with awk, then eliminate the file systems you don't want to work on
  • - keep a list of file systems in a configuration file
  • - list file systems by volume group using lsvgfs

That last option is the one I prefer. The lsvgfs command gives you all the file system mount points in a volume group, and it doesn't require filtering the output as the first two methods above do. Plus, with lsvgfs you don't have to keep a configuration file up to date every time a file system gets created or deleted.

Simple Syntax, Simple Output

The syntax for lsvgfs is very simple: just append the volume group name.

lsvgfs datavg
 
/usr/local/logs
/reports
/reports/acme

The output is also very simple: you just see the file system mount points. This can be pretty handy. For example, you can use lsvgfs to display file system space information just for the datavg file systems:

df -g $(lsvgfs datavg)
 
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/dev/logslv       20.00     10.66   47%    31339     2% /usr/local/logs
/dev/reportslv     10.00      9.96    1%        4     1% /reports
/dev/acmelv       4.00      2.56   36%      677     1% /reports/acme

That works because df can take a list of file systems or directories as its argument.

Run find for datavg File Systems

Using lsvgfs is also helpful for searching through file systems that all belong to the one volume group. That's because find can have multiple directories as starting points. Here's how to find all the files in datavg:

find $(lsvgfs datavg) -xdev -print

The -xdev ensures that when the find command is searching a parent file system such as /reports, it won't search through nested file systems such as /reports/acme.

Of course, you can narrow down the search by using other options on the find command such as -name, -mtime and so on. You could use other options of find to run a backup or some other command. See the Resources section below for more details on the find command.

Loop Through Each File System

If you want to run a command on each file system one at a time, you can create a simple script. Here's how to display total disk usage in GB (using du -gs) for file systems in datavg:

for $fs in $(lsvgfs datavg)
do
du -gsx $fs
# The -x flag will keep to the current file system and not report on nested file systems
done

All File Systems in All Volume Groups

If you have several volume groups, you can enhance the script. First list all the active volume groups using lsvg, then run lsvgfs for each volume group so that you can identify that volume group's file systems.

for vg in $(lsvg)
do
     for fs in $(lsvgfs $vg)
     do
           # Insert the command to run on each file system. It might be a backup,
           # a find command, or maybe fsck to run a file system check
     done
done

Exclude rootvg

If you're doing a file system backup, you may want to skip all the rootvg file systems, since they're already backed up with the mksysb command (unless you're excluding some using mksysb -e).

A slight amendment to the script above will list all non-rootvg file systems. When you get a list of volume groups, you can exclude rootvg by using grep -vw. The -v displays output that doesn't match the pattern 'rootvg'. And the -w looks for an exact word match so that you don't miss out on volume groups called rootvg2 or beetrootvg.

for vg in $(lsvg | grep -vw rootvg)
do
      for fs in $(lsvgfs $vg)
      do
           find $fs -xdev -print | backup -ivqf /archive/${fs}.bkp
           # The -xdev flag stops the find command from traversing nested file systems
      done
done

This simple script will use the mount points of all local (non-NFS) file systems for all volume groups (except rootvg). If you have several user volume groups, this script will find them all and their file systems. And if your logical partition only has rootvg, and no user volume groups such as datavg, there won't be any file systems to find.

Practical Uses for lsvgfs

Here are some other ways where lsvgfs can be of service:

Unmount all file systems. If you plan to move an entire volume group to a new logical partition, you first have to unmount all of the volume group's file systems. First list the file systems with lsvgfs, then run umount on each one.

Be careful of nested file systems. You have to unmount the child file system (e.g. /reports/acme) before you can unmount the parent file system (/reports). When you're ready to import the volume group and mount the file systems again, mount the parent first. For more details on how to move data quickly between AIX logical partitions using the Logical Volume Manager, see Resources below.

File system check (fsck). If you need to run fsck on each file system in a volume group, you can use the file system mount point (e.g. fsck –y /somefs) instead of the logical volume device (fsck –y /dev/lv15). Here are the commands you’d use to unmount a file system, run a file system check, and then mount the file system again.

for fs in $(lsvgfs datavg)
do
      umount $fs
      fsck -y $fs
      mount $fs
done

The same rules apply for nested file systems as in the previous example.

Change file system characteristics. You can change the characteristics of all file systems using chfs. For example, you can assign the file systems in a volume group to a mount group:

for fs in $(lsvgfs datavg)
do
      chfs -u datafs $fs
done

and then mount the entire group using mount -t datafs. Use umount -t datafs to unmount them all.

Simple and Smart

The lsvgfs command is very helpful when you want to run a command on all file systems in a volume group. Simple syntax, simple output is what makes lsvgfs a smart and handy tool to have.

Resources:

Anthony English is an AIX / Power Systems engineer working in Sydney. Follow him on Twitter @AIXDownUnder.

Comments

Was it good for you, too?Join the discussion » ,but you need to login first before you make comments.

     

    Other Recent Comments

    1. Re: Easy Ways to Trace VSCSI Configuration with AIX

      No Anthony, it's not so obvious. As you see, I've removed first paths and after that I changed vscsi...

      --Andrey Klyachkin

    2. Re: Easy Ways to Trace VSCSI Configuration with AIX

      Thanks, Andrey. Your test shows that if one path is down, then its corresponding VSCSI adapter isn't...

      --Anthony English

    3. Re: Easy Ways to Trace VSCSI Configuration with AIX

      Test with rmpath/cvai:# lspath -l hdisk1 -F parentvscsi0vscsi1# lspath -l hdisk0 -F parentvscsi0vscs...

      --Andrey Klyachkin

    4. Re: IBM Reveals PowerLinux Details and Pricing

      Thanks for the tip, Bill -- much appreciated! (I must say, though, we'll have to wrangle a few Power...

      --Chris Maxcer

    5. Re: IBM Reveals PowerLinux Details and Pricing

      http://www.ibm.com/developerworks/group/tpl

      --Bill Buros

    Google Links

    Sponsored Links

    Featured Links

    MiddleR
    BottomL BottomM BottomR

    © Penton Media, Inc.