How do I know if a partition is ext2, ext3, or ext4?
How do I tell what sort of data (what data format) is in a file?
→ Use the file
utility.
Here, you want to know the format of data in a device file, so you need to pass the -s
flag to tell file
not just to say that it's a device file but look at the content. Sometimes you'll need the -L
flag as well, if the device file name is a symbolic link. You'll see output like this:
# file -sL /dev/sd*
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=63fa0104-4aab-4dc8-a50d-e2c1bf0fb188 (extents) (large files) (huge files)
/dev/sdb1: Linux rev 1.0 ext2 filesystem data, UUID=b3c82023-78e1-4ad4-b6e0-62355b272166
/dev/sdb2: Linux/i386 swap file (new style), version 1 (4K pages), size 4194303 pages, no label, UUID=3f64308c-19db-4da5-a9a0-db4d7defb80f
Given this sample output, the first disk has one partition and the second disk has two partitions. /dev/sda1
is an ext4 filesystem, /dev/sdb1
is an ext2 filesystem, and /dev/sdb2
is some swap space (about 4GB).
You must run this command as root, because ordinary users may not read disk partitions directly: if needed, add sudo
in front.
Another option is to use blkid
:
$ blkid /dev/sda1
/dev/sda1: UUID="625fa1fa-2785-4abc-a15a-bfcc498139d1" TYPE="ext2"
This recognizes most filesystem types and stuff like encrypted partitions.
You can also search for partitions with a given type:
# blkid -t TYPE=ext2
/dev/sda1: UUID="625fa1fa-2785-4abc-a15a-bfcc498139d1" TYPE="ext2"
/dev/sdb1: UUID="b80153f4-92a1-473f-b7f6-80e601ae21ac" TYPE="ext2"
You can use sudo parted -l
[shredder12]$ sudo parted -l
Model: ATA WDC WD1600BEVT-7 (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 8587MB 8587MB primary ext3 boot
4 8587MB 40.0GB 31.4GB primary ext4
2 40.0GB 55.0GB 15.0GB primary ext4
3 55.0GB 160GB 105GB extended
5 55.0GB 158GB 103GB logical ext4
6 158GB 160GB 1999MB logical linux-swap(v1)
Source