一:查看磁盘信息
[root@xxx ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 253:0 0 100G 0 disk
├─vda1 253:1 0 600M 0 part /boot/efi
├─vda2 253:2 0 1G 0 part /boot
└─vda3 253:3 0 98.4G 0 part
├─klas_host--10--175--1--143-root 252:0 0 90.4G 0 lvm /
└─klas_host--10--175--1--143-swap 252:1 0 8G 0 lvm [SWAP]
vdb 253:16 0 200G 0 disk
[root@xxx ~]# dh -f
-bash: dh: command not found
## 查看磁盘使用情况,会发现我的vdb磁盘并没有挂载进来
[root@xxx ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.1G 0 7.1G 0% /dev
tmpfs 7.4G 0 7.4G 0% /dev/shm
tmpfs 7.4G 53M 7.3G 1% /run
tmpfs 7.4G 0 7.4G 0% /sys/fs/cgroup
/dev/mapper/klas_host--10--175--1--143-root 91G 8.7G 82G 10% /
tmpfs 7.4G 128K 7.4G 1% /tmp
/dev/vda2 1014M 222M 793M 22% /boot
/dev/vda1 599M 6.5M 593M 2% /boot/efi
tmpfs 1.5G 0 1.5G 0% /run/user/993
tmpfs 1.5G 0 1.5G 0% /run/user/0
## 查看磁盘目录信息
[root@xxx ~]# ls /dev/vdb*
/dev/vdb
可以看到我的vdb磁盘是没有进行挂载的,挂载前需要先进行磁盘分区
二:硬盘分区
分区相关指令
m 显示命令列表
p 显示磁盘分区同fdisk -l
n 新增分区
d 删除分区
w 写入并退出
[root@xxx~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.35.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.
Created a new DOS disklabel with disk identifier 0x62ac3941.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-419430399, default 419430399):
Created a new partition 1 of type 'Linux' and of size 200 GiB.
Command (m for help):
首先输入n新增分区,然后选择p分区类型为主分区。然后按回车键直到出现“Command(m for help):”,最后输入w写入分区并退出。
三:格式化硬盘分区,一定要格式化不然不会分配uuid
## 格式化硬盘分区
[root@xxx ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 52428544 4k blocks and 13107200 inodes
Filesystem UUID: 2130fb42-18cd-407c-9236-e11cb9cc01ee
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 (262144 blocks): done
Writing superblocks and filesystem accounting information: done
四:挂载磁盘
## 进入根目录
[root@xxx ~]# cd /
## 创建需要挂载的目录
[root@xxx /]# mkdir chanquan
## 设置挂载目录
[root@xxx /]# mount /dev/vdb1 /chanquan
## 查看磁盘信息后面出现/chanquan 说明已经挂载到这个目录上面了
[root@xxx /]# lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
sr0
vda
├─vda1 vfat FAT32 608A-BD92 592.4M 1% /boot/efi
├─vda2 xfs 3dbf7365-4c66-428d-987c-eafb7f14a236 792.8M 22% /boot
└─vda3 LVM2_member LVM2 001 5Xy3Qi-PRlh-VuhP-1Uwq-73Af-S3tk-sVHeUO
├─klas_host--10--175--1--143-root xfs f0bc98c0-d2fb-4339-b496-d53ec90036c2 81.7G 10% /
└─klas_host--10--175--1--143-swap swap 1 b89bc452-81dd-4ad5-aea6-5d3731ded378 [SWAP]
vdb
└─vdb1 ext4 1.0 2130fb42-18cd-407c-9236-e11cb9cc01ee 185.8G 0% /chanquan
注意:到这一步就已经挂载好了,但是服务器重启之后就会失效,所以还需要加一下配置
## 查看fstab文件
[root@xxx /]# vim /etc/fstab
## 添加该配置 /dev/vdb1用分配的uuid也可以
/dev/vdb1 /chanquan ext4 defaults 0 0
## 添加完配置后,执行mount -a即可生效
[root@xxx /]# mount -a
配置案例图
五:查看信息,如下/dev/vdb1已经挂载到/chanquan目录
[root@xxx /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.1G 0 7.1G 0% /dev
tmpfs 7.4G 0 7.4G 0% /dev/shm
tmpfs 7.4G 54M 7.3G 1% /run
tmpfs 7.4G 0 7.4G 0% /sys/fs/cgroup
/dev/mapper/klas_host--10--175--1--143-root 91G 8.7G 82G 10% /
tmpfs 7.4G 128K 7.4G 1% /tmp
/dev/vda2 1014M 222M 793M 22% /boot
/dev/vda1 599M 6.5M 593M 2% /boot/efi
tmpfs 1.5G 0 1.5G 0% /run/user/993
tmpfs 1.5G 0 1.5G 0% /run/user/0
/dev/vdb1 196G 61M 186G 1% /chanquan