lvm-usage v4.51 [05 May 2024] by Dominic
Description
For GNU/Linux systems using LVM (Logical Volume Management), shows usage of:
- LVM Physical Volumes (PVs)
- LVM Volume Groups (VGs)
- LVM Logical Volumes (LVs)
And for all systems (using LVM or not) it shows usage of:
- Mounted filesystems
- Physical disk partitions
It also gives a localised example showing how space could be added using LVM. When run with '-q' option it will be silent unless any filesystem's level of usage is over the specified percent_trigger, and so it can be used to issue a warning if running out of space.
With '-f' option, it shows in a tree format the usage of the filesystem (if any) that is above percent_trigger level or, if none, then /home.
Suggested use is as a cron job with e.g. -q 75 (percent_trigger is ignored without -q switch.) Note that if run with '-f' option it can take many minutes to complete.
All sizes are reported in binary quantities e.g. gibibytes i.e. powers of 1024 not 1000.
Oh, and it runs happily on systems that do not have or use LVM, too.
Usage
lvm-usage.sh [options] [percent_trigger]
Example
Options
-b show size and location of physical partitions in bytes
-f show full tree usage of the first volume with usage over percent_trigger (default /home)
-h shows these instructions and exit
-i use ascii characters for tree
-l show changelog and exit
-q suppress output unless usage is over percent_trigger (default 0%)
Dependencies
awk bash coreutils grep linux-utils parted sed optional:util-linux_(for_lsblk)
License
Copyright © 2024 Dominic Raferd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Changelog
4.51 [05 May 2024] - bugfix for sdnx_crypt devices
4.50 [03 May 2024] - bugfix for nvme devices, closer shellcheck compliance, stop using swapon -s which was, better lv name identification
4.42 [11 Sep 2023] - stop having lines in body that end in a colon (attempt to prevent breaking DKIM)
4.41 [19 Jan 2021] - limit line length (when listing directory contents) so if output is emailed it does not break DKIM
4.40 [18 May 2020] - alter -f so (a) it is based on the first-listed volume that was over percent_trigger, default /home, rather than only ever /home, and (b) it excludes directories on different file systems
4.34 [01 Aug 2018] - bugfix, with newer 'df' was always remounting /tmp
4.33 [16 Sep 2017] - ignore loop devices in listing of physical devices
4.32 [28 Oct 2016] - ignore /dev/loop devices
4.31 [11 Aug 2016] - add name and ip of machine to output
4.30 [18 Mar 2016] - remove all use of fdisk to make GPT-disk-compatible
4.26 [14 Dec 2015] - don't warn about 'full' iso9660 fs
4.25 [22 Sep 2015] - add -i option
4.24 [18 Aug 2015] - fix some PATH problems on some os (e.g. Centos 5), restore ability to work without lsblk (also missing on Centos 5)
4.23 [21 Jul 2015] - add swap info and include all filesystems
4.22 [20 Jul 2015] - output layout improvement
4.21 [04 May 2015] - corrected/simplified list of dependencies
4.20 [04 Apr 2015] - consistently use powers of 1024, lsblk instead of fdisk
4.14 [16 Mar 2015] - simplified/improved resizing example
4.13 [26 Feb 2015] - add example for resizing with btrfs
4.12 [21 Feb 2015] - minor layout improvement
4.11 [03 Feb 2015] - include tmpfs filesystems in report
4.10 [16 Jan 2015] - use mktemp, recreate/mount /tmp read-write if it is currently read-only
4.03 [05 Mar 2014] - remove extraneous sudo
4.02 [02 Mar 2014] - improved layout
4.0110 [10 Jan 2014] - minor fix
3.1117 [17 Nov 2013] - also exclude tmpfs & devtmpfs filesystems, add listing of physical partitions
3.0611 [11 June 2013] - also exclude shmfs filesystems
2.0807 [07 Aug 2012] - also exclude ecryptfs filesystems from output
2.0717 [17 Jul 2012] - minor correction for output wording
2.0513 [13 May 2012] - improved example text
2.0430 [30 Apr 2012] - when analysing /home, show files + directories over 1GB
2.0426 [26 Apr 2012] - improved example text
2.0417 [19 Apr 2012] - improved localised example for adding PV to VG
2.0412 [12 Apr 2012] - correctly remove temporary files in quiet mode
2.0219 [19 Feb 2012] - work smoothly if no LVM-mapped filesystems, bugfix, improved help, rename as 'lvm-usage.sh'
2.0216 [16 Feb 2012] - change -f fast option to -f full
2.0214 [14 Feb 2012] - exclude 'iso9660', include 'none' filesystems
2.0209 [09 Feb 2012] - provide localised examples in help text, add listing and checking of non-LVM filesystems
2.0125 [25 Jan 2012] - minor correction in help text
2.0117 [17 Jan 2012] - trivial elucidation in help text
2.0106 [06 Jan 2012] - fix for VG containing dash in name, add -f option
1.1231 [31 Dec 2011] - changed text
Download lvm-usage.sh
Donation
I have provided this software free gratis and for nothing. If you would like to thank me with a contribution, please let me know and I will send you a link. Thank you!
My Other Sites
- TimeDicer - Onsite/offsite data backup for Windows (uses rdiff-backup)
- Finding a 4D Backup Solution
- Web Scraping How To - extracting data from web sites
My Programs
Here is a selection of some (other) programs I have written, most of which run under GNU/Linux from the command line (CLI), are freely available and can be obtained by clicking on the links. Dependencies are shown and while in most cases written and tested on an x86-based Linux server, they should run on a Raspberry Pi, and many can run under Windows using Windows Subsystem for Linux (WSL) or Cygwin. Email me if you have problems or questions, or if you think I could help with a programming requirement.
Backup Utilities
- TimeDicer - Onsite/offsite data backup for Windows (uses rdiff-backup) [ GNU/Linux & MS Windows©: 2008-20 ]
- rdiff-backup-regress - GNU/Linux script to regress an rdiff-backup archive. [ GNU/Linux: 2012-24 ]
Debian/Ubuntu kernel and LVM Utilities
- kernel-remove - GNU/Linux script to list the installed GNU/Linux kernels in a Debian-based distro (e.g. Ubuntu), and can be used to remove an unwanted kernel and related packages, updating grub appropriately. [ GNU/Linux-Debian/Ubuntu: 2010-24 ]
- lvm-delete-snapshot - GNU/Linux script to remove LVM snapshot that has been left over by another process. [ GNU/Linux: 2012-21 ]
- netnames - GNU/Linux script shows current name, biosdevname and 'predictable name' of network device - helps with network device name scheme migration. [ GNU/Linux-Debian/Ubuntu: 2020-20 ]
- lv-convert2cache - GNU/Linux script to convert an existing LV into a cache LV using a smaller faster device as a cache. [ GNU/Linux: 2022-24 ]
Miscellaneous Programs
- sleepwalker - Windows© program which can be run from a remote machine to 'wake up' a Windows© machine behind a router, wait for it to start and then initiate Remote Desktop session. [MS Windows©: 2008-22]
- numliststat - GNU/Linux program giving statistical value(s) for a piped-in list of numbers. [ GNU/Linux: 2022-24 ]
- relay-enforcer - GNU/Linux program enabling a postfix-based mail server relaying to Gmail to act on reports from Gmail about blocked emails. [ GNU/Linux: 2016-24 ]
- pdf-compress - GNU/Linux program to create smaller b/w pdf file from an original large pdf file, especially when original resulted from scanning. [ GNU/Linux: 2016-24 ]
- tiny-device-monitor - GNU/Linux program to test webpages (including password-protected) or machines to check they are live; use as a cron job for your own websites, for hardware presenting a webpage, or for any machines with a presence on your local LAN or on the internet. [ GNU/Linux: 2009-24 ]
- form-extractor - GNU/Linux program to extract form tags from a web page or downloaded file. [ GNU/Linux: 2012-24 ]
- mythic-dns-sync - GNU/Linux program to update DNS record at mythic-beasts.com to match local external ip. [ GNU/Linux: 2016-23 ]
- saynoto0870 - For UK, a GNU/Linux script which performs automated lookup of the www.saynoto0870.com database, finding cheap or free geographic number replacements for expensive non-geographic (087* or 084*) numbers. [ GNU/Linux: 2012-12 ]
- bind9-resolved-switch - GNU/Linux program for switching permanently between using bind9 or systemd-resolved as the system DNS resolver. [ GNU/Linux: 2016-24 ]
- unlock - GNU/Linux remote program for easy entering of decrypt passphrase on a remote machine which has root dm-crypt+LUKS. [ GNU/Linux: 2017-18 ]
- wifi-updown - GNU/Linux program to take down wifi interface if there is a working wired interface (or restore wifi if not). [ GNU/Linux: 2018-23 ]
- routefix - GNU/Linux program to restore a default ip traffic route if there is none such (e.g. after running wifi-updown). [ GNU/Linux: 2018-23 ]
- dutree - GNU/Linux program to show a tree-style list of files and directories at the specified location which are greater than the specified size (default 1GB). [ GNU/Linux: 2012-24 ]
- Accounts - Multi-business multi-currency accounting software, uses Access [MS Windows©: 1996-2024]
- Rents Program - Residential lettings/landlord front office program, with many special features for UK market [MS Windows©: 1991-2024]
This section is closed. If you have a question, please submit it by email, thank you.