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.
pvdisplay will show you which disks and partitions are "in use" for volume-groups
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.
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
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)
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