Hướng dẫn thêm ổ đĩa mới vào máy chủ centos – How to add new hard disk to Centos server

Môi trường thực hiện: Centos 7

ổ cứng mới = 80GB

mount point = /net

kiểm tra ổ đĩa mới thêm bằng fdisk -l

[root@localhost ~]# fdisk -l



Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b1107



   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200    41943039    19921920   8e  Linux LVM



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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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



[root@localhost ~]#

Thấy phần ổ đĩa mới: Disk /dev/sdb: 85.9 GB, 85899345920 bytes, 167772160 sectors
gõ: fdisk /dev/sdb

[root@localhost ~]# 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 0xa07e2d9e.



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):

First sector (2048-167772159, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159):

Using default value 167772159

Partition 1 of type Linux and of size 80 GiB is set



Command (m for help): w

The partition table has been altered!



Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]#

Đã tạo xong phân vùng, tiến hành format sang định dạng ext4, lưu ý, phân vùng mới tạo từ sdb ở trên giờ là sdb1

[root@localhost ~]# mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

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

Giờ ổ đĩa đã sẵn sàng, chỉ cần mount vào đâu đó thì chúng đã sẵn sàng sử dụng, ví dụ mount vào /net1

[root@localhost ~]# mount /dev/sdb1 /net1/

[root@localhost ~]#

[root@localhost ~]#

[root@localhost ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   17G  1.5G   16G   9% /

devtmpfs                 478M     0  478M   0% /dev

tmpfs                    489M     0  489M   0% /dev/shm

tmpfs                    489M  6.7M  482M   2% /run

tmpfs                    489M     0  489M   0% /sys/fs/cgroup

/dev/sda1               1014M  125M  890M  13% /boot

tmpfs                     98M     0   98M   0% /run/user/0

/dev/sdb1                 79G   57M   75G   1% /net1

Đã thêm thành công

Để tự động mount ổ khi reboot, có thể thao tác bằng nhiều cách:
– Chạy tự động lệnh mount /dev/sdb1 /net1/ mỗi lần khởi động
– thêm vào /etc/fstab

/dev/sdb1 /net1                       ext4     noauto        0 0