How do I know if a partition is ext2, ext3, or ext4?
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?
Out 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.
How do I tell what sort of data (what data format) is in a file?
→ Use the
Here, you want to know the format of data in a device file, so you need to pass the
-sflag to tell
filenot just to say that it's a device file but look at the content. Sometimes you'll need the
-Lflag 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/sda1is an ext4 filesystem,
/dev/sdb1is an ext2 filesystem, and
/dev/sdb2is some swap space (about 4GB).
You must run this command as root, because ordinary users may not read disk partitions directly: if needed, add
@heinrich5991 “you need to pass the -s flag …”. I show the command `file -s /dev/sd*` − with `sudo` in front, that's `sudo file -s /dev/sd*`.
@TiloBunt It works for LVM as well. The device name will be `/dev/VOLUMEGROUP/LOGICALVOLUME` or `/dev/mapper/VOLUMEGROUP-LOGICALVOLUME` instead of `/dev/sdLETTERDIGIT`.
tried that `file -s /dev/mapper/` but get `symbolic link to `../dm-0'` same for `file -s /dev/vg_devccsrv11/*`
@TiloBunt Make that `file -sL /dev/mapper/foo-bar`, with the `-L` flag to dereference the symlink.
I'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)`
@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 there `file` has both many false positives and many false negatives.