1

This question is essentially the opposite of the first question below, and adjacently related to the second question, and is therefore not a duplicate:

  1. Ask Ubuntu: How do I find out what filesystem my partitions are using?
  2. Unix & Linux: How to tell what type of filesystem you're on?

df -h shows my filesystems. Ex:

$ df -h
Filesystem                 Size  Used Avail Use% Mounted on
udev                       7.7G     0  7.7G   0% /dev
tmpfs                      1.6G  2.3M  1.6G   1% /run
/dev/mapper/vgubuntu-root  467G  410G   33G  93% /
tmpfs                      7.8G  139M  7.7G   2% /dev/shm
tmpfs                      5.0M  4.0K  5.0M   1% /run/lock
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/loop0                 9.0M  9.0M     0 100% /snap/canonical-livepatch/146
/dev/loop1                 128K  128K     0 100% /snap/bare/5
/dev/loop2                 165M  165M     0 100% /snap/gnome-3-28-1804/161
/dev/loop3                  82M   82M     0 100% /snap/gtk-common-themes/1534
/dev/loop9                 291M  291M     0 100% /snap/vault/2012
/dev/loop10                 46M   46M     0 100% /snap/snap-store/638
/dev/loop7                 347M  347M     0 100% /snap/gnome-3-38-2004/115
/dev/sda2                  704M  305M  348M  47% /boot
/dev/loop6                  43M   43M     0 100% /snap/leafpad/91
/dev/loop8                 321M  321M     0 100% /snap/vlc/3078
/dev/loop11                 46M   46M     0 100% /snap/snap-store/599
/dev/loop16                219M  219M     0 100% /snap/gnome-3-34-1804/72
/dev/loop13                117M  117M     0 100% /snap/core/14399
/dev/loop15                296M  296M     0 100% /snap/vlc/2344
/dev/sda1                  511M   26M  486M   6% /boot/efi
/dev/loop14                 64M   64M     0 100% /snap/core20/1738
/dev/loop12                 92M   92M     0 100% /snap/gtk-common-themes/1535
/dev/loop17                219M  219M     0 100% /snap/gnome-3-34-1804/77
/dev/loop19                256K  256K     0 100% /snap/gtk2-common-themes/13
/dev/loop21                9.0M  9.0M     0 100% /snap/canonical-livepatch/164
/dev/loop18                 50M   50M     0 100% /snap/snapd/17883
/dev/loop23                347M  347M     0 100% /snap/gnome-3-38-2004/119
/dev/loop20                163M  163M     0 100% /snap/gnome-3-28-1804/145
tmpfs                      1.6G  196K  1.6G   1% /run/user/1000
/dev/loop24                 56M   56M     0 100% /snap/core18/2667
/dev/loop25                 64M   64M     0 100% /snap/core20/1778
/dev/loop4                 117M  117M     0 100% /snap/core/14447
/dev/loop5                  50M   50M     0 100% /snap/snapd/17950
/dev/loop26                 56M   56M     0 100% /snap/core18/2679

I want to know which partition each filesystem is on, in particular my root filesystem mounted at /. I'd also like to know how full each partition is.

How can I find this out? Using GUI tools to prove that your command-line tools worked is ok, but ultimately I need command-line tools as I need to run this on minimalistic remote embedded Linux edge devices.

3 Answers3

0

I figured out at least one way. Other answers are welcome.

Summary

My / root mount point is on the /dev/sda3 partition (as seen at the bottom of lsblk).

And, my /dev/sda3 partition is about (410 GiB (used in vgubuntu-root, as shown by df -h) + 0.980 GiB (used in vgubuntu-swap, as shown by lsblk))/(475.7 GiB (total in sda3, as shown by lsblk)) = 410.98/475.7 = 86.4% full.

Key partition or filesystem-related commands:

# get disk usage and see mount points (but not partitions :()
df -h

see which partition your filesystems are on, and how big they are

lsblk

and on embedded Linux devices with BusyBox:

mountpoint -n /

---------------------

and maybe useful

blkid

see also

sudo fdisk -l

get additional partition info for /dev/sda3

sudo fdisk -l /dev/sda3

Details

The end of lsblk shows all of my partitions, their size, and which mount point they are mounted to. On my Ubuntu 20.04 machine, notice the part beginning with sda near the end. That's where my physical partitions start:

$ lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
loop0                   7:0    0     9M  1 loop  /snap/canonical-livepatch/146
loop1                   7:1    0     4K  1 loop  /snap/bare/5
loop2                   7:2    0 164.8M  1 loop  /snap/gnome-3-28-1804/161
loop3                   7:3    0  81.3M  1 loop  /snap/gtk-common-themes/1534
loop4                   7:4    0 116.7M  1 loop  /snap/core/14447
loop5                   7:5    0  49.8M  1 loop  /snap/snapd/17950
loop6                   7:6    0  42.7M  1 loop  /snap/leafpad/91
loop7                   7:7    0 346.3M  1 loop  /snap/gnome-3-38-2004/115
loop8                   7:8    0 320.4M  1 loop  /snap/vlc/3078
loop9                   7:9    0 290.1M  1 loop  /snap/vault/2012
loop10                  7:10   0    46M  1 loop  /snap/snap-store/638
loop11                  7:11   0  45.9M  1 loop  /snap/snap-store/599
loop12                  7:12   0  91.7M  1 loop  /snap/gtk-common-themes/1535
loop13                  7:13   0 116.7M  1 loop  /snap/core/14399
loop14                  7:14   0  63.2M  1 loop  /snap/core20/1738
loop15                  7:15   0 295.7M  1 loop  /snap/vlc/2344
loop16                  7:16   0   219M  1 loop  /snap/gnome-3-34-1804/72
loop17                  7:17   0   219M  1 loop  /snap/gnome-3-34-1804/77
loop18                  7:18   0  49.6M  1 loop  /snap/snapd/17883
loop19                  7:19   0   140K  1 loop  /snap/gtk2-common-themes/13
loop20                  7:20   0 162.9M  1 loop  /snap/gnome-3-28-1804/145
loop21                  7:21   0     9M  1 loop  /snap/canonical-livepatch/164
loop23                  7:23   0 346.3M  1 loop  /snap/gnome-3-38-2004/119
loop24                  7:24   0  55.6M  1 loop  /snap/core18/2667
loop25                  7:25   0  63.3M  1 loop  /snap/core20/1778
loop26                  7:26   0  55.6M  1 loop  /snap/core18/2679
sda                     8:0    0   477G  0 disk  
├─sda1                  8:1    0   512M  0 part  /boot/efi
├─sda2                  8:2    0   732M  0 part  /boot
└─sda3                  8:3    0 475.7G  0 part  
  └─sda3_crypt        253:0    0 475.7G  0 crypt 
    ├─vgubuntu-root   253:1    0 474.8G  0 lvm   /
    └─vgubuntu-swap_1 253:2    0   980M  0 lvm   [SWAP]

So, the root mount point (/) is on vgubuntu-root within partition sda3. Its full partition hierarchy is sda/sda3/sda3_crypt/vgubuntu-root. The gparted GUI confirms this and shows it like this:

enter image description here

