记录新服务器的磁盘挂载流程
1.背景
scss
申请的服务器到了。
服务器配置:CPU(虚拟核数):
16C, 内存(GB):64G
系统盘(GB):100G
数据盘:3300G
操作系统:CentOS8.2.v1
数量:XX台
磁盘挂载
拿到服务器最先想到的是挂载一下数据盘(新服务器一般都是自行挂载的)
1.观察磁盘分区状态 可以看到有个3.2T 数据盘
ruby
[root@k8s03 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 378K 0 rom
vda 253:0 0 100G 0 disk
`-vda1 253:1 0 100G 0 part /
vdb 253:16 0 3.2T 0 disk
2.挂载注意事项
创建分区有两个工具: 1.faisk 2. parted
注意:fdisk命令只支持msdos,分区的时候只支持小容量硬盘(<=2T),而parted支持大硬盘。就现状分配3.4T数据盘而言,需要parted工具进行分配
3.使用parted工具进行分区创建
ini
[root@k8s03 /]# parted /dev/vdb
GNU Parted 3.2
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3543GB //全部磁盘空间
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) mkpart
Partition name? []? vdb1
File system type? [ext2]? xfs // 文件系统类型:ext4、XFS、NTFS、FAT32、exFAT ......跟据特点选择
Start? 0
End? 3543GB
Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s
Ignore/Cancel? Ignore
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3543GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 3543GB 3543GB xfs vdb1
(parted) quit
Information: You may need to update /etc/fstab.
[root@k8s03 /]# mkfs
mkfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
[root@k8s03 /]# mkfs.xfs /dev/vdb1 //格式化数据盘
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=216268798 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=865075191, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=422399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
ruby
[root@k8s03 //]# mkdir /data
[root@k8s03 //]# mount /dev/vdb1 /data/
[root@k8s03 //]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 857M 31G 3% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/vda1 100G 3.3G 97G 4% /
tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/vdb1 3.3T 24G 3.2T 1% /data
这样就挂载成功了!
4.设置自动挂载
磁盘被手动挂载之后都必须把挂载信息写入/etc/fstab这个文件中,否则下次开机启动时仍然需要重新挂载。系统开机时会主动读取/etc/fstab这个文件中的内容,根据文件里面的配置挂载磁盘。这样我们只需要将磁盘的挂载信息写入这个文件中我们就不需要每次开机启动之后手动进行挂载了。
ini
[root@k8s03 //]# blkid //查询分区uuid
/dev/sr0: UUID="2024-06-12-10-04-18-00" LABEL="config-2" TYPE="iso9660"
/dev/vda1: UUID="89c8b1b1-23df-4f7c-95a7-6358f693aaef" TYPE="xfs" PARTUUID="a0b3e45c-01"
/dev/vdb1: UUID="39ffa0df-9ccf-4b1e-ae54-bc2382d43b21" TYPE="xfs" PARTLABEL="vdb1" PARTUUID="e51e1d9c-a1c0-48eb-bf88-71e367fcb961"
ini
[root@k8s03 //]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 16 07:30:50 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=89c8b1b1-23df-4f7c-95a7-6358f693aaef / xfs defaults 0 0
UUID=39ffa0df-9ccf-4b1e-ae54-bc2382d43b21 /data xfs defaults 0 0
保存修改,然后重启系统
reboot
重启后,挂载信息正常即可。
bash
[root@k8s03 //]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 857M 31G 3% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/vda1 100G 3.3G 97G 4% /
tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/vdb1 3.3T 24G 3.2T 1% /data