Centos 挂载新磁盘 (1068 views)

gHOST

2019-12-09 20:03:56

查看当前未挂载的硬盘

[root@localhost ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000aaa23

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83875364    41936658+  83  Linux

Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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

可以看到 /dev/vdb 有 107.4 GB 没有分区

创建硬盘分区

  • 命令 fdisk /dev/vdb
  • 输入 n 新建分区
  • 输入 p 分区类型为主分区
  • 输入 1 分区数量
  • 回车 默认 2048 分区开始扇区
  • 回车 默认 209715199 分区截止扇区,这里将全部磁盘分配给新分区
  • 输入 wq 保存退出
[root@localhost ~]# fdisk /dev/vdb
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 0xbd01f8de.

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-209715199, default 2048): # 默认开始扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): # 默认结束扇区, 全盘全部用于该分区
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): wq # 保存退出
The partition table has been altered!

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

格式化刚刚创建的分区

[root@localhost ~]# mkfs.ext4 /dev/vdb1
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
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 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, 23887872

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

建立挂载目录

[root@localhost ~]# mkdir /data

获取新分区的 UUID

方法一

[root@localhost ~]# ll /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Dec  9 19:47 2a417d5c-6998-4381-bb19-de09165ba77e -> ../../vdb1
lrwxrwxrwx 1 root root 10 Dec  9 19:20 87ba1103-a0d7-49ef-a8ae-6ce1d3fd2453 -> ../../vda1

方法二

[root@localhost ~]# blkid /dev/vdb1
/dev/vdb1: UUID="2a417d5c-6998-4381-bb19-de09165ba77e" TYPE="ext4"

编辑 /etc/fstab 写入挂载磁盘信息

[root@localhost ~]# vi /etc/fstab

将以下内容写入文件

UUID=2a417d5c-6998-4381-bb19-de09165ba77e /data                   ext4    defaults        0 0

文件编辑之后的内容如下

#
# /etc/fstab
# Created by anaconda on Tue Oct  8 09:13:42 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=87ba1103-a0d7-49ef-a8ae-6ce1d3fd2453 /                       ext4    defaults        1 1
UUID=2a417d5c-6998-4381-bb19-de09165ba77e /data                   ext4    defaults        0 0

使修改之后的磁盘挂载配置生效

[root@localhost ~]# mount -a
[root@localhost ~]# df 
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         7985068       0   7985068   0% /dev
tmpfs            7995440       0   7995440   0% /dev/shm
tmpfs            7995440     444   7994996   1% /run
tmpfs            7995440       0   7995440   0% /sys/fs/cgroup
/dev/vda1       41147472 2108324  37135656   6% /
tmpfs            1599092       0   1599092   0% /run/user/1000
/dev/vdb1      103079864   61464  97759188   1% /data

完成