I'm writing a script that will copy all of the files on a device to a directory. The problem is that some of the devices have multiple partitions and some of the partitions don't have filesystems to copy files from. At the moment, I'm thinking about using
lsblk to get a list of partitions on the device and
file -s to check for a filesystem on each partition.
Is there a less brute way to do what I am trying to do?
Here is information regarding the empty partition problem:
# /dev/sdb is a flashdrive with two partitions # /dev/sdb1 has no filesystem # /dev/sdb2 has an ext4 partition $ lsblk -fi ... sdb vfat CARRIER-R C84B-6A72 |-sdb1 vfat CARRIER-R C84B-6A72 `-sdb2 ext4 CARRIER-R 33ebb632-68a5-4bf5-bd29-90733af9699e ... $ lsblk -ln -o NAME,FSTYPE ... sdb vfat sdb1 vfat sdb2 ext4 ... # As confirmation, mounting the partition fails $ mount -t auto /dev/sdb1 /mnt mount: wrong fs type, bad option, bad superblock on /dev/sdb1 ... $ dmesg | tail ... [ 985.933627] EXT4-fs (sdb1): VFS: Can't find ext4 filesystem [ 985.935722] EXT4-fs (sdb1): VFS: Can't find ext4 filesystem [ 985.937603] EXT4-fs (sdb1): VFS: Can't find ext4 filesystem [ 985.939623] FAT-fs (sdb1): invalid media value (0xa7) [ 985.939627] FAT-fs (sdb1): Can't find a valid FAT filesystem