On embedded Linux boards running BusyBox (Ubuntu doesn't have the -n option, for instance), you can also use mountpoint -n <mount_point>. Ex: mountpoint -n / would show something like this, confirming that the / filesystem mount point is on partition /dev/sda3:

$ mountpoint -n /
/dev/sda3 /

Again, on Ubuntu, the -n option doesn't exist, but on a board with BusyBox, the help menu when you run just mountpoint says:

# mountpoint
BusyBox v1.31.1 (2023-01-26 07:37:10 UTC) multi-call binary.

Usage: mountpoint [-q] <[-dn] DIR | -x DEVICE>

Check if the directory is a mountpoint

-q  Quiet
-d  Print major/minor device number of the filesystem
-n  Print device name of the filesystem
-x  Print major/minor device number of the blockdevice

So, -n will Print device name of the filesystem.

Now that we know from lsblk or mountpoint -n / that the partition for this filesystem (and root mountpoint) is /dev/sda3, we can get more partition info with:

sudo fdisk -l /dev/sda3

Example run and output:

$ sudo fdisk -l /dev/sda3
[sudo] password for gabriel: 
Disk /dev/sda3: 475.74 GiB, 510804361216 bytes, 997664768 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

The size is 475.74 GiB, as also previously shown by lsblk.

Previously from lsblk:

└─sda3                  8:3    0 475.7G  0 part  
  └─sda3_crypt        253:0    0 475.7G  0 crypt 
    ├─vgubuntu-root   253:1    0 474.8G  0 lvm   /
    └─vgubuntu-swap_1 253:2    0   980M  0 lvm   [SWAP]

So we can see my root filesystem mounted at / is only allotted 474.8 GiB of the 475.7 GiB total in partition /dev/sda3.

df -h from my question previously showed:

Filesystem                 Size  Used Avail Use% Mounted on
...
/dev/mapper/vgubuntu-root  467G  410G   33G  93% /

So, my /dev/sda3 partition is about (410 GiB (used in vgubuntu-root, as shown by df -h) + 0.980 GiB (used in vgubuntu-swap, as shown by lsblk))/(475.7 GiB (total in sda3, as shown by lsblk)) = 410.98/475.7 = 86.4% full.

0

You could use grep to show only the filesystems you're interested in. e.g.

$ df -h | grep ^/dev/ | grep -vE '^/dev/(loop|shm)'

Better yet, use awk (because piping grep into grep is kind of silly, and because awk can use boolean operators - e.g. AND &&, OR ||, and NOT ! - in patterns):

df -h | awk 'NR==1; /^\/dev\// && ! /^\/dev\/(loop|shm)/'

This prints the first line (the header) and any line starting with /dev/ except for those with /dev/shm or /dev/loop. On your system, with the sample df -h output you posted, it would show:

$ awk 'NR==1; /^\/dev/ && ! /dev\/(loop|shm)/' /tmp/df-sample.txt
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/vgubuntu-root  467G  410G   33G  93% /
/dev/sda2                  704M  305M  348M  47% /boot
/dev/sda1                  511M   26M  486M   6% /boot/efi

Adjust the regular expressions to suit your needs.


NOTE: this won't work with any ZFS filesystems - they're mounted as pool/dataset, not from /dev. e.g. on my system with the rootfs and several other filesystems on pool "hex", as well as an mdadm raid1 ext4 for /boot and a FAT partition for /boot/efi (all of these are partitions on the same pair of identical NVME drives - contrary to what a lot of people think, ZFS works perfectly well with partitions, you don't have to give it entire disks):

$ df -Th
Filesystem                 Type  Size  Used  Avail  Use%  Mounted on
hex/ROOT                   zfs   243G  14G   229G   6%    /
/dev/md0                   ext4  2.0G  335M  1.5G   18%   /boot
/dev/nvme1n1p2             vfat  511M  49M   463M   10%   /boot/efi
hex/local                  zfs   230G  855M  229G   1%    /usr/local
hex/home                   zfs   257G  28G   229G   11%   /home
hex/var                    zfs   229G  128K  229G   1%    /var
...
...

But,since you know the pool name, you can adjust the regex to suit, e.g.:

df -h | awk 'NR==1; /^(\/dev|hex)/ && ! /dev\/(loop|shm)/'

or matching of the fs type (df -T):

df -Th | awk 'NR==1 || $2 ~ /zfs|btrfs|ext|fat|xfs/'

See also GNU df's -t option to limit what kind of filesystems will be displayed, and the -x option for excluding fs types.

cas
  • 78,579
0

I like this command - lsblk

fred@Z170-jammy:~$ lsblk -e 7 -o model,name,fstype,size,fsused,label,partlabel,mountpoint,uuid
MODEL NAME     FSTYPE   SIZE FSUSED LABEL  PARTLABEL          MOUNTPOINT UUID
HGST  sda             931.5G                                             
      ├─sda1   vfat   510.2M        ESP_B  EFI System Partition
      │                                                                  F496-1330
      ├─sda2   ext4    30.3G   6.1G hirsute
      │                                    hirsute            /media/fre 2888d7ab-23e4-4981-8566-7e23335be781
      ├─sda3   ext4    49.8G    40K ISO_b  ISO_b              /media/fre c395f36d-5e02-4913-a904-e336054b2eff
      ├─sda4   ext4   147.6G 115.6G backup_b
      │                                    backup_b           /media/fre dd4e4a2e-4785-4441-91b0-28234b98e625
      ├─sda5   ext4    30.3G   6.2G focal_a
      │                                    focal_a            /media/fre f2cde08c-a045-43ef-83bd-a4132aa23fbd
      ├─sda6   ext4   302.7G 117.8G data   data               /media/fre f9537995-8b44-4abb-b5fb-ec27023f57b2
      ├─sda7   swap     2.1G                                             3ef43e7c-8a35-4f8b-bc73-c91d6098d4cd
      ├─sda8   ext4    24.4G   8.2G impish impish             /media/fre a269adca-248f-4633-a06d-01348ae42d3a
      ├─sda9   ext4      24G   6.9G groovy_k
      │                                    groovy_k           /media/fre 6fadac33-0cdc-4005-940c-a4d035058dd8
      └─sda10  ext4    33.3G   9.7G jammy-b
                                           jammy_b            /media/fre aa644837-3a50-4cc3-b5b9-683172ea7d60
Samsu nvme0n1         465.8G                                             
      ├─nvme0n1p1
      │        vfat     512M  16.2M ESP_NVME
      │                                    esp_nvme           /boot/efi  4954-C122
      ├─nvme0n1p2
      │        ext4    29.3G   8.7G focal_0
      │                                    focal_0            /media/fre b913e1bc-6f08-4984-b653-9a604d95470a
      ├─nvme0n1p3
      │        ext4    29.3G  10.1G focal_k
      │                                    focal_k            /media/fre 54029c4f-0cbe-413e-80ce-78a4995b0551
      ├─nvme0n1p4
      │        ext4    29.3G  15.7G jammy  jammy              /          9da6b198-e2ca-4e27-8a18-6daf4ecfc324
      └─nvme0n1p5
               ext4   195.3G 134.9G nvme_data
                                           nvme_data          /mnt/data  1a44f4af-6780-4bbd-ad0b-6385ed30830b
oldfred
  • 650