1. fdisk
The fdisk command can display the partitions and details like file system type, model, zise. In Ubuntu 20.04 report the size of each partitions, but not in all Linux distributions!
@ sudo fdisk -l
Disk /dev/nvme0n1: 232.91 GiB, 250059350016 bytes, 488397168 sectors
Disk model: Samsung SSD 970 EVO 250GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 935DF0C6-01CF-4BC6-B8E4-9675A5EBC9B6
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 3147775 2097152 1G Linux filesystem
/dev/nvme0n1p3 3147776 488394751 485246976 231.4G Linux filesystem
Disk /dev/sda: 238.49 GiB, 256060514304 bytes, 500118192 sectors
Disk model: Samsung SSD 850
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 47D26543-4BD4-4427-935F-A40AA9D848EF
Device Start End Sectors Size Type
/dev/sda1 2048 500117503 500115456 238.5G Linux filesystem
2. sfdisk
It is another utility with a similar purpose to fdisk command, but with more features.
Ex. Can display the size of each partition in bytes:
@ sudo sfdisk -s
/dev/loop0: 56692
/dev/loop1: 56712
/dev/loop2: 69376
/dev/loop3: 30600
/dev/loop4: 31808
/dev/loop5: 72984
/dev/nvme0n1: 244198584
/dev/sda: 250059096
/dev/sdb: 2930266584
/dev/sdc: 1953481728
/dev/sdd: 3907018584
/dev/sde: 2930266584
/dev/mapper/ubuntu--vg-ubuntu--lv: 121311232
total: 12336920564 blocks
3. cfdisk
is a Linux partition editor with an interactive user interface. It can be used to list existing partitions, as well as to create or modify them.
Here is an example of how to use cfdisk command to list the partitions on disk /dev/nvme0n1
@ sudo cfdisk /dev/nvme0n1
4. parted
is another command line utility for listing partitions and modifying them if necessary.
Here is an example of using parted command that lists the partition details:
@ sudo parted -l
Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 256GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 256GB 256GB ext4 primary
Model: WD Elements 10B8 (scsi)
Disk /dev/sdc: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 2000GB 2000GB primary ntfs
Model: ATA HGST HUS726040AL (scsi)
Disk /dev/sdd: 4001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 4001GB 4001GB ext4 primary
Model: Samsung SSD 970 EVO 250GB (nvme)
Disk /dev/nvme0n1: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 538MB 537MB fat32 boot, esp
2 538MB 1612MB 1074MB ext4
3 1612MB 250GB 248GB
With parted you can delete, modify, create partitions on a physical disk:
@ sudo parted -h Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...] Apply COMMANDs with PARAMETERS to DEVICE. If no COMMAND(s) are given, run in interactive mode. OPTIONs: -h, --help displays this help message -l, --list lists partition layout on all block devices -m, --machine displays machine parseable output -s, --script never prompts for user intervention -v, --version displays the version -a, --align=[none|cyl|min|opt] alignment for new partitions COMMANDs: align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted Report bugs to [email protected]
A single command line to create an ext4 primary partition on /dev/sdd disk:
@ sudo parted /dev/sdd -a opt mkpart primary ext4 2048s 4001GB
Previously, however, it is necessary for the existing partitions to be deleted using the rm
command from the parted, the existing space must be sufficient for the above command, approximately 4Tb.
Use this command carefully because if you choose the wrong disk you worked on or delete the wrong partitions, you may lose all information!
5. df
is a disk utility that prints details about mounted file systems. The list generated by df command even includes file systems that are not “real” disk partitions, like tmpfs, udev :
@ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.7G 0 7.7G 0% /dev
tmpfs 1.6G 1.5M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 114G 65G 43G 61% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/nvme0n1p2 976M 199M 711M 22% /boot
/dev/nvme0n1p1 511M 7.8M 504M 2% /boot/efi
/dev/loop0 56M 56M 0 100% /snap/core18/1932
/dev/sde1 2.8T 2.5T 297G 90% /srv/TOSHIBA-3T-ENTERPRISE
/dev/loop1 56M 56M 0 100% /snap/core18/1944
/dev/loop2 68M 68M 0 100% /snap/lxd/18150
/dev/sdd1 3.6T 224G 3.2T 7% /srv/HGST-4T
/dev/sdb1 2.7T 2.4T 169G 94% /srv/TOSHIBA-3T-V300
/dev/loop3 30M 30M 0 100% /snap/snapd/8542
/dev/loop4 32M 32M 0 100% /snap/snapd/10492
/dev/loop5 72M 72M 0 100% /snap/lxd/16099
/dev/sdc1 1.9T 1.7T 123G 94% /srv/WD-2T-USB
/dev/sda1 234G 11G 212G 5% /srv/SAMSUNG-850-PRO
tmpfs 1.6G 0 1.6G 0% /run/user/1001
Use linux grep
command to filter out real hard disk partitions/file systems,
Here’s an example of how to find only file systems that are actual devices or partitions and start with a /dev
:
@ df -h | grep ^/dev
/dev/mapper/ubuntu--vg-ubuntu--lv 114G 65G 43G 61% /
/dev/nvme0n1p2 976M 199M 711M 22% /boot
/dev/nvme0n1p1 511M 7.8M 504M 2% /boot/efi
/dev/loop0 56M 56M 0 100% /snap/core18/1932
/dev/sde1 2.8T 2.5T 297G 90% /srv/TOSHIBA-3T-ENTERPRISE
/dev/loop1 56M 56M 0 100% /snap/core18/1944
/dev/loop2 68M 68M 0 100% /snap/lxd/18150
/dev/sdd1 3.6T 224G 3.2T 7% /srv/HGST-4T
/dev/sdb1 2.7T 2.4T 169G 94% /srv/TOSHIBA-3T-V300
/dev/loop3 30M 30M 0 100% /snap/snapd/8542
/dev/loop4 32M 32M 0 100% /snap/snapd/10492
/dev/loop5 72M 72M 0 100% /snap/lxd/16099
/dev/sdc1 1.9T 1.7T 123G 94% /srv/WD-2T-USB
/dev/sda1 234G 11G 212G 5% /srv/SAMSUNG-850-PRO
or print only disk drive starting with /dev/sd*
and stick the first line about information
@ df | grep -E 'Use%|dev/sd'
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sde1 2930265088 2619654144 310610944 90% /srv/TOSHIBA-3T-ENTERPRISE
/dev/sdd1 3844639728 234504604 3414767908 7% /srv/HGST-4T
/dev/sdb1 2883219632 2560507192 176182804 94% /srv/TOSHIBA-3T-V300
/dev/sdc1 1953480700 1824711644 128769056 94% /srv/WD-2T-USB
Show only the file systems that are user-accesible devices or partitions, start with /dev/sd*
or /dev/nvme*
@ df -h | grep -E ^/dev/'(sd|nvme)'
/dev/nvme0n1p2 976M 199M 711M 22% /boot
/dev/nvme0n1p1 511M 7.8M 504M 2% /boot/efi
/dev/sde1 2.8T 2.5T 297G 90% /srv/TOSHIBA-3T-ENTERPRISE
/dev/sdd1 3.6T 224G 3.2T 7% /srv/HGST-4T
/dev/sdb1 2.7T 2.4T 169G 94% /srv/TOSHIBA-3T-V300
/dev/sdc1 1.9T 1.7T 123G 94% /srv/WD-2T-USB
/dev/sda1 234G 11G 212G 5% /srv/SAMSUNG-850-PRO
6. lsblk
lists all storage blocks, which include disk partitions & optical drives. Details include the total size of the partition and mount point, if any.
@ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55.4M 1 loop /snap/core18/1932
loop1 7:1 0 55.4M 1 loop /snap/core18/1944
loop2 7:2 0 67.8M 1 loop /snap/lxd/18150
loop3 7:3 0 29.9M 1 loop /snap/snapd/8542
loop4 7:4 0 31.1M 1 loop /snap/snapd/10492
loop5 7:5 0 71.3M 1 loop /snap/lxd/16099
sda 8:0 0 238.5G 0 disk
└─sda1 8:1 0 238.5G 0 part /srv/SAMSUNG-850-PRO
sdb 8:16 0 2.7T 0 disk
└─sdb1 8:17 0 2.7T 0 part /srv/TOSHIBA-3T-V300
sdc 8:32 0 1.8T 0 disk
└─sdc1 8:33 0 1.8T 0 part /srv/WD-2T-USB
sdd 8:48 0 3.7T 0 disk
└─sdd1 8:49 0 3.7T 0 part /srv/HGST-4T
sde 8:64 0 2.7T 0 disk
└─sde1 8:65 0 2.7T 0 part /srv/TOSHIBA-3T-ENTERPRISE
nvme0n1 259:0 0 232.9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 1G 0 part /boot
└─nvme0n1p3 259:3 0 231.4G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 115.7G 0 lvm /
Show filterd only real disk-device with details like SIZE:
@ lsblk | grep -E 'SIZE|disk'
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
sdb 8:16 0 2.7T 0 disk
sdc 8:32 0 1.8T 0 disk
sdd 8:48 0 3.7T 0 disk
sde 8:64 0 2.7T 0 disk
nvme0n1 259:0 0 232.9G 0 disk
Show filterd only partition with details like SIZE, MOUNTPOINT:
@ lsblk | grep -E 'SIZE|part'
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
└─sda1 8:1 0 238.5G 0 part /srv/SAMSUNG-850-PRO
└─sdb1 8:17 0 2.7T 0 part /srv/TOSHIBA-3T-V300
└─sdc1 8:33 0 1.8T 0 part /srv/WD-2T-USB
└─sdd1 8:49 0 3.7T 0 part /srv/HGST-4T
└─sde1 8:65 0 2.7T 0 part /srv/TOSHIBA-3T-ENTERPRISE
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 1G 0 part /boot
└─nvme0n1p3 259:3 0 231.4G 0 part
using “-o” option can be used to specify the columns to display: UUID , Model of device and only disk/partition (not loop, lvm)
@ lsblk -o PATH,SIZE,TYPE,MOUNTPOINT,UUID,MODEL | grep -E 'MODEL|part|disk'
PATH SIZE TYPE MOUNTPOINT UUID MODEL
/dev/sda 238.5G disk Samsung_SSD_850
/dev/sda1 238.5G part /srv/SAMSUNG-850-PRO 69c930c7-8035-45bc-ac5d-e52bf39a107f
/dev/sdb 2.7T disk TOSHIBA_HDWU130
/dev/sdb1 2.7T part /srv/TOSHIBA-3T-V300 8f1560d4-dac7-42f6-835a-adbaf0df2fe1
/dev/sdc 1.8T disk Elements_10B8
/dev/sdc1 1.8T part /srv/WD-2T-USB F474B7AA74B76DCC
/dev/sdd 3.7T disk HGST_HUS726040AL
/dev/sdd1 3.7T part /srv/HGST-4T 4b98c45d-b7cf-4bbc-819e-7283b3f5247e
/dev/sde 2.7T disk TOSHIBA_MG03ACA3
/dev/sde1 2.7T part /srv/TOSHIBA-3T-ENTERPRISE FCCB-C31F
/dev/nvme0n1 232.9G disk Samsung SSD 970 EVO 250GB
/dev/nvme0n1p1 512M part /boot/efi DC9D-9B44
/dev/nvme0n1p2 1G part /boot 480d97d7-9613-43f0-aa10-089988d8ea04
/dev/nvme0n1p3 231.4G part Qp4dGc-yfAo-hKMR-00As-Lwr1-O60b-gEBO7o
7. blkid
prints the attributes of the block device (partitions and storage media) such as uuid and the type of file system. Note: Does not report the space on the partitions.
@ blkid
/dev/nvme0n1p1: UUID="DC9D-9B44" TYPE="vfat" PARTUUID="8c33a40d-1614-43b0-beb6-ed1dd683f272"
/dev/nvme0n1p2: UUID="480d97d7-9613-43f0-aa10-089988d8ea04" TYPE="ext4" PARTUUID="d8749998-ec49-497f-931d-fb04edba1675"
/dev/nvme0n1p3: UUID="Qp4dGc-yfAo-hKMR-00As-Lwr1-O60b-gEBO7o" TYPE="LVM2_member" PARTUUID="42f2aba8-030a-427e-8671-3efcdc94edd0"
/dev/sda1: LABEL="SAMSUNG-850-PRO" UUID="69c930c7-8035-45bc-ac5d-e52bf39a107f" TYPE="ext4" PARTLABEL="primary" PARTUUID="ce799da8-2abe-49b4-83ce-2b1d4dedcb4d"
/dev/sdb1: LABEL="topmovie" UUID="8f1560d4-dac7-42f6-835a-adbaf0df2fe1" TYPE="ext4" PARTLABEL="primary" PARTUUID="2afb0def-dc44-4483-8896-1a55c1974f6e"
/dev/sdc1: LABEL="W-MEDIA" UUID="F474B7AA74B76DCC" TYPE="ntfs" PARTUUID="aee4ad06-01"
/dev/sdd1: LABEL="HGST-4TB" UUID="4b98c45d-b7cf-4bbc-819e-7283b3f5247e" TYPE="ext4" PARTLABEL="primary" PARTUUID="b1883b52-a37d-49db-903e-0cceb188f0b8"
/dev/sde1: LABEL="MOVIE2020" UUID="FCCB-C31F" TYPE="exfat" PTTYPE="atari" PARTLABEL="Basic data partition" PARTUUID="ee66f8e9-5073-4757-905e-ac86406ae9e2"
/dev/mapper/ubuntu--vg-ubuntu--lv: UUID="ad2242f7-dc17-44ad-b977-897c77a186d8" TYPE="ext4"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
you can list device with filter by type partition, example for ext4
:
@ blkid -t TYPE=ext4
/dev/nvme0n1p2: UUID="480d97d7-9613-43f0-aa10-089988d8ea04" TYPE="ext4" PARTUUID="d8749998-ec49-497f-931d-fb04edba1675"
/dev/sda1: LABEL="SAMSUNG-850-PRO" UUID="69c930c7-8035-45bc-ac5d-e52bf39a107f" TYPE="ext4" PARTLABEL="primary" PARTUUID="ce799da8-2abe-49b4-83ce-2b1d4dedcb4d"
/dev/sdb1: LABEL="topmovie" UUID="8f1560d4-dac7-42f6-835a-adbaf0df2fe1" TYPE="ext4" PARTLABEL="primary" PARTUUID="2afb0def-dc44-4483-8896-1a55c1974f6e"
/dev/sdd1: LABEL="HGST-4TB" UUID="4b98c45d-b7cf-4bbc-819e-7283b3f5247e" TYPE="ext4" PARTLABEL="primary" PARTUUID="b1883b52-a37d-49db-903e-0cceb188f0b8"
/dev/mapper/ubuntu--vg-ubuntu--lv: UUID="ad2242f7-dc17-44ad-b977-897c77a186d8" TYPE="ext4"
8. mke2fs
is used to create an ext2, ext3, or ext4 filesystem, usually in a disk partition.
example with format disk partition in ext4 type:
@ mke4fs -t ext4 /dev/sdd1
this last command is similar with next mkfs command:
@ mkfs.ext4 /dev/sdd1
9. mkfs
is used to format a Linux file system on a device, usually a hard disk partition, and actuality is simply a front-end for the various file system builders (mkfs.fstype) available under Linux OS.
@ mkfs.ext2 /dev/sda1 @ mkfs.ext3 /dev/sdb1 @ mkfs.ext4 /dev/sdd1
10. tune2fs
adjust tunable file system parameters on the ext2, ext3 or ext4 Linux file systems.
The current values of these options can be displayed by using the -l option :
@ tune2fs -l /dev/sdd1
tune2fs 1.45.5 (07-Jan-2020)
Filesystem volume name: HGST-4TB
Last mounted on: /srv/HGST-4T
Filesystem UUID: 4b98c45d-b7cf-4bbc-819e-7283b3f5247e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 244195328
Block count: 976754176
Reserved block count: 48837708
Free blocks: 904226234
Free inodes: 244195110
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 1024
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Tue Dec 22 13:57:55 2020
Last mount time: Wed Dec 23 14:41:50 2020
Last write time: Wed Dec 23 14:44:23 2020
Mount count: 3
Maximum mount count: -1
Last checked: Tue Dec 22 13:57:55 2020
Check interval: 0 ()
Lifetime writes: 284 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 32
Desired extra isize: 32
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: eea7c603-9c96-43ba-907b-ad22a23d3431
Journal backup: inode blocks
Checksum type: crc32c
Checksum: 0x5a7626e9
Example to determine the block size of an etx2/ext3/ext4 partition on Linux, filter output with grep:
@ tune2fs -l /dev/sdd1 | grep -i 'block size'
Block size: 4096
11. stat
is a Linux command-line utility that displays detailed information about given files or file systems.
using stat command in the curent folder:
root@byrev:/srv/WD-2T-USB# stat .
File: .
Size: 69632 Blocks: 136 IO Block: 4096 directory
Device: 821h/2081d Inode: 5 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ userx) Gid: ( 1000/ userx)
Access: 2020-12-16 20:52:10.394697300 +0000
Modify: 2020-12-16 20:52:10.392883100 +0000
Change: 2020-12-16 20:52:10.392883100 +0000
Birth: -
using stat command in the any path:
@ stat /dev/sda1
12. dumpe2fs
dump ext2/ext3/ext4 filesystem information; prints the super block and blocks group information for the filesystem present on device.
-h option displays only superblock information and not any of the detailed information about the block group descriptor:
@ dumpe2fs -h /dev/sdd1
dumpe2fs 1.45.5 (07-Jan-2020)
Filesystem volume name: HGST-4TB
Last mounted on: /srv/HGST-4T
Filesystem UUID: 4b98c45d-b7cf-4bbc-819e-7283b3f5247e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 244195328
Block count: 976754176
Reserved block count: 48837708
Free blocks: 904226234
Free inodes: 244195110
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 1024
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Tue Dec 22 13:57:55 2020
Last mount time: Wed Dec 23 14:41:50 2020
Last write time: Wed Dec 23 14:44:23 2020
Mount count: 3
Maximum mount count: -1
Last checked: Tue Dec 22 13:57:55 2020
Check interval: 0 ()
Lifetime writes: 284 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 32
Desired extra isize: 32
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: eea7c603-9c96-43ba-907b-ad22a23d3431
Journal backup: inode blocks
Checksum type: crc32c
Checksum: 0x5a7626e9
Journal features: journal_incompat_revoke journal_64bit journal_checksum_v3
Journal size: 1024M
Journal length: 262144
Journal sequence: 0x00000772
Journal start: 1
Journal checksum type: crc32c
Journal checksum: 0x6761e6f7
13. e2label
Change disk label in linux/ubuntu using e2label command:
@ e2label /dev/sdf1 SAMSUNG-8T
Leave a Reply
Your email address will not be published. Required fields are marked *