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?
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
-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 /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)
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
has_journal— it's ext3
has_journal— it's ext2
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-
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.
df -T see man
df for more options still one more way I found is
Surprised this isn't on here already.
use -T option to print file system type
[root@centos6 ~]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup-lv_root ext4 6795192 6367072 76276 99% / tmpfs tmpfs 639164 0 639164 0% /dev/shm /dev/sda1 ext4 487652 28684 433368 7% /boot
fdisk [options] -l <disk> list partition table(s) fdisk -s <partition> give partition size(s) in blocks fdisk [options] <disk> change partition table
Here's a useful oneliner to get just the filesystem type:
blkid -o export <partition-device> | grep '^TYPE' | cut -d"=" -f2
An example run is:
# blkid -o export /dev/sda1 | grep '^TYPE' | cut -d"=" -f2 vfat # blkid -o export /dev/sda2 | grep '^TYPE' | cut -d"=" -f2 ext4
This didn't show the BSD answer I was looking for. I had the impression these type bytes were actually contained in the partition table on the disk, not sure about that. There's only type 85 for all Linux extfs types, but Linux doesn't recognize OpenBSD's A6 type at all either.
> 00 unused 20 Willowsoft 66 NetWare 386 A9 NetBSD > 01 DOS FAT-12 24 NEC DOS 67 Novell AB MacOS X boot > 02 XENIX / 27 Win Recovery 68 Novell AF MacOS X HFS+ > 03 XENIX /usr 38 Theos 69 Novell B7 BSDI filesy* > 04 DOS FAT-16 39 Plan 9 70 DiskSecure B8 BSDI swap > 05 Extended DOS 40 VENIX 286 75 PCIX BF Solaris > 06 DOS > 32MB 41 Lin/Minux DR 80 Minix (old) C0 CTOS > 07 NTFS 42 LinuxSwap DR 81 Minix (new) C1 DRDOSs FAT12 > 08 AIX fs 43 Linux DR 82 Linux swap C4 DRDOSs 09 AIX/Coherent 4D QNX 4.2 Pri 83 Linux files* C6 DRDOSs >=32M > 0A OS/2 Bootmgr 4E QNX 4.2 Sec 84 OS/2 hidden C7 HPFS Disbled > 0B Win95 FAT-32 4F QNX 4.2 Ter 85 Linux ext. DB CPM/C.DOS/C* > 0C Win95 FAT32L 50 DM 86 NT FAT VS DE Dell Maint > 0E DOS FAT-16 51 DM 87 NTFS VS E1 SpeedStor > 0F Extended LBA 52 CP/M or SysV 8E Linux LVM E3 SpeedStor > 10 OPUS 53 DM 93 Amoeba FS E4 SpeedStor > 11 OS/2 hidden 54 Ontrack 94 Amoeba BBT EB BeOS/i386 > 12 Compaq Diag. 55 EZ-Drive 99 Mylex EE EFI GPT > 14 OS/2 hidden 56 Golden Bow 9F BSDI EF EFI Sys > 16 OS/2 hidden 5C Priam A0 NotebookSave F1 SpeedStor > 17 OS/2 hidden 61 SpeedStor A5 FreeBSD F2 DOS 3.3+ Sec > 18 AST swap 63 ISC, HURD, * A6 OpenBSD F4 SpeedStor > 19 Willowtech 64 NetWare 2.xx A7 NEXTSTEP FF Xenix BBT > 1C ThinkPad Rec 65 NetWare 3.xx A8 MacOS X
The formatting may get mangled, it's a nice table 70 columns wide. If you're in OpenBSD's fdisk and you hit ? when it asks for partition type this is what you get. The types show when you're editing or listing the partition table.
Partition types on Wikipedia: https://en.wikipedia.org/wiki/Partition_type