How to capture all disks that donâÂÂt have a file system
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I want to capture all disks that do not have a filesystem ( all disks that mkfs
not runs on them )
I tried the below, but still gives the OS ( sda ).
What is the best approach with lsblk
or other command to capture all disks that are without filesystem?
lsblk -f | egrep -v "xfs|ext3|ext4"
NAME FSTYPE LABEL UUID
MOUNTPOINT
fd0
sda
âÂÂâÂÂsda2 LVM2_member v0593a-KiKU-9emb-STbx-ByMz-S95k-jChr0m
âÂÂâÂÂvg00-lv_swap swap 1beb675f-0b4c-4225-8455-e876cafc5756
[SWAP]
sdg
sdh
sdi
sdj
sdk
sr0
linux filesystems mkfs lsblk
add a comment |Â
up vote
5
down vote
favorite
I want to capture all disks that do not have a filesystem ( all disks that mkfs
not runs on them )
I tried the below, but still gives the OS ( sda ).
What is the best approach with lsblk
or other command to capture all disks that are without filesystem?
lsblk -f | egrep -v "xfs|ext3|ext4"
NAME FSTYPE LABEL UUID
MOUNTPOINT
fd0
sda
âÂÂâÂÂsda2 LVM2_member v0593a-KiKU-9emb-STbx-ByMz-S95k-jChr0m
âÂÂâÂÂvg00-lv_swap swap 1beb675f-0b4c-4225-8455-e876cafc5756
[SWAP]
sdg
sdh
sdi
sdj
sdk
sr0
linux filesystems mkfs lsblk
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I want to capture all disks that do not have a filesystem ( all disks that mkfs
not runs on them )
I tried the below, but still gives the OS ( sda ).
What is the best approach with lsblk
or other command to capture all disks that are without filesystem?
lsblk -f | egrep -v "xfs|ext3|ext4"
NAME FSTYPE LABEL UUID
MOUNTPOINT
fd0
sda
âÂÂâÂÂsda2 LVM2_member v0593a-KiKU-9emb-STbx-ByMz-S95k-jChr0m
âÂÂâÂÂvg00-lv_swap swap 1beb675f-0b4c-4225-8455-e876cafc5756
[SWAP]
sdg
sdh
sdi
sdj
sdk
sr0
linux filesystems mkfs lsblk
I want to capture all disks that do not have a filesystem ( all disks that mkfs
not runs on them )
I tried the below, but still gives the OS ( sda ).
What is the best approach with lsblk
or other command to capture all disks that are without filesystem?
lsblk -f | egrep -v "xfs|ext3|ext4"
NAME FSTYPE LABEL UUID
MOUNTPOINT
fd0
sda
âÂÂâÂÂsda2 LVM2_member v0593a-KiKU-9emb-STbx-ByMz-S95k-jChr0m
âÂÂâÂÂvg00-lv_swap swap 1beb675f-0b4c-4225-8455-e876cafc5756
[SWAP]
sdg
sdh
sdi
sdj
sdk
sr0
linux filesystems mkfs lsblk
edited Dec 22 '17 at 12:41
Jeff Schaller
31.8k848109
31.8k848109
asked Dec 22 '17 at 11:23
yael
2,0091145
2,0091145
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
3
down vote
accepted
lsblk -o NAME,FSTYPE -dsn
This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second column. If its blank there is no recognized file system.
So to get the output you want in one command
lsblk -o NAME,FSTYPE -dsn | awk '$2 == "" print $1'
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices yourlsblk ... | awk ...
command lists arezd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be/dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTWfile -s /dev/zd128p3
reports/dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.
â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem withlsblk
not recognising the filesystem on a formatted ZVOL block device...btw,blkid
recognises them and detects the fs type.
â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
 |Â
