Managing Disks, Partitions and File Systems

Define Disks, Partitions and File systems and Its type

Advantage and Disadvantage.

Disk Partition and its type

Getting ready

$ vagrant up
$ vagrant ssh

How to do it

configure MBR with fdisk

From the man pages fdisk , it manipulate disk partition table. use helping command for fdisk

# fdisk --help

fdisk key option for basic

$ sudo fdisk --help
fdisk: invalid option -- '-'
Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track
$ sudo fdsik -l
$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):
creating/managing Simple partition
$ sudo fdisk -l

Disk /dev/sda: 15.4 GB, 15448023040 bytes, 30171920 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00032ce9

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    30171135    14572544   8e  Linux LVM

Disk /dev/sdb: 11.9 GB, 11938160640 bytes, 23316720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/cl-root: 13.3 GB, 13329498112 bytes, 26034176 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/cl-swap: 1547 MB, 1547698176 bytes, 3022848 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xcd3c1eb0.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-23316719, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-23316719, default 23316719): +500M
Partition 1 of type Linux and of size 500 MiB is set

Command (m for help): p

Disk /dev/sdb: 11.9 GB, 11938160640 bytes, 23316720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xcd3c1eb0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1026047      512000   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo partprobe
$ sudo cat /proc/partitions 
major minor  #blocks  name

   8        0   15085960 sda
   8        1     512000 sda1
   8        2   14572544 sda2
   8       16   11658360 sdb
   8       17     512000 sdb1
 253        0   13017088 dm-0
 253        1    1511424 dm-1
creating/managing swap space
$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (1026048-23316719, default 1026048): 
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-23316719, default 23316719): +1024M
Partition 2 of type Linux and of size 1 GiB is set

Command (m for help): p

Disk /dev/sdb: 11.9 GB, 11938160640 bytes, 23316720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xcd3c1eb0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1026047      512000   83  Linux
/dev/sdb2         1026048     3123199     1048576   83  Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p

Disk /dev/sdb: 11.9 GB, 11938160640 bytes, 23316720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xcd3c1eb0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1026047      512000   83  Linux
/dev/sdb2         1026048     3123199     1048576   82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo partprobe
$ sudo cat /proc/partitions 
major minor  #blocks  name

   8        0   15085960 sda
   8        1     512000 sda1
   8        2   14572544 sda2
   8       16   11658360 sdb
   8       17     512000 sdb1
   8       18    1048576 sdb2
 253        0   13017088 dm-0
 253        1    1511424 dm-1

Make swap file system

$ sudo mkswap /dev/sdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=73d6f881-0e2b-47ce-8826-7c9e241b78fe
Deleting partition
$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): d
Partition number (1,2, default 2): 1
Partition 1 is deleted

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

GPT partition

Manage GPT with gdisk

From the man pages gdisk , it manipulate disk partition table. use helping command for gdisk

# gdisk --help

gdisk key option for basic

