With 'lsblk' I can get something like this: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part ├─vg0-root 253:0 0 15G 0 lvm / └─vg0-var 253:1 0 5G 0 lvm /var sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─vg1-data 253:2 0 100G 0 lvm /mnt/data sr0 11:0 1 1024M 0 rom
What I'm looking for is output like: / 15G /var 5G /mnt/data 100G
So I just want the size of the block devices which are actually mounted. I'm wondering what is the most reliable way to produce the second output. I can just grep for 'lvm', but I can't guarantee the mounts are all LVM type. I can grep for ' 253:', but is the 253 going to be reliable? What does 253 even mean?
From https://www.kernel.org/doc/html/latest/admin-guide/devices.html :
240-254 block LOCAL/EXPERIMENTAL USE Allocated for local/experimental use. For devices not assigned official numbers, these ranges should be used in order to avoid conflicting with future assignments.
... which isn't encouraging. Is that list outdated? grep for '/'s?
Doesn’t df -h give that info? Sorry if I misunderstood your question.
Sent from my iPhone
On Feb 21, 2024, at 16:36, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
With 'lsblk' I can get something like this: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part ├─vg0-root 253:0 0 15G 0 lvm / └─vg0-var 253:1 0 5G 0 lvm /var sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─vg1-data 253:2 0 100G 0 lvm /mnt/data sr0 11:0 1 1024M 0 rom
What I'm looking for is output like: / 15G /var 5G /mnt/data 100G
So I just want the size of the block devices which are actually mounted. I'm wondering what is the most reliable way to produce the second output. I can just grep for 'lvm', but I can't guarantee the mounts are all LVM type. I can grep for ' 253:', but is the 253 going to be reliable? What does 253 even mean?
From https://www.kernel.org/doc/html/latest/admin-guide/devices.html : 240-254 block LOCAL/EXPERIMENTAL USE Allocated for local/experimental use. For devices not assigned official numbers, these ranges should be used in order to avoid conflicting with future assignments. ... which isn't encouraging. Is that list outdated? grep for '/'s?
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Fair question. On the same system, df -h gives: Filesystem Size Used Avail Use% Mounted on udev 465M 0 465M 0% /dev tmpfs 99M 7.8M 91M 8% /run /dev/mapper/vg0-root 15G 3.3G 12G 22% / tmpfs 493M 0 493M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/mapper/vg1-data 98G 61M 93G 1% /mnt/data /dev/mapper/vg0-var 5.0G 956M 4.1G 19% /var tmpfs 99M 0 99M 0% /run/user/1000
Where '/' and 'var' are correct, but /mnt/data shows as 98G instead of 100G. I'm looking for the disk sizes, not the file system sizes.
This is actually a VM, and I can get the exact disk sizes from VMware... but not the mount points. And since / and /var are on the same disk, the VMware info lacks the detail I need.
Major device 253 seems to be used for LVM devices, so assuming that misses things like "sda2 8:2 0 2G 0 part /boot", which I'd also like to account for. Another system, for example, has NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 48G 0 part ├─ubuntu--vg-root 253:0 0 24G 0 lvm / └─ubuntu--vg-var 253:1 0 24G 0 lvm /var sr0 11:0 1 1024M 0 rom
And from that I would want /boot 2G / 24G /var 24G which adds up to 50G (sda)
lsblk -e 7 | grep '/' | awk '{ print $NF, $4 }' basically works (for my sample of two systems), but I don't know how reliable assuming grep '/' is going to be for what I want.
On Wed, Feb 21, 2024 at 4:44 PM Vijay Sankar vsankar@foretell.ca wrote:
Doesn’t df -h give that info? Sorry if I misunderstood your question.
Sent from my iPhone
On Feb 21, 2024, at 16:36, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
With 'lsblk' I can get something like this: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part ├─vg0-root 253:0 0 15G 0 lvm / └─vg0-var 253:1 0 5G 0 lvm /var sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─vg1-data 253:2 0 100G 0 lvm /mnt/data sr0 11:0 1 1024M 0 rom
What I'm looking for is output like: / 15G /var 5G /mnt/data 100G
So I just want the size of the block devices which are actually mounted. I'm wondering what is the most reliable way to produce the second output. I can just grep for 'lvm', but I can't guarantee the mounts are all LVM type. I can grep for ' 253:', but is the 253 going to be reliable? What does 253 even mean?
From https://www.kernel.org/doc/html/latest/admin-guide/devices.html :
240-254 block LOCAL/EXPERIMENTAL USE Allocated for local/experimental use. For devices not assigned official numbers, these ranges should be used in order to avoid conflicting with future assignments.
... which isn't encouraging. Is that list outdated? grep for '/'s?
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
No worries. I’d just use whatever, but I’m trying to come up with something I can use via Ansible across a couple of hundred machines. I need precise numbers for work reasons. 🙂
On Wed, Feb 21, 2024 at 18:47 Vijay Sankar vsankar@foretell.ca wrote:
Thanks for the explanation Kevin and sorry for the noise. I tend to use disklabel to see the size of each partition or physical disk info and df just to see how much is on each mount point as my needs are quite trivial. However, I am an OpenBSD user and don’t know as much about Linux etc.
Sent from my iPhone
On Feb 21, 2024, at 18:23, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
Fair question. On the same system, df -h gives: Filesystem Size Used Avail Use% Mounted on udev 465M 0 465M 0% /dev tmpfs 99M 7.8M 91M 8% /run /dev/mapper/vg0-root 15G 3.3G 12G 22% / tmpfs 493M 0 493M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/mapper/vg1-data 98G 61M 93G 1% /mnt/data /dev/mapper/vg0-var 5.0G 956M 4.1G 19% /var tmpfs 99M 0 99M 0% /run/user/1000
Where '/' and 'var' are correct, but /mnt/data shows as 98G instead of 100G. I'm looking for the disk sizes, not the file system sizes.
This is actually a VM, and I can get the exact disk sizes from VMware... but not the mount points. And since / and /var are on the same disk, the VMware info lacks the detail I need.
Major device 253 seems to be used for LVM devices, so assuming that misses things like "sda2 8:2 0 2G 0 part /boot", which I'd also like to account for. Another system, for example, has NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 48G 0 part ├─ubuntu--vg-root 253:0 0 24G 0 lvm / └─ubuntu--vg-var 253:1 0 24G 0 lvm /var sr0 11:0 1 1024M 0 rom
And from that I would want /boot 2G / 24G /var 24G which adds up to 50G (sda)
lsblk -e 7 | grep '/' | awk '{ print $NF, $4 }' basically works (for my sample of two systems), but I don't know how reliable assuming grep '/' is going to be for what I want.
On Wed, Feb 21, 2024 at 4:44 PM Vijay Sankar vsankar@foretell.ca wrote:
Doesn’t df -h give that info? Sorry if I misunderstood your question.
Sent from my iPhone
On Feb 21, 2024, at 16:36, Kevin McGregor kevin.a.mcgregor@gmail.com wrote:
With 'lsblk' I can get something like this: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part ├─vg0-root 253:0 0 15G 0 lvm / └─vg0-var 253:1 0 5G 0 lvm /var sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─vg1-data 253:2 0 100G 0 lvm /mnt/data sr0 11:0 1 1024M 0 rom
What I'm looking for is output like: / 15G /var 5G /mnt/data 100G
So I just want the size of the block devices which are actually mounted. I'm wondering what is the most reliable way to produce the second output. I can just grep for 'lvm', but I can't guarantee the mounts are all LVM type. I can grep for ' 253:', but is the 253 going to be reliable? What does 253 even mean?
From https://www.kernel.org/doc/html/latest/admin-guide/devices.html :
240-254 block LOCAL/EXPERIMENTAL USE Allocated for local/experimental use. For devices not assigned official numbers, these ranges should be used in order to avoid conflicting with future assignments.
... which isn't encouraging. Is that list outdated? grep for '/'s?
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
Roundtable mailing list Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable
If you’re using awk anyway: lsblk -b -r | awk 'NR>1 && $7 {print $1,$4}' appears to do the trick. Unfortunately, it doesn’t do the VG/LV to dm-X translation for you, and using -l instead of -r doesn’t really work either b/c of the rather silly column formatting lsblk does – there’s a SPACE in the middle of the first column, gee, thanks.
The lsblk(8) manpage notes that it pulls all of its information from sysfs, so I imagine you could fairly easily do exactly the same, targeting only the info you really want.
Finally, note that in your example, 98G is correct as the “disk” size – to get that result from df, you *must* have an LV that’s 98G, and the LV is the “disk” as far as the filesystem is concerned. There are many reasons this can happen, but I guarantee you can’t actually put 100G of user data on that filesystem. I do this deliberately, but alignment issues or metadata can sometimes chew up a bit of space, too. Cross-check against the output of lvscan(8) and if that reports 100G, let us know – and also file a bug with the vendor!
If you use df, I would suggest an invocation such as df -lm | awk '/^/dev/ && $2>1 {print $6,$1,$2}' depending on which bits of info you want.
-Adam
From: Roundtable roundtable-bounces@muug.ca On Behalf Of Kevin McGregor Sent: Wednesday, February 21, 2024 7:41 PM To: Continuation of Round Table discussion roundtable@muug.ca Subject: Re: [RndTbl] Getting disk sizes of mountpoints
No worries. I’d just use whatever, but I’m trying to come up with something I can use via Ansible across a couple of hundred machines. I need precise numbers for work reasons. 🙂
On Wed, Feb 21, 2024 at 18:47 Vijay Sankar <vsankar@foretell.camailto:vsankar@foretell.ca> wrote: Thanks for the explanation Kevin and sorry for the noise. I tend to use disklabel to see the size of each partition or physical disk info and df just to see how much is on each mount point as my needs are quite trivial. However, I am an OpenBSD user and don’t know as much about Linux etc.
Sent from my iPhone
On Feb 21, 2024, at 18:23, Kevin McGregor <kevin.a.mcgregor@gmail.commailto:kevin.a.mcgregor@gmail.com> wrote: Fair question. On the same system, df -h gives: Filesystem Size Used Avail Use% Mounted on udev 465M 0 465M 0% /dev tmpfs 99M 7.8M 91M 8% /run /dev/mapper/vg0-root 15G 3.3G 12G 22% / tmpfs 493M 0 493M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/mapper/vg1-data 98G 61M 93G 1% /mnt/data /dev/mapper/vg0-var 5.0G 956M 4.1G 19% /var tmpfs 99M 0 99M 0% /run/user/1000
Where '/' and 'var' are correct, but /mnt/data shows as 98G instead of 100G. I'm looking for the disk sizes, not the file system sizes.
This is actually a VM, and I can get the exact disk sizes from VMware... but not the mount points. And since / and /var are on the same disk, the VMware info lacks the detail I need.
Major device 253 seems to be used for LVM devices, so assuming that misses things like "sda2 8:2 0 2G 0 part /boot", which I'd also like to account for. Another system, for example, has NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 48G 0 part ├─ubuntu--vg-root 253:0 0 24G 0 lvm / └─ubuntu--vg-var 253:1 0 24G 0 lvm /var sr0 11:0 1 1024M 0 rom
And from that I would want /boot 2G / 24G /var 24G which adds up to 50G (sda)
lsblk -e 7 | grep '/' | awk '{ print $NF, $4 }' basically works (for my sample of two systems), but I don't know how reliable assuming grep '/' is going to be for what I want.
On Wed, Feb 21, 2024 at 4:44 PM Vijay Sankar <vsankar@foretell.camailto:vsankar@foretell.ca> wrote: Doesn’t df -h give that info? Sorry if I misunderstood your question.
Sent from my iPhone
On Feb 21, 2024, at 16:36, Kevin McGregor <kevin.a.mcgregor@gmail.commailto:kevin.a.mcgregor@gmail.com> wrote: With 'lsblk' I can get something like this: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part ├─vg0-root 253:0 0 15G 0 lvm / └─vg0-var 253:1 0 5G 0 lvm /var sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─vg1-data 253:2 0 100G 0 lvm /mnt/data sr0 11:0 1 1024M 0 rom
What I'm looking for is output like: / 15G /var 5G /mnt/data 100G
So I just want the size of the block devices which are actually mounted. I'm wondering what is the most reliable way to produce the second output. I can just grep for 'lvm', but I can't guarantee the mounts are all LVM type. I can grep for ' 253:', but is the 253 going to be reliable? What does 253 even mean?
From https://www.kernel.org/doc/html/latest/admin-guide/devices.html :
240-254 block LOCAL/EXPERIMENTAL USE
Allocated for local/experimental use. For devices not
assigned official numbers, these ranges should be
used in order to avoid conflicting with future assignments. ... which isn't encouraging. Is that list outdated? grep for '/'s?
_______________________________________________ Roundtable mailing list Roundtable@muug.camailto:Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable _______________________________________________ Roundtable mailing list Roundtable@muug.camailto:Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable _______________________________________________ Roundtable mailing list Roundtable@muug.camailto:Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable _______________________________________________ Roundtable mailing list Roundtable@muug.camailto:Roundtable@muug.ca https://muug.ca/mailman/listinfo/roundtable