show 6 more comments
up vote
0
down vote
In my opinion, the best option is FDISK.
syntax:
fdisk -l | grep -i ^disk
add a comment |Â
up vote
0
down vote
You can use parted utility for listing all disks,whether they have filesystems or not:
sudo parted
and then type "print free".
It will print all partitioned as well as non-partitioned drives.
add a comment |Â
up vote
0
down vote
The following one-liner seems to work. It prints all block device names except those which have a TYPE, PTTYPE, LABEL, or PARTLABEL. The last two on the grounds that something with a label is likely to be in use already.
This seems to me to be a much better approach than using grep -v
to exclude a list of filesystem types known at this moment in time.
blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]+"/ print $1'
Note: the list of block devices produced by this are NOT in any way guaranteed not to be in use, just that they don't have any of the commonly used markers that in-use block devices have. They're probably not in use, but without spending significantly more time researching the issue I'm extremely reluctant to even suggest that it is any kind of guaranteed list.
On one of my ZFS On Linux boxes, it produces the following output:
# blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]*"/ print $1'
/dev/sdb9
This is correct for that system. /dev/sdb9 IS an unformatted, unused partition. It's an 8MB partition at the end of a disk which is used in a single-disk ZFS pool (this is a home machine for testing stuff and I needed its mirror drive for something else and haven't got around to replacing it yet)
BTW, blkid
takes significantly longer to run than lsblk
. It does a lot more work trying to identify what kind of block device it's looking at.
This is probably only noticeable on servers with hundreds of drives/lvm members/zvols and other block devices.
For example, on one of my medium-sized servers (with 362 block devices of various kinds), blkid
takes about 2 minutes to run, while lsblk
takes about 0.09 seconds. On another, much smaller, system with only 39 block devices (the home testing box mentioned above), blkid
takes 0.16 seconds while lsblk
takes 0.01 seconds.
If you need to run this repeatedly and the run-time is too long, you can always cache blkdid
's output in a tmpfile for a short time. e.g. if the cache either doesn't exist or is older than, say, 30 minutes then generate the cache file (blkid > /path/to/blkid.cache
) and use that as the input to awk
or whatever.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
lsblk -o NAME,FSTYPE -dsn
This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second column. If its blank there is no recognized file system.
So to get the output you want in one command
lsblk -o NAME,FSTYPE -dsn | awk '$2 == "" print $1'
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices yourlsblk ... | awk ...
command lists arezd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be/dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTWfile -s /dev/zd128p3
reports/dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.
â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem withlsblk
not recognising the filesystem on a formatted ZVOL block device...btw,blkid
recognises them and detects the fs type.
â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
 |Â
show 6 more comments
up vote
3
down vote
accepted
lsblk -o NAME,FSTYPE -dsn
This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second column. If its blank there is no recognized file system.
So to get the output you want in one command
lsblk -o NAME,FSTYPE -dsn | awk '$2 == "" print $1'
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices yourlsblk ... | awk ...
command lists arezd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be/dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTWfile -s /dev/zd128p3
reports/dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.
â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem withlsblk
not recognising the filesystem on a formatted ZVOL block device...btw,blkid
recognises them and detects the fs type.
â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
 |Â
show 6 more comments
up vote
3
down vote
accepted
up vote
3
down vote
accepted
lsblk -o NAME,FSTYPE -dsn
This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second column. If its blank there is no recognized file system.
So to get the output you want in one command
lsblk -o NAME,FSTYPE -dsn | awk '$2 == "" print $1'
lsblk -o NAME,FSTYPE -dsn
This will print a list of block devices that are not themselves holders for partitions (they do not have a partition table). The detected file system type is in the second column. If its blank there is no recognized file system.
So to get the output you want in one command
lsblk -o NAME,FSTYPE -dsn | awk '$2 == "" print $1'
edited Dec 22 '17 at 14:34
answered Dec 22 '17 at 14:20
jdwolf
2,392116
2,392116
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices yourlsblk ... | awk ...
command lists arezd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be/dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTWfile -s /dev/zd128p3
reports/dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.
â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem withlsblk
not recognising the filesystem on a formatted ZVOL block device...btw,blkid
recognises them and detects the fs type.
â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
 |Â
show 6 more comments
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices yourlsblk ... | awk ...
command lists arezd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be/dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTWfile -s /dev/zd128p3
reports/dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.
â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem withlsblk
not recognising the filesystem on a formatted ZVOL block device...btw,blkid
recognises them and detects the fs type.
â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices your
lsblk ... | awk ...
command lists are zd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be /dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTW file -s /dev/zd128p3
reports /dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.â cas
Dec 23 '17 at 7:35
This is good unless you've got ZFS pools with ZVOLs on them. e.g. on one of my systems, some of the block devices your
lsblk ... | awk ...
command lists are zd128p[123]
. They're actually partitions 1-3 of /dev/zd128 (which happens to be /dev/zvol/volumes/freebsd
, my freebsd VM's disk image). There are other ZVOL devices which it lists, too (including a few centos, debian, and ubuntu VMs). BTW file -s /dev/zd128p3
reports /dev/zd128p3: Unix Fast File system [v2] (little-endian) last mounted on [.....]
. I'm not sure if this would happen with LVM volumes too - it's been a while.â cas
Dec 23 '17 at 7:35
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
@cas the above command only recognizes containers in the case of block devices that are part of a partition table. As far as I know that concept doesn't extend to a fs volume. Also it would skip block devices without a partition table that are in containers. Maybe I shouldn't assume the op doesn't want that? but such devices are ambiguous whether you'd want a file system on them or a partition table.
â jdwolf
Dec 23 '17 at 8:05
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem with
lsblk
not recognising the filesystem on a formatted ZVOL block device...btw, blkid
recognises them and detects the fs type.â cas
Dec 23 '17 at 8:13
my comment really wasn't about containers or VMs (i.e. the fact that my ZVOLs are mostly used for VMs isn't relevant). ZFS ZVOLs are block devices, just like any other - that's their entire purpose. The kernel recognises them as block devices, and they can be formatted with filesystems, as several of mine were - but your command still listed them as unformatted block devices. This is a problem with
lsblk
not recognising the filesystem on a formatted ZVOL block device...btw, blkid
recognises them and detects the fs type.â cas
Dec 23 '17 at 8:13
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas NVM. lsblk handles LVM volumes just fine. Any PVs partitions or not are considered holders.
â jdwolf
Dec 23 '17 at 8:14
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
@cas the term "container" was misspoken. I meant holders which means block devices where there is a partitions or volumes on it. Or in other words where the kernel is using it to derive other block devices.
â jdwolf
Dec 23 '17 at 8:18
 |Â