$ sudo gdisk --help
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Command (? for help):
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-23316686, default = 2048) or {+-}size{KMGTP}: 2048
Last sector (2048-23316686, default = 23316686) or {+-}size{KMGTP}: +500M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8300
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdb: 23316720 sectors, 11.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 82E73976-D4E1-4285-B008-A93959FE66DA
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 23316686
Partitions will be aligned on 2048-sector boundaries
Total free space is 22292653 sectors (10.6 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
$ sudo partprobe
$ sudo cat /proc/partitions 
major minor  #blocks  name

   8        0   15085960 sda
   8        1     512000 sda1
   8        2   14572544 sda2
   8       16   11658360 sdb
   8       17     512000 sdb1
 253        0   13017088 dm-0
 253        1    1511424 dm-1
creating/managing swap space
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-23316686, default = 1026048) or {+-}size{KMGTP}: 
Last sector (1026048-23316686, default = 23316686) or {+-}size{KMGTP}: +1024M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8e00 Linux LVM             a500 FreeBSD disklabel     a501 FreeBSD boot        
a502 FreeBSD swap          a503 FreeBSD UFS           a504 FreeBSD ZFS         
a505 FreeBSD Vinum/RAID    a580 Midnight BSD data     a581 Midnight BSD boot   
a582 Midnight BSD swap     a583 Midnight BSD UFS      a584 Midnight BSD ZFS    
a585 Midnight BSD Vinum    a800 Apple UFS             a901 NetBSD swap         
a902 NetBSD FFS            a903 NetBSD LFS            a904 NetBSD concatenated 
a905 NetBSD encrypted      a906 NetBSD RAID           ab00 Apple boot          
af00 Apple HFS/HFS+        af01 Apple RAID            af02 Apple RAID offline  
af03 Apple label           af04 AppleTV recovery      af05 Apple Core Storage  
be00 Solaris boot          bf00 Solaris root          bf01 Solaris /usr & Mac Z
bf02 Solaris swap          bf03 Solaris backup        bf04 Solaris /var        
bf05 Solaris /home         bf06 Solaris alternate se  bf07 Solaris Reserved 1  
bf08 Solaris Reserved 2    bf09 Solaris Reserved 3    bf0a Solaris Reserved 4  
bf0b Solaris Reserved 5    c001 HP-UX data            c002 HP-UX service       
ed00 Sony system partitio  ef00 EFI System            ef01 MBR partition scheme
ef02 BIOS boot partition   fb00 VMWare VMFS           fb01 VMWare reserved     
fc00 VMWare kcore crash p  fd00 Linux RAID            
Hex code or GUID (L to show codes, Enter = 8300):  8200
Changed type of partition to 'Linux swap'

