I would like to add a new storage disk on my CentOS 7 linux system . How Do I format newly added hard disk to XFS or EXT4/3 file system under CentOS7/6.5 or RHEL 7/6.5? How To create a new partition for a new disk on centos 7 system? This post will show you how to format linux filesystem for a hard disk.
You need to use “fdisk” command firstly to create a new partition and using “mkfs” command to format or build a file system on that partition.
CentOS 7/RHEL 7 Find the New Added Hardward Disk
To find the new added hardward disk on you system so that you can create a new partition on the new hardware disk, type:
cat /proc/partition
or
ls /dev/sd* or ls /dev/hd*
outputs:
[root@devops Desktop]# cat /proc/partitions major minor #blocks name 11 0 56976 sr0 8 0 46603360 sda 8 1 512000 sda1 8 2 46090240 sda2 8 16 8388608 sdb 253 0 2129920 dm-0 253 1 43958272 dm-1 [root@devops Desktop]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sdb
Form above outputs, you can see that there is a new disk “sdb” added just now.
CentOS 7/RHEL7 Add a New Partition
To add a new partition on newly added hardware disk “/dev/sdb“, you need to use “fdisk” command with “hardware disk name”, type:
fdisk /dev/sdb
outputs:
[root@devops Desktop]# 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 0xc484f67f. Command (m for help): m #======>print help message 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 #========> press "n" key to 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): First sector (2048-16777215, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): Using default value 16777215 Partition 1 of type Linux and of size 8 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Now a new parition will be added in partition table, you can use “cat /proc/partition” command to check, there is a new line “sdb1”.
[root@devops Desktop]# cat /proc/partitions
major minor #blocks name
11 0 56976 sr0
8 0 46603360 sda
8 1 512000 sda1
8 2 46090240 sda2
8 16 8388608 sdb
8 17 8387584 sdb1
253 0 2129920 dm-0
253 1 43958272 dm-1
CentOS 7/RHEL7 Format Filesystem For A partition
While you installed centos 7 or RHEL 7 Os on your machine, it will format partition as a new “XFS” filesystem by default. so I will show you how to format filesystem as XFS on a new partition. issue the following command:
mkfs.xfs /dev/sdb1
outputs:
[root@devops Desktop]# mkfs.xfs /dev/sdb1 meta-data=/dev/sdb1 isize=256 agcount=4, agsize=524224 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=2096896, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@devops Desktop]#
If you want to format filesystem as “EXT4” for partition “/dev/sdb1”, just simply run the following command:
mkfs.ext4 /dev/sdb1
outputs:
[root@devops Desktop]# mkfs.ext4 /dev/sdb1 Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 524288 inodes, 2097152 blocks 104857 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2147483648 64 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Last, you can mount the new file system, type the following command:
mount /dev/sdb1 /mnt
done…