How to format and partition disk on CentOS 7

This is not a tutorial. I just simply memo what I did to reset ( re-partition and format ) disk which was used for CentOS 6.6 in order to use on CentOS 7.

If Gnome GUI can be used, there is a graphical tool under Applications > Utilities > Disks. This is easier than command line command, fdisk and more intuitive.

If Gnome GUI can not be used, fdisk can be used to re-partition and format disk.

Check installed disks

The disk /dev/sdc is the one I want to re-partition and format.

[root@localhost ~]# sudo fdisk -l

Disk /dev/sdb: 320.1 GB, 320072933376 bytes, 625142448 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: gpt


#         Start          End    Size  Type            Name
 1         2048       411647    200M  EFI System      EFI System Partition
 2       411648      1435647    500M  Microsoft basic 
 3      1435648     50587647   23.4G  Linux swap      
 4     50587648    621975551  272.5G  Microsoft basic 

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     3278847     1638400   82  Linux swap / Solaris
/dev/sdc2   *     3278848   625141759   310931456   83  Linux

Re-partitioning ( delete and save )


[root@localhost ~]# fdisk /dev/sdc
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): p

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     3278847     1638400   82  Linux swap / Solaris
/dev/sdc2   *     3278848   625141759   310931456   83  Linux

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

Command (m for help): p

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     3278847     1638400   82  Linux swap / Solaris

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): p

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

   Device Boot      Start         End      Blocks   Id  System

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

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


Add new partition

[root@localhost ~]# fdisk /dev/sdc
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): p

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

   Device Boot      Start         End      Blocks   Id  System


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): 
First sector (2048-625142447, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-625142447, default 625142447): 
Using default value 625142447
Partition 1 of type Linux and of size 298.1 GiB is set

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

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


Check partitions


[root@localhost ~]$ sudo fdisk -l /dev/sdc

Disk /dev/sdc: 320.1 GB, 320072933376 bytes, 625142448 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: 0xeee30193

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   625142447   312570200   83  Linux

Formatting disk


sudo mkfs.xfs /dev/sdc1

References

 

One thought on “How to format and partition disk on CentOS 7

  1. Pingback: Openstack – new volume – Helge's blog

Leave a Reply