findmnt 隸屬 util-linux 套件,預設內建於主流發行版。用於列出、查詢、掛載/卸載檔案系統,支援樹狀、列表、JSON、原始、df 風格等多種輸出格式。
# 樹狀預設輸出
findmnt
# 列表格式
findmnt -l
# 僅顯示 /etc/fstab 定義的掛載點
findmnt -s
# 依檔案系統類型過濾
findmnt -t ext4
findmnt -t ext4,xfs,btrfs
findmnt -D
# SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
findmnt --raw
# TARGET SOURCE FSTYPE OPTIONS
findmnt -o TARGET,SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,OPTIONS
# 支援欄位:TARGET, SOURCE, FSTYPE, LABEL, UUID, PARTLABEL, PARTUUID, OPTIONS, SIZE, USED, AVAIL, USE%, MODE
# 依裝置路徑
findmnt -S /dev/sda1
findmnt --source /dev/nvme0n1p2
# 依掛載點
findmnt -T /
findmnt --target /home
# 掛載 (自動從 /etc/fstab 讀取選項)
findmnt --mount /dev/sdb1 /mnt/data
# 卸載
findmnt --unmount /mnt/data
# 模擬掛載 (僅檢查語法)
findmnt --mount --fake /dev/sdb1 /mnt/data
findmnt -J
# {
# "filesystems": [
# {"target":"/","source":"/dev/mapper/root","fstype":"ext4","options":"rw,relatime"},
# ...
# ]
# }
#!/bin/bash
# 檢查關鍵掛載點是否存在且非唯讀
for mp in / /boot /var /home; do
if ! findmnt -n -o TARGET,OPTIONS "$mp" | grep -qv 'ro\b'; then
echo "WARNING: $mp not mounted or read-only"
fi
done