show 6 more comments
up vote
0
down vote
In my opinion, the best option is FDISK.
syntax:
fdisk -l | grep -i ^disk
add a comment |Â
up vote
0
down vote
In my opinion, the best option is FDISK.
syntax:
fdisk -l | grep -i ^disk
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In my opinion, the best option is FDISK.
syntax:
fdisk -l | grep -i ^disk
In my opinion, the best option is FDISK.
syntax:
fdisk -l | grep -i ^disk
edited Dec 22 '17 at 15:52
answered Dec 22 '17 at 15:26
Alessandro Schneider
1012
1012
add a comment |Â
add a comment |Â
up vote
0
down vote
You can use parted utility for listing all disks,whether they have filesystems or not:
sudo parted
and then type "print free".
It will print all partitioned as well as non-partitioned drives.
add a comment |Â
up vote
0
down vote
You can use parted utility for listing all disks,whether they have filesystems or not:
sudo parted
and then type "print free".
It will print all partitioned as well as non-partitioned drives.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can use parted utility for listing all disks,whether they have filesystems or not:
sudo parted
and then type "print free".
It will print all partitioned as well as non-partitioned drives.
You can use parted utility for listing all disks,whether they have filesystems or not:
sudo parted
and then type "print free".
It will print all partitioned as well as non-partitioned drives.
answered Dec 24 '17 at 14:39
AshishKumar
11
11
add a comment |Â
add a comment |Â
up vote
0
down vote
The following one-liner seems to work. It prints all block device names except those which have a TYPE, PTTYPE, LABEL, or PARTLABEL. The last two on the grounds that something with a label is likely to be in use already.
This seems to me to be a much better approach than using grep -v
to exclude a list of filesystem types known at this moment in time.
blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]+"/ print $1'
Note: the list of block devices produced by this are NOT in any way guaranteed not to be in use, just that they don't have any of the commonly used markers that in-use block devices have. They're probably not in use, but without spending significantly more time researching the issue I'm extremely reluctant to even suggest that it is any kind of guaranteed list.
On one of my ZFS On Linux boxes, it produces the following output:
# blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]*"/ print $1'
/dev/sdb9
This is correct for that system. /dev/sdb9 IS an unformatted, unused partition. It's an 8MB partition at the end of a disk which is used in a single-disk ZFS pool (this is a home machine for testing stuff and I needed its mirror drive for something else and haven't got around to replacing it yet)
BTW, blkid
takes significantly longer to run than lsblk
. It does a lot more work trying to identify what kind of block device it's looking at.
This is probably only noticeable on servers with hundreds of drives/lvm members/zvols and other block devices.
For example, on one of my medium-sized servers (with 362 block devices of various kinds), blkid
takes about 2 minutes to run, while lsblk
takes about 0.09 seconds. On another, much smaller, system with only 39 block devices (the home testing box mentioned above), blkid
takes 0.16 seconds while lsblk
takes 0.01 seconds.
If you need to run this repeatedly and the run-time is too long, you can always cache blkdid
's output in a tmpfile for a short time. e.g. if the cache either doesn't exist or is older than, say, 30 minutes then generate the cache file (blkid > /path/to/blkid.cache
) and use that as the input to awk
or whatever.
add a comment |Â
up vote
0
down vote
The following one-liner seems to work. It prints all block device names except those which have a TYPE, PTTYPE, LABEL, or PARTLABEL. The last two on the grounds that something with a label is likely to be in use already.
This seems to me to be a much better approach than using grep -v
to exclude a list of filesystem types known at this moment in time.
blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]+"/ print $1'
Note: the list of block devices produced by this are NOT in any way guaranteed not to be in use, just that they don't have any of the commonly used markers that in-use block devices have. They're probably not in use, but without spending significantly more time researching the issue I'm extremely reluctant to even suggest that it is any kind of guaranteed list.
On one of my ZFS On Linux boxes, it produces the following output:
# blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]*"/ print $1'
/dev/sdb9
This is correct for that system. /dev/sdb9 IS an unformatted, unused partition. It's an 8MB partition at the end of a disk which is used in a single-disk ZFS pool (this is a home machine for testing stuff and I needed its mirror drive for something else and haven't got around to replacing it yet)
BTW, blkid
takes significantly longer to run than lsblk
. It does a lot more work trying to identify what kind of block device it's looking at.
This is probably only noticeable on servers with hundreds of drives/lvm members/zvols and other block devices.
For example, on one of my medium-sized servers (with 362 block devices of various kinds), blkid
takes about 2 minutes to run, while lsblk
takes about 0.09 seconds. On another, much smaller, system with only 39 block devices (the home testing box mentioned above), blkid
takes 0.16 seconds while lsblk
takes 0.01 seconds.
If you need to run this repeatedly and the run-time is too long, you can always cache blkdid
's output in a tmpfile for a short time. e.g. if the cache either doesn't exist or is older than, say, 30 minutes then generate the cache file (blkid > /path/to/blkid.cache
) and use that as the input to awk
or whatever.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The following one-liner seems to work. It prints all block device names except those which have a TYPE, PTTYPE, LABEL, or PARTLABEL. The last two on the grounds that something with a label is likely to be in use already.
This seems to me to be a much better approach than using grep -v
to exclude a list of filesystem types known at this moment in time.
blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]+"/ print $1'
Note: the list of block devices produced by this are NOT in any way guaranteed not to be in use, just that they don't have any of the commonly used markers that in-use block devices have. They're probably not in use, but without spending significantly more time researching the issue I'm extremely reluctant to even suggest that it is any kind of guaranteed list.
On one of my ZFS On Linux boxes, it produces the following output:
# blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]*"/ print $1'
/dev/sdb9
This is correct for that system. /dev/sdb9 IS an unformatted, unused partition. It's an 8MB partition at the end of a disk which is used in a single-disk ZFS pool (this is a home machine for testing stuff and I needed its mirror drive for something else and haven't got around to replacing it yet)
BTW, blkid
takes significantly longer to run than lsblk
. It does a lot more work trying to identify what kind of block device it's looking at.
This is probably only noticeable on servers with hundreds of drives/lvm members/zvols and other block devices.
For example, on one of my medium-sized servers (with 362 block devices of various kinds), blkid
takes about 2 minutes to run, while lsblk
takes about 0.09 seconds. On another, much smaller, system with only 39 block devices (the home testing box mentioned above), blkid
takes 0.16 seconds while lsblk
takes 0.01 seconds.
If you need to run this repeatedly and the run-time is too long, you can always cache blkdid
's output in a tmpfile for a short time. e.g. if the cache either doesn't exist or is older than, say, 30 minutes then generate the cache file (blkid > /path/to/blkid.cache
) and use that as the input to awk
or whatever.
The following one-liner seems to work. It prints all block device names except those which have a TYPE, PTTYPE, LABEL, or PARTLABEL. The last two on the grounds that something with a label is likely to be in use already.
This seems to me to be a much better approach than using grep -v
to exclude a list of filesystem types known at this moment in time.
blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]+"/ print $1'
Note: the list of block devices produced by this are NOT in any way guaranteed not to be in use, just that they don't have any of the commonly used markers that in-use block devices have. They're probably not in use, but without spending significantly more time researching the issue I'm extremely reluctant to even suggest that it is any kind of guaranteed list.
On one of my ZFS On Linux boxes, it produces the following output:
# blkid | awk -F': ' '!/ ((PT)?TYPE|(PART)?LABEL)="[^"]*"/ print $1'
/dev/sdb9
This is correct for that system. /dev/sdb9 IS an unformatted, unused partition. It's an 8MB partition at the end of a disk which is used in a single-disk ZFS pool (this is a home machine for testing stuff and I needed its mirror drive for something else and haven't got around to replacing it yet)
BTW, blkid
takes significantly longer to run than lsblk
. It does a lot more work trying to identify what kind of block device it's looking at.
This is probably only noticeable on servers with hundreds of drives/lvm members/zvols and other block devices.
For example, on one of my medium-sized servers (with 362 block devices of various kinds), blkid
takes about 2 minutes to run, while lsblk
takes about 0.09 seconds. On another, much smaller, system with only 39 block devices (the home testing box mentioned above), blkid
takes 0.16 seconds while lsblk
takes 0.01 seconds.
If you need to run this repeatedly and the run-time is too long, you can always cache blkdid
's output in a tmpfile for a short time. e.g. if the cache either doesn't exist or is older than, say, 30 minutes then generate the cache file (blkid > /path/to/blkid.cache
) and use that as the input to awk
or whatever.
answered Dec 25 '17 at 12:44
cas
37.7k44394
37.7k44394
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412483%2fhow-to-capture-all-disks-that-don-t-have-a-file-system%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password