Add new disk to Centos 7

A series of articles on working with a hard drive

  • Mount a new disk in CentOS
  • How to grow LVM partition on CentOS 7
  • Add new disk to Centos 7
  • How to delete / home partition and expand root partition in Centos 7
  • Mount LVM partition on Ubuntu 18.04 / 18.10
  • Extend LVM partition for GPT disk tables on Centos 7

Add the disk to the system, check if it appears:

[[email protected]]# fdisk -l

Divide the disk into partitions

[[email protected]]# fdisk /dev/sdb

Команда (m для справки): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Номер раздела (1-4, default 1): 1
Первый sector (2048-167772159, по умолчанию 2048): 
Используется значение по умолчанию 2048
Last sector, +sectors or +size{K,M,G} (2048-167772159, по умолчанию 167772159): 
Используется значение по умолчанию 167772159
Partition 1 of type Linux and of size 80 GiB is set

Команда (m для справки): w
Таблица разделов была изменена!

Вызывается ioctl() для перечитывания таблицы разделов.
Синхронизируются диски.

Where: n – create partition p – primary partition w – save changes

We check if the / dev / sdb1 partition should appear

[[email protected]]# fdisk -l /dev/sdb

Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0xfbf1a157

Create an ext4 file system on a new partition

[[email protected]]# mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20971264 blocks
1048563 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2168455168
640 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, 2654208, 
	4096000, 7962624, 11239424, 20480000

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

Mount a new disk to the / opt directory and see the result

[[email protected]]# mount -t ext4 /dev/sdb1 /opt
[[email protected]]# df -h

Файловая система                         Размер Использовано  Дост Использовано% Cмонтировано в
/dev/mapper/centos_srv--tiledev--01-root    22G         1,4G   21G            7% /
devtmpfs                                   7,8G            0  7,8G            0% /dev
tmpfs                                      7,8G            0  7,8G            0% /dev/shm
tmpfs                                      7,8G          17M  7,8G            1% /run
tmpfs                                      7,8G            0  7,8G            0% /sys/fs/cgroup
/dev/sda1                                  497M         156M  342M           32% /boot
tmpfs                                      1,6G            0  1,6G            0% /run/user/0
/dev/sdb1                                   79G          57M   75G            1% /opt

We set up automatic disk mounting at system startup, for this we edit / etc / fstab at the very end, add:

[[email protected]]# nano /etc/fstab
/dev/sdb1 /opt ext4 defaults 0 0