lvm 的一些笔记

今天,不得不面对lvm了,毕竞是公司用的.

 

 

=================================================================

创建LVM

1、首先,我们要先创建新磁盘分区 #fdisk /dev/hda

创建2个500MB分区(hda10,hda11),然后在fdisk命令下输入t,选择刚创建好的分区,输入8e,将刚创建好的2个分区转换为8e格式。输入w保存退出

2、激活刚创建好的分区 #partprobe

3、创建成pv格式 #pvcreate /dev/had{10,11}
#pvdisplay  查看pv

4、将分区加载到vg卷组,vg0是卷组名称,vg0卷组总空间是1000MB #vgcreate vg0 /dev/had{10,11}
#vgdisplay  查看vg卷组


5、创建lv分区800M是分区大小,lv0是lv分区名称,vg0是加载到卷组名称,此时创建了一个800MB的lvm分区,vg0卷组还剩余200MB的空间 #lvcreate –L 800M –nlv0 vg0
#lvdisplay  查看lv分区

6、将lv分区格式化成ext3格式 #mkfs.ext3 /dev/vg0/lv0

7、将LVM分区mount到目录上,并修改fstab表 #mount /dev/vg0/lv0 /lvm
#vi /etc/fstab

8、扩展(lv)刚才我们创建了800mb的lvm分区,当要对分区进行扩展应如下操作: #lvextend –L+100M /dev/vg0/lv0
#ext2online /dev/vg0/lv0动态扩展

此时,我们已经向lv0分区增加了100MB空间,vg0卷组还剩余100MB空间,如果当我们认为空间还是不足,需要扩充,而vg0卷组的空间也不足时,我们就需要对vg0卷组进行扩展,然后再对lv分区进行扩展

1、创建1个500MB分区(hda12),然后在fdisk命令下输入t,选择刚创建好的分区,输入8e,将刚创建好的分区转换为8e格式。输入w保存退出 #fdisk /dev/had

2、激活刚创建好的分区 #partprobe

3、创建成pv格式 #pvcreate /dev/had12

4、将hda12添加到vg0卷组,此时vg0卷组的总空间大小为1500MB #vgextend vg0 /dev/hda12

5、对lv0分区进行动态扩展,增加500M空间 #lvextend –L+500M /dev/vg0/lv0
#ext2online /dev/vg0/lv0

此时我们创建 LVM分区大小总空间应为800M+100M+500M=1400M

总结LVM几个高级命令:lvchange、vgexport/vgimport、vgcfgbackup/vgcfgrestore
nge
vgexport/vgimport

首先在源主机上将文件系统umount:
umount /u05
再将LV和VG inactive:
lvchange -an /dev/vg_u05/lv_u05
vgchange -an vg_u05
最后导出VG:
vgexport vg_u05

目标主机上操作:

导入VG:
vgimport vg_u05
激活VG,MOUNT 文件系统:
vgchange -ay VG10
mkdir /u05
mount /dev/VG10/lv_vol01 /ccstg

backup/vgcfgrestore
1当你要备份你的卷组信息是,你就需要为卷组作备份,使用vgcfgbackup来备份
#vgcfgbackup vg0 -f <path>
备份的信息就是我们前面提到的VGDA备份到/etc/lwmconf/

2当你的卷组信息意外丢失时,你可以使用这个文件来恢复你的卷组信息,前提是你要备份了的
#vgcfgrestor -n vg0 /dev/hda8
或者
#vgcfgrestor -f /etc/lvmconf/
重卷组vg0中恢复物理卷的VGDA信息 -n参数指定卷组的名程 -f 制定备份文件路径

3 恢复了物理卷及卷组的信息后我们还要恢复原来的建立的卷组和逻辑卷的设备文件
#vgmknods

===============================================================

----

 

So you have an LVM based file system that needs extended? Now a days this can be done pretty quickly with a few commands. The following will walk you through a basic online resize of an ext3 and reiserfs based filesystem. Keep in mind, if you’re dealing with critical production data of any type, you probably should resize those offline, and during a scheduled maintenance window as a safety measure.

#df -k /mnt/test
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/testvg-test
2097084 1760768 336316 84% /mnt/test

When resizing volumes, you have to keep in mind that the file system also has to be made aware of the new volume size. A common misconception is that you can resize the LVM device and the file system will automatically grow with it, not the case in ext3 and reiserfs that I’m aware of.

The test volume we’re messing with is nearly full, so we will add another 1GB to this. We’ll start off first by extending the logical volume using the ‘lvextend’ command.

#lvextend
Please specify either size or extents (not both)
lvextend: Add space to a logical volume

lvextend
[-A|--autobackup y|n]
[--alloc AllocationPolicy]
[-d|--debug]
[-h|--help]
[-i|--stripes Stripes [-I|--stripesize StripeSize]]
{-l|–extents [+]LogicalExtentsNumber[%{VG|FREE}] |
-L|–size [+]LogicalVolumeSize[kKmMgGtTpPeE]}
[-m|--mirrors Mirrors]
[-n|--nofsck]
[-r|--resizefs]
[-t|--test]
[--type VolumeType]
[-v|--verbose]
[--version]
LogicalVolume[Path] [ PhysicalVolumePath... ]

#lvextend -L+1G /dev/testvg/test
Extending logical volume test to 3.00 GB
Logical volume test successfully resized
#lvs /dev/testvg/test
LV VG Attr LSize Origin Snap% Move Log Copy%
test testvg -wi-ao 3.00G
#
#df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 1.7G 329M 84% /mnt/test
#

Note the file system size remains at 2GB. Once the logical volume is extended, we will have to figure out what type of file system this is. You can run the following to determine this:

#mount | grep /mnt/test
/dev/mapper/testvg-test on /mnt/test type reiserfs (rw)

So we’re dealing with reiserfs.

It may also be smart to run an fsck at this point, depending on whether or not you can take the volume offline. Since this is test data, I’ll ignore the fsck and go ahead and resize the file system while it’s online. For reiserfs, this is done using the ‘resize_reiserfs’ command. You can either specify the size of let the command figure it out, and grow to the full extent of the volume. I’ll let it figure it out.

#resize_reiserfs /dev/testvg/test
resize_reiserfs 3.6.19 (2003 www.namesys.com)

resize_reiserfs: On-line resizing finished successfully.

#df -h /mnt/test/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
3.0G 1.7G 1.4G 56% /mnt/test
#

That’s it… Pretty tough huh?

Now for ext3, we’ll use the same volume.

#df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 68M 1.9G 4% /mnt/test
#mount | grep /mnt/test
/dev/mapper/testvg-test on /mnt/test type ext3 (rw)
#

#lvextend -L+1G /dev/testvg/test
Extending logical volume test to 3.00 GB
Logical volume test successfully resized
#!df
df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 68M 1.9G 4% /mnt/test
#

You’ll resize ext3 using the ‘resize2fs’ command as shown. Pretty similar to reiserfs.

#resize2fs
resize2fs 1.40.2 (12-Jul-2007)
Usage: resize2fs [-d debug_flags] [-f] [-F] [-p] device [new_size]

#resize2fs /dev/testvg/test
resize2fs 1.40.2 (12-Jul-2007)
Filesystem at /dev/testvg/test is mounted on /mnt/test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/testvg/test to 786432 (4k) blocks.
The filesystem on /dev/testvg/test is now 786432 blocks long.

#!df
df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
3.0G 68M 2.8G 3% /mnt/test
#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值