How do I know if a partition is ext2, ext3, or ext4?
Solution 1
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.
Solution 2
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"
Solution 3
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)
Solution 4
Surprised this isn't on here already.
No sudo
required:
lsblk -f
Solution 5
Still another way, since you know you're running some flavor of ext?
, is to look at the filesystem's feature list:
# tune2fs -l /dev/sda1 | grep features
If in the list you see:
-
extent
— it's ext4 - no
extent
, buthas_journal
— it's ext3 - neither
extent
norhas_journal
— it's ext2
The parted
and blkid
answers are better if you want these heuristics run for you automatically. (They tell the difference with feature checks, too.) They can also identify non-ext?
filesystems.
This method has the virtue of showing you the low-level differences.
The important thing to realize here is that these three filesystems are forwards compatible, and to some extent backwards-compatible, too. Later versions just add features on top of the older ones.
See the ext4 HOWTO for more information on this.
Related videos on Youtube
user2935706
Updated on September 18, 2022Comments
-
user2935706 over 1 year
I just formatted stuff. One disk I format as ext2. The other I want to format as ext4. I want to test how they perform.
Now, how do I know the kind of file system in a partition?
-
zacharyalexstern over 11 yearsOut of curiosity, what are you trying to test? Journal vs. no journal? For the record, you can operate ext4 in no-journal mode, and still benefit from all the other new features.
-
Ciro Santilli Путлер Капут 六四事 over 8 years
-
-
user2935706 over 11 yearsparted is not installed. Also the drives are not mounted yet.
-
tonybka over 11 years@JimThio I assume you were able to install it? You should be able to get it by simply doing
sudo apt-get install parted
(orgparted
) if you are on Ubuntu or any other debian derivative. -
Warren Young over 11 yearsThis has the same weakness as h3rmiller's
mount
based answer. -
Warren Young over 11 years+1: I've verified that this gives the correct result when mounting an
ext2
filesystem withmount -t ext4
.blkid
isn't fooled by that. -
Warren Young over 11 years+1: I've verified that this gives the correct result when mounting an
ext2
filesystem withmount -t ext4
.parted
isn't fooled by that. -
Warren Young over 11 yearsh3rrmiller removed his answer, so for those who don't have the rep to see it now, the problem is that if you say
mount -t ext4
on anext2
filesystem,df -T
reportsext4
. That is, it's just reading what the mount table says, not looking at the filesystem metadata to figure this out. -
mattdm over 11 years@Warren: That's because it is an ext4 filesystem in that case. Just one with not many features.
-
Warren Young over 11 years@mattdm: So when you unmount it...is it still an ext4 filesystem?
-
mattdm over 11 years@Warren: in a sense, all ext2 filesystems are also ext4 filesystems, yes. (But of course, not in the sense most people mean.)
-
Warren Young over 11 yearsOn what system?
fdisk
, on the system I'm using at the moment at least, only shows the partition type, not the filesystem type. That means not only can't it tell the difference betweenext2
,ext3
, andext4
, it also can't discern ReiserFS or XFS from these. -
user2935706 over 11 yearsWhile this is not the most upvoted answer, this is the one I actually use. Also I do not need to specify the device.
-
user2935706 over 11 years+1 for effort. I have done fdisk before asking this question. Keep points up.
-
heinrich5991 over 11 yearsWhen entering
$ sudo file /dev/sda1
, I get/dev/sda1: block special
-
Warren Young over 11 yearsIn that case, I've been using
ext4
since 1993 or so, in Yggdrasil Linux. I'm probably usingext5
already. Woohoo, I live in the FUTURE! -
Cannon8668 over 9 yearsdoesn't work for LVM stuff: parted -l seems to work better
-
Gilles 'SO- stop being evil' over 9 years@TiloBunt It works for LVM as well. The device name will be
/dev/VOLUMEGROUP/LOGICALVOLUME
or/dev/mapper/VOLUMEGROUP-LOGICALVOLUME
instead of/dev/sdLETTERDIGIT
. -
Gilles 'SO- stop being evil' over 9 years@TiloBunt Make that
file -sL /dev/mapper/foo-bar
, with the-L
flag to dereference the symlink. -
Jose Diaz-Gonzalez about 9 yearsFor what its worth, this also appears to work for xfs drives, though apparently it's
blkid
is not as great aslsblk
is at detecting unmounted drives (if you need to) -
iTag almost 9 yearsIf I run this without
sudo
theFSTYPE
column is blank. -
Freedom_Ben almost 9 years@Flup I just tried it myself again and it worked perfectly without sudo. FSTYPE column was fully populated. May be some disparity between our systems?
-
don_crissti over 8 years@Flup - you must be using Debian/Ubuntu or derivatives... They're famous for doing something (or maybe not doing something, I wouldn't know) and the end result is you need root privileges to list some
lsblk
columns... -
Basile Starynkevitch over 8 yearsBecause it is not the best answer: a partition might be grub-labeled as ext2 and contains ext4 filesystem (and then would be mounted as ext4 with
mount -t auto
) -
Brain2000 about 8 yearsThanks! The file command wasn't working, but this gave me what I needed.
-
rectalogic almost 7 yearsI've been using this technique for years. But today it failed because the unformatted EBS volume happens to match the signature of a DOS executable:
$ sudo file -s /dev/xvdm /dev/xvdm: DOS executable (COM)
-
Gilles 'SO- stop being evil' almost 7 years@rectalogic
file
guesses, and sometimes it can guess wrong. When you know what kind of file you're looking at (e.g. you know that it's a filesystem image) it works reasonably well. When it's open-ended, such as in your case with a volume that contained “random” garbage, there can be false positives. COM executables don't actually have any structure, so therefile
has both many false positives and many false negatives. -
rectalogic almost 7 yearsI've switched to using
blkid -o value -s TYPE /dev/xvdm
- it exits with 2 if the device is unformatted, otherwise prints the filesystem, and works with LUKS encrypted filesystems. -
jokab over 5 yearsi had to sudo blkid /dev/sda1 else I get blank results
-
zer09 over 4 yearsBest answer for me, using without sudo, also works on Debian/Ubuntu derivatives, I am on Pop Os.
-
Vishnu Dasu over 2 years