文章目录
本文将一块新的存储盘挂在到/opt/data目录下,并将存储盘做成lvm格式,便于以后进行扩容和升级。
1 查看存储盘名称
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: 0x00093d87
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 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是需要分区挂在的硬盘
2 fdisk将新盘进行分区
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 0x75acc5e3.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 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): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
说明:
命令(输入 m 获取帮助):n 添加新的物理分区,全部选择默认值
命令(输入 m 获取帮助):t 输入t修改分区 id
Hex 代码(输入 L 列出所有代码):8e 8e分区修改为Linux LVM类型
命令(输入 m 获取帮助):w 输入 w 将修改写入磁盘
3 创建VG(卷组)
重新查看存储盘
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: 0x00093d87
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 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
Disk label type: dos
Disk identifier: 0x75acc5e3
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
最后多了 /dev/vdb1
创建VG卷组
vgcreate centos /dev/vdb1
回显下列信息成功
Physical volume "/dev/vdb1" successfully created.
Volume group "centos" successfully created
4 将VG卷全部空间作为lv逻辑卷
将VG卷全部空间作为lv逻辑卷,并取名data
lvcreate -l +100%FREE -n data centos
回显如下信息
Logical volume "data" created.
5 制作xfs文件格式
mkfs.xfs /dev/centos/data
回显如下信息
meta-data=/dev/centos/data isize=512 agcount=4, agsize=6553344 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26213376, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
6 将盘挂载到/opt/data目录下
mount -t xfs /dev/centos/data /opt/data
7 配置/etc/fstab确保重启后挂载
在文件最后追加内容:/dev/centos/dcos /dcos xfs defaults 1 2
echo /dev/centos/data /opt/data xfs defaults 1 2 >> /etc/fstab
8 查看挂载情况
df -lh
回显如下信息
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 3.1G 35G 9% /
devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 360M 3.3G 10% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
tmpfs 748M 0 748M 0% /run/user/0
/dev/mapper/centos-data 100G 33M 100G 1% /opt/data