Fix “device excluded by a filter” LVM error.

Sometimes you can encounter “device excluded by a filter” LVM error.

$ sudo pvcreate /dev/sdb
Device /dev/sdb excluded by a filter.

This error is caused by the leftover partition table.

$ sudo wipefs --no-act /dev/sdb
DEVICE OFFSET     TYPE UUID LABEL
sdb    0x200      gpt
sdb    0x3ffffe00 gpt
sdb    0x1fe      PMBR

Use dry-run mode to see the operations that will be performed.

$ sudo wipefs --all --no-act /dev/sdb
/dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x3ffffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success

Create backup and perform these operations to remove partition table signatures.

$ sudo wipefs --all --backup /dev/sdb
/dev/sdb: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x3ffffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success

List stored signatures.

$ sudo bash -c "find ~/ -maxdepth 1 -name 'wipefs-sdb-*.bak'"
/root/wipefs-sdb-0x00000200.bak
/root/wipefs-sdb-0x3ffffe00.bak
/root/wipefs-sdb-0x000001fe.bak
See the last section to learn how to recover in case of an emergency, as this is the last moment to undo this operation.

Initialize physical volume for use by the LVM.

$ sudo pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.

In case of emergency

Use created backup to generate commands required to undo wipe operation.

$ sudo bash -c 'find ~/ -maxdepth 1 -name "wipefs-sdb-*.bak"| while read file; do addr=$(echo $file | sed "s/.*wipefs-.*-\(.*\).bak/\1/"); echo sudo dd if=${file} of=/dev/sdb seek=$((${addr})) bs=1 conv=notrunc; done'
sudo dd if=/root/wipefs-sdb-0x00000200.bak of=/dev/sdb seek=512 bs=1 conv=notrunc
sudo dd if=/root/wipefs-sdb-0x3ffffe00.bak of=/dev/sdb seek=1073741312 bs=1 conv=notrunc
sudo dd if=/root/wipefs-sdb-0x000001fe.bak of=/dev/sdb seek=510 bs=1 conv=notrunc

Execute these commands.

$ sudo dd if=/root/wipefs-sdb-0x00000200.bak of=/dev/sdb seek=512 bs=1 conv=notrunc
8+0 records in
8+0 records out
8 bytes copied, 0.000480618 s, 16.6 kB/s
$ sudo dd if=/root/wipefs-sdb-0x3ffffe00.bak of=/dev/sdb seek=1073741312 bs=1 conv=notrunc
8+0 records in
8+0 records out
8 bytes copied, 0.000370395 s, 21.6 kB/s
$ sudo dd if=/root/wipefs-sdb-0x000001fe.bak of=/dev/sdb seek=510 bs=1 conv=notrunc
2+0 records in
2+0 records out
2 bytes copied, 0.000264022 s, 7.6 kB/s

See wipefs manual page. This utility is part of the util-linux package.