Command (? for help): p
Disk /dev/sdb: 23316720 sectors, 11.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 82E73976-D4E1-4285-B008-A93959FE66DA
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 23316686
Partitions will be aligned on 2048-sector boundaries
Total free space is 20195501 sectors (9.6 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048         3123199   1024.0 MiB  8200  Linux swap

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
$ sudo partprobe
$ sudo cat /proc/partitions 
major minor  #blocks  name

   8        0   15085960 sda
   8        1     512000 sda1
   8        2   14572544 sda2
   8       16   11658360 sdb
   8       17     512000 sdb1
   8       18    1048576 sdb2
 253        0   13017088 dm-0
 253        1    1511424 dm-1
$ sudo mkswap /dev/sdb1
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=5f2257bc-ef5a-4d27-9664-97d5cf78bcef
Deleting partition
$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Command (? for help): d
Partition number (1-2): 1

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

Creating/Making file Systems

Now For Btrfs file system

$ sudo  mkfs.btrfs /dev/sdb1
SMALL VOLUME: forcing mixed metadata/data groups
btrfs-progs v3.19.1
See http://btrfs.wiki.kernel.org for more information.

Turning ON incompat feature 'mixed-bg': mixed data and metadata block groups
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
Created a data/metadata chunk of size 8388608
fs created label (null) on /dev/sdb1
    nodesize 4096 leafsize 4096 sectorsize 4096 size 500.00MiB

For XFS file system

$ sudo mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

For ext4 file systems

$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

Type of file system

$ sudo mkfs press[TAB]
mkfs         mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
changing/maintenance the File Systems and Troubleshooting
$ sudo  mkfs.btrfs -f /dev/sdb1
$ sudo mkfs.xfs -f /dev/sdb1
$ sudo mkfs.ext4 -f /dev/sdb1

Use Syntax of Disk Space and Disk Use

Disk Space

From the man pages df, it report file system disk space usage.

use helping command for df

# df --help

df key option for basic

$ df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include dummy file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
      --direct          show statistics for a file instead of mount point
      --total           produce a grand total
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

check the disk space usage

$ df
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/mapper/cl-root  13006848 5599380   7407468  44% /
devtmpfs               744500       0    744500   0% /dev
tmpfs                  759820     156    759664   1% /dev/shm
tmpfs                  759820    8920    750900   2% /run
tmpfs                  759820       0    759820   0% /sys/fs/cgroup
tmpfs                  759820     164    759656   1% /tmp
/dev/sda1              508588  169616    338972  34% /boot
tmpfs                  151968      12    151956   1% /run/user/1000

View information of file system usage

$ df -a
Filesystem          1K-blocks    Used Available Use% Mounted on
rootfs                      -       -         -    - /
sysfs                       0       0         0    - /sys
proc                        0       0         0    - /proc
devtmpfs               744500       0    744500   0% /dev
securityfs                  0       0         0    - /sys/kernel/security
tmpfs                  759820     156    759664   1% /dev/shm
devpts                      0       0         0    - /dev/pts
tmpfs                  759820    8920    750900   2% /run
tmpfs                  759820       0    759820   0% /sys/fs/cgroup
cgroup                      0       0         0    - /sys/fs/cgroup/systemd
pstore                      0       0         0    - /sys/fs/pstore
cgroup                      0       0         0    - /sys/fs/cgroup/cpuset
cgroup                      0       0         0    - /sys/fs/cgroup/net_cls
cgroup                      0       0         0    - /sys/fs/cgroup/freezer
cgroup                      0       0         0    - /sys/fs/cgroup/devices
cgroup                      0       0         0    - /sys/fs/cgroup/memory
cgroup                      0       0         0    - /sys/fs/cgroup/perf_event
cgroup                      0       0         0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                      0       0         0    - /sys/fs/cgroup/blkio
cgroup                      0       0         0    - /sys/fs/cgroup/hugetlb
configfs                    0       0         0    - /sys/kernel/config
/dev/mapper/cl-root  13006848 5598604   7408244  44% /
selinuxfs                   0       0         0    - /sys/fs/selinux
systemd-1                   0       0         0    - /proc/sys/fs/binfmt_misc
hugetlbfs                   0       0         0    - /dev/hugepages
tmpfs                  759820     164    759656   1% /tmp
debugfs                     0       0         0    - /sys/kernel/debug
mqueue                      0       0         0    - /dev/mqueue
sunrpc                      0       0         0    - /var/lib/nfs/rpc_pipefs
nfsd                        0       0         0    - /proc/fs/nfsd
/dev/sda1              508588  169616    338972  34% /boot
tmpfs                  151968      12    151956   1% /run/user/1000
fusectl                     0       0         0    - /sys/fs/fuse/connections
gvfsd-fuse                  0       0         0    - /run/user/1000/gvfs

View Disk spce in human readable format

$ df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   13G  5.4G  7.1G  44% /
devtmpfs             728M     0  728M   0% /dev
tmpfs                743M  156K  742M   1% /dev/shm
tmpfs                743M  8.8M  734M   2% /run
tmpfs                743M     0  743M   0% /sys/fs/cgroup
tmpfs                743M  172K  742M   1% /tmp
/dev/sda1            497M  166M  332M  34% /boot
tmpfs                149M   12K  149M   1% /run/user/1000

view inforamation file system in byte

$ df -k
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/mapper/cl-root  13006848 5598800   7408048  44% /
devtmpfs               744500       0    744500   0% /dev
tmpfs                  759820     156    759664   1% /dev/shm
tmpfs                  759820    8920    750900   2% /run
tmpfs                  759820       0    759820   0% /sys/fs/cgroup
tmpfs                  759820     172    759648   1% /tmp
/dev/sda1              508588  169616    338972  34% /boot
tmpfs                  151968      12    151956   1% /run/user/1000

view inforamation file system in megabyte

$ df -m
Filesystem          1M-blocks  Used Available Use% Mounted on
/dev/mapper/cl-root     12702  5469      7234  44% /
devtmpfs                  728     0       728   0% /dev
tmpfs                     743     1       742   1% /dev/shm
tmpfs                     743     9       734   2% /run
tmpfs                     743     0       743   0% /sys/fs/cgroup
tmpfs                     743     1       742   1% /tmp
/dev/sda1                 497   166       332  34% /boot
tmpfs                     149     1       149   1% /run/user/1000

View informatin file system Inode

$ df -i
Filesystem            Inodes  IUsed    IFree IUse% Mounted on
/dev/mapper/cl-root 13017088 148235 12868853    2% /
devtmpfs              186125    371   185754    1% /dev
tmpfs                 189955     10   189945    1% /dev/shm
tmpfs                 189955    491   189464    1% /run
tmpfs                 189955     13   189942    1% /sys/fs/cgroup
tmpfs                 189955     32   189923    1% /tmp
/dev/sda1             512000    345   511655    1% /boot
tmpfs                 189955     30   189925    1% /run/user/1000

View information file system Type

]$ df -T
Filesystem          Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/cl-root xfs       13006848 5599264   7407584  44% /
devtmpfs            devtmpfs    744500       0    744500   0% /dev
tmpfs               tmpfs       759820     156    759664   1% /dev/shm
tmpfs               tmpfs       759820    8920    750900   2% /run
tmpfs               tmpfs       759820       0    759820   0% /sys/fs/cgroup
tmpfs               tmpfs       759820     172    759648   1% /tmp
/dev/sda1           xfs         508588  169616    338972  34% /boot
tmpfs               tmpfs       151968      12    151956   1% /run/user/1000

