-2

How to check if a disk is in use? If in use, How to check free, used space before I can start using it?

I'm trying this in Perl and Any help is appreciated.

  • 2
    What do you mean by "a disk in use"? Are you looking for open files? Or the disk being mounted somewhere? Having certain partitions? – Bram Jun 18 '12 at 19:21
  • @Bram - I'm looking for disk partitions whilst created as logical volumes under a volume group. – doubledecker Jun 19 '12 at 8:52
  • sorry but I can't make heads or tails of that statement. Do you want to know which partitions are used as "physical volumes" in a volume group? Or file systems created on a logical volume? AFAIK you can't create a partition on a logical volume and it certainly wouldn't make much sense if you could. Perhaps it helps if you edit your question explaining how you do this manually. That might make it easier for people to help you script it in any language. – Bram Jun 19 '12 at 14:58
2

pvdisplay will show you which disks and partitions are "in use" for volume-groups

Use lvs to get a summary of all configured LVs. LVs that are in use have normally the "ao" attribute set. LVs with just "a" are active, but not currently in use. Use blkid to see which filesystems are where. Use df -h to see the currently mounted filesystems and their human-readable sizes.

  • Huge assumption on OP using LVM. – karatedog Sep 30 at 8:08
  • I'm will delete my comment, I haven't read the OP's first comment, which clearly describes LV and VG. – karatedog Oct 17 at 5:02
1

I always do lsof | grep file/filesystem to list open or "in use" files.

Human readable output of "df" might be helpful as well: df -h /mountpoint

1

I am using next command to check is disk in use:

vmstat -d | head -1 ; vmstat -d 1 | grep sda

(where is sda disk name)

0

fuser -m /path/to/mountpoint works in shell to show if a disk is use. You could do a system() call from Perl

df /path/to/mountpoint tells you about disk space

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.