LVM挂载数据盘

查看硬盘分区:fdisk -l

LVM挂载数据盘_第1张图片

把root 分区的空间扩大,敲入下面的命令

逻辑卷扩容: lvextend –L +100g /dev/vol_name/lv_name (给/dev/vol_name/lv_name扩容100g)


LVM挂载数据盘_第2张图片

将vg空间划入分区:lvextend -L +10G 分区名

lvextend -l +100%FREE /dev/centos/root

进入分区管理: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 0x4da2e52d.

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-209717247, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-209717247, default 209717247): 107375230976
Partition 1 of type Linux and of size 511 MiB 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): p

Disk /dev/sdb: 107.4 GB, 107375230976 bytes, 209717248 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: 0x4da2e52d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     1048576      523264+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

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

[root@localhost /]# partprobe //使分区表生效,无需重启

删除硬盘上的LVM分区

1、fdisk /dev/sdb
2、Command (m for help): p
3、Command (m for help): d
Selected partition 1
4、Command (m for help): p <--在显示分区情况,发现已经没了
5、 Command (m for help): w

创建分区物理卷 删除分区:pvremove /dev/sdb1

[root@localhost /]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@localhost /]#

创建卷组

创建卷组:vgcreate vol_name /dev/sdb (vol_name 为卷组名字)

卷组添加成员 //VG添加成员 删除成员:vgreduce vg_test_01 /dev/sdb2

[root@localhost /]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 data-group lvm2 a-- <300.00g 1020.00m
/dev/sdb1 lvm2 --- 100.00g 100.00g
/dev/vda2 centos lvm2 a-- <99.00g 0
[root@localhost /]# vgextend data-group /dev/sdb1
Volume group "data-group" successfully extended

创建逻辑卷

[root@localhost /]# lvcreate -L 100G -n data1 data-group
Logical volume "data1" created.
[root@localhost /]#
[root@localhost /]# mkfs.xfs /dev/data-group/data1 //将逻辑卷格式化并指定文件类型xfs
meta-data=/dev/data-group/data1 isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
取消逻辑卷:lvremove /dev/vg0/lv0

挂载逻辑卷->文件系统

[root@localhost /]#
[root@localhost /]# mkdir data1
[root@localhost /]# mount /dev/data-group/data1 /data1 取消挂载:umount /mnt/lv0


LVM挂载数据盘_第3张图片

挂载报错:

[root@hyp-2 data]# mount /dev/mapper/data--group-data /data
mount: /dev/mapper/data--group-data is already mounted or /data busy


LVM挂载数据盘_第4张图片

[root@hyp-2 /]# mount /dev/mapper/data--group-data /data
mount: /dev/mapper/data--group-data is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
解决:
[root@hyp-2 /]# mkfs.xfs /dev/data-group/data
mkfs.xfs: /dev/data-group/data appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@hyp-2 /]# mkfs.xfs -f /dev/data-group/data 注意:需要加上-f

你可能感兴趣的:(LVM挂载数据盘)