View limited file system

$ df -t xfs
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/mapper/cl-root  13006848 5599116   7407732  44% /
/dev/sda1              508588  169616    338972  34% /boot

View does not belong to xfs file system

$ df -x xfs
Filesystem     1K-blocks  Used Available Use% Mounted on
devtmpfs          744500     0    744500   0% /dev
tmpfs             759820   156    759664   1% /dev/shm
tmpfs             759820  8920    750900   2% /run
tmpfs             759820     0    759820   0% /sys/fs/cgroup
tmpfs             759820   172    759648   1% /tmp
tmpfs             151968    12    151956   1% /run/user/1000

Disk Use

From the man pages du, it estimate file space usage.

use helping command for du

# du --help

du key option for basic

]$ du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with 0 byte rather than newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize disk usage of the
                          NUL-terminated file names specified in file F;
                          if F is -, then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes          list inode usage information instead of block usage
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   for directories do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using STYLE, which can be:
                            full-iso, long-iso, iso, or +FORMAT;
                            FORMAT is interpreted like in 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

View usage summary of disk

$ du /home/centos7server/
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
12    /home/centos7server/

View disk in human readable format

$ du -h /home/centos7server/
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
12K    /home/centos7server/

View total disk use

$ du -sh /home/centos7server/
12k    /home/centos7server/

View with hidden file

$ du -a /home/centos7server/
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
4    /home/centos7server/.bash_logout
4    /home/centos7server/.bash_profile
4    /home/centos7server/.bashrc
12    /home/centos7server/

VIew flag with -h

$ du -ah /home/centos7server/
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
4.0K    /home/centos7server/.bash_logout
4.0K    /home/centos7server/.bash_profile
4.0K    /home/centos7server/.bashrc
12K    /home/shyam/

View modification time

# du -ha --time /home/centos7server/
0    2014-06-10 01:07    /home/centos7server/.mozilla/extensions
0    2014-06-10 01:07    /home/centos7server/.mozilla/plugins
0    2015-12-10 16:30    /home/centos7server/.mozilla
4.0K    2015-11-20 10:32    /home/centos7server/.bash_logout
4.0K    2015-11-20 10:32    /home/centos7server/.bash_profile
4.0K    2015-11-20 10:32    /home/centos7server/.bashrc
12K    2016-05-25 11:00    /home/centos7server/

VIew

$ du -ah --exclude="*.txt" /home/centos7server
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
4.0K    /home/centos7server/.bash_logout
4.0K    /home/centos7server/.bash_profile
4.0K    /home/centos7server/.bashrc
12K    /home/centos7server

View total count

$ du -ch /home/centos7server
0    /home/centos7server/.mozilla/extensions
0    /home/centos7server/.mozilla/plugins
0    /home/centos7server/.mozilla
12K    /home/shyam/
12K    total
$ du -mh /home/centos7server
$ du -k /home/centos7server

How it work

results matching ""

    No results matching ""