在安装centos的时候由于对分区不熟悉,选择了默认分区,导致在安装mysql的时候,没有一个单独的分区来存放data。只能研究下如何调整lvm卷的大小了。。
用vgdisplay指令查看vg卷的大小
[root@localhost caoyong]# vgdisplay --- Volume group --- VG Name vg_centoscy System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 4 Open LV 4 Max PV 0 Cur PV 1 Act PV 1 VG Size 465.27 GiB PE Size 4.00 MiB Total PE 119109 Alloc PE / Size 119109 / 465.27 GiB Free PE / Size 0 / 0 VG UUID LKnVzD-DeMj-Fonv-zR9Z-vCHs-1TMl-2ELianVG Name 卷组名称
Free PE / Size 卷组剩余空间
vg_centoscy卷组中已经没有剩余空间让我分割给其他lvm,因此我们要从其他lvm中分割一部分空间出来
使用lvdisplay指令查看vg_centoscy到lvm分配情况
[root@localhost caoyong]# lvdisplay vg_centoscy --- Logical volume --- LV Path /dev/vg_centoscy/lv_root LV Name lv_root VG Name vg_centoscy LV UUID 4rlwmS-6ZZT-nGFE-aKgl-KZaW-FlUn-fMA9of LV Write Access read/write LV Creation host, time centos-cy, 2010-01-04 10:42:37 +0800 LV Status available # open 1 LV Size 50.00 GiB Current LE 12800 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_centoscy/lv_home LV Name lv_home VG Name vg_centoscy LV UUID IknYf3-lhXg-3qAU-kEum-Nhyj-2kiZ-SBdmHg LV Write Access read/write LV Creation host, time centos-cy, 2010-01-04 10:42:47 +0800 LV Status available # open 1 LV Size 400.00 GiB Current LE 102400 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_centoscy/lv_swap LV Name lv_swap VG Name vg_centoscy LV UUID 8pOAL1-o0kr-0glK-jJve-G6Oo-8mZM-DHxgPE LV Write Access read/write LV Creation host, time centos-cy, 2010-01-04 10:44:04 +0800 LV Status available # open 1 LV Size 3.72 GiB Current LE 952 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/vg_centoscy/data LV Name data VG Name vg_centoscy LV UUID p0X3ih-jDiQ-GN3B-R9Zd-U8qI-loSF-Sql6sc LV Write Access read/write LV Creation host, time localhost.localdomain, 2012-12-28 13:07:42 +0800 LV Status available # open 1 LV Size 11.55 GiB Current LE 2957 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
lvm的空间调整指令是
lvextend 增加lvm空间
lvreduce 减少lvm空间
这里使用-L 参数指定需要调整到大小
例如lvextend -L 450G /dev/vg_centoscy/lv_home 表示将lv_home卷的大小调整到450G,前提是vg中有足够的空间。注意,lvextend指令所指定到大小必须大于需要调整到lvm的大小
-L指令也可以用 + 来调整大小 表示当前空间需要增加到大小 比如 -L +50G 表示lv_home卷的空间调整为400G+50G
lvreduce指令跟lvextend指令完全相反,这里就不仔细说明了
[root@localhost caoyong]# lvreduce -L -10G -f /dev/vg_centoscy/lv_home WARNING: Reducing active and open logical volume to 390.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Reducing logical volume lv_home to 390.00 GiB Logical volume lv_home successfully resized
接下来创建新的lvm
lvmcreate -L 10G -n mylvm /dev/vg_centoscy
[root@localhost caoyong]# lvcreate -L 10G -n mylvm /dev/vg_centoscy Logical volume "mylvm" created在vg_centoscy卷组中创建mylvm卷,我们使用lvdisplay指令查看,mylvm卷已经创建完成,接下来要将lvm挂载到linux的 / 中
创建/mylvm 分区
[root@localhost caoyong]# mkdir /mylvm
格式化mylvm卷
[root@localhost caoyong]# mke2fs -j -t ext4 /dev/vg_centoscy/mylvm mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=2684354560 80 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 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost caoyong]# mount -t ext4 /dev/vg_centoscy/mylvm /mylvm到这里,lvm卷的分割,创建和挂载完成。
上述mylvm卷是在写博文时查看指令和运行结果所临时分割的空间,data卷是之前操作中分割给mysql作为数据储存用的空间。本人初学linux,有什么遗漏到地方希望有人指正