blob: e38a719411484a86bfdd164776e285e8d1b406c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/sh
#
# Print some common lsblk values
#
# Any (lowercased) name symlinked to the lsblk script will be passed to lsblk
# as one of its --output names. Here's a partial list of --output names
# from the lsblk binary:
#
# Available columns (for --output):
# NAME device name
# KNAME internal kernel device name
# MAJ:MIN major:minor device number
# FSTYPE filesystem type
# MOUNTPOINT where the device is mounted
# LABEL filesystem LABEL
# UUID filesystem UUID
# RA read-ahead of the device
# RO read-only device
# RM removable device
# MODEL device identifier
# SIZE size of the device
# STATE state of the device
# OWNER user name
# GROUP group name
# MODE device node permissions
# ALIGNMENT alignment offset
# MIN-IO minimum I/O size
# OPT-IO optimal I/O size
# PHY-SEC physical sector size
# LOG-SEC logical sector size
# ROTA rotational device
# SCHED I/O scheduler name
# RQ-SIZE request queue size
# TYPE device type
# DISC-ALN discard alignment offset
# DISC-GRAN discard granularity
# DISC-MAX discard max bytes
# DISC-ZERO discard zeroes data
#
# If the script is run as just 'lsblk' then print out disk size, vendor,
# model number and serial number.
helpstr="
label: Show filesystem label.
model: Show disk model number.
serial: Show disk serial number.
size: Show the disk capacity.
vendor: Show the disk vendor.
lsblk: Show the disk size, vendor, model number, and serial number."
script=$(basename "$0")
if [ "$1" = "-h" ] ; then
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
exit
fi
if [ "$script" = "lsblk" ] ; then
list="size vendor model serial"
else
list=$(echo "$script" | tr '[:upper:]' '[:lower:]')
fi
# Older versions of lsblk don't support all these values (like SERIAL).
for i in $list ; do
# Special case: Looking up the size of a file-based vdev can't
# be done with lsblk.
if [ "$i" = "size" ] && [ -f "$VDEV_UPATH" ] ; then
size="$(du -h --apparent-size $VDEV_UPATH | cut -f 1)"
echo "size=$size"
continue
fi
val=""
if val=$(eval "lsblk -dl -n -o $i $VDEV_UPATH 2>/dev/null") ; then
# Remove leading/trailing whitespace from value
val=$(echo "$val" | sed -e 's/^[[:space:]]*//' \
-e 's/[[:space:]]*$//')
fi
echo "$i=$val"
done
|