`

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
#

分享到:
评论

相关推荐

    详细的LVM学习笔记

    详细的LVM学习笔记,我自己一步步实现,记录下来的。

    LVM管理操作笔记

    LVM管理操作笔记 很珍贵的培训资料,内部培训防止泄露

    linux硬盘划分lvm和raid笔记

    自己写的lvm和raid笔记,总结很比较全面(个人认为)。推荐下载

    LVM(Logical volume manager)实验笔记

    LVM(Logical volume manager)实验笔记。通过该实验,更加清楚LVM逻辑卷管理的原理。

    RHEL5下LVM创建和应用

    基于RHEL5下LVM逻辑卷管理实验笔记

    lvm2py:使用ctypes的Python lvm绑定

    与可用的命令行选项相比,它的功能有一些限制。 例如,尚未在api中实现对物理卷和逻辑卷的调整大小。 尽管如此,仍计划在不久的将来做出贡献。 这是使用LVM 2.2进行测试的第一个版本,请在下面的链接中或通过电子...

    Linux 学习笔记-LVM磁盘管理

    逻辑卷管理通过将底层物理硬盘抽象封装起来,以逻辑卷的形式表现给上层系统,逻辑卷的大小可以动态调整,而且 ...  使用 LVM 的步骤:  a. 物理硬盘格式化为 PV(物理卷),底层空间被分做每个4M大小的PE。

    RHCE课程笔记

    RHCE课程-RH131Linux管理笔记七-Linux分区,格式化,SWAP,LVM,软件RAID的创建 12月27日课程 8、自动挂载和NIS服务器及客户端配置 9、软件RIDE及XEN虚拟机 RHCE课程-RH131Linux管理笔记八-安装和管理XEN虚拟机 1月...

    linux全套学习笔记_博雅运维

    linux全套学习笔记_博雅运维,适合linux初学者,包含用户管理,进程管理,分区管理,vim,磁盘阵列,LVM逻辑卷,dns,ftp,nfs,samba,dhcp,apache,mysql,php,nginx,iptables,selinux,lamp,lnmp架构,phpmyadmin,...

    project-LVM::part_alternation_mark:这是一家网上商店,主要销售服装(鞋子)。 笔记

    LVM项目| 鞋子销售网站(在线商店) 这是一个封闭的项目,由客户的订单创建。 适用德国版权法规。 什么是LVM网站? 该网站提供用于转售的服装产品(鞋)。 由于这个原因,在这个项目中, 应该创建一个醒目醒目的...

    Linux Raid 5 扩容学习笔记(精排编目)

    本人在redhat linux 5上的学习笔记,动态增加硬盘、格式化、增加新分区到LVM下的Raid分区、分区故障模拟和替换、给分区扩容等 给同样的菜鸟和有需要的朋友,如有不正确的地方请大家指点

    ASM学习笔记

    这是Oracle提供的一个卷管理器,用于替代操作系统所提供的LVM,它不仅支持单实例配置,也支持RAC这样的多实例配置。将给Oracle数据库管理员带来极大的方便,ASM可以自动管理磁盘组,并提供数据冗余和优化。特别是...

    one-janitor:您的个人 OpenNebula 和 LVM 管理员

    在不需要的 HV 上检查激活的 LVM 逻辑卷,寻找恶意 LV。 (如果你使用 clvm 它会显示误报) 检查不存在的 VM 的逻辑卷,寻找幻影 LV。用法安装节点 main.js笔记Hypervisor 列表是从 OpenNebula 自动加载的,如果...

    Linux-RHCE系列实战教程打包

    2、Linux LVM逻辑卷管理 3、Linux 软RAID创建和维护 4、Quota磁盘限额 5、RedHat 5.4 RHCE YUM学习笔记 6、RHCE-253 Apache服务常规配置 7、RHCE-253 Apache服务高级配置 8、RHCE-253 DHCP服务配置 9、RHCE-253 DNS...

    centos7 应用笔记: systemd-analyze 分析开机过程

    centos7 应用笔记: systemd-analyze 分析开机过程 centos7 是使用 systemd 管理服务的。 如果 开机很慢。可以使用 systemd-analyze 分析开机过程。 使用 systemd-analyze 分析开机过程 # 打印耗时的服务 systemd-...

    linux RHCE 实验手册

    Linux LVM逻辑卷管理.pdf 3. Linux 软RAID创建和维护.pdf 4. Quota磁盘限额.pdf 5. RedHat 5.4 RHCE YUM学习笔记.pdf 6. RHCE-253 Apache服务常规配置.pdf 7. RHCE-253 Apache服务高级配置.pdf 8. RHCE-253 ...

    notaslinux:Linux中过程的内存和注释

    笔记Linux LINUX记事本 LVM常规 快照和恢复过程 在此过程中,将快照复制到逻辑卷之一以继续更新操作系统,如果出现问题,将对其进行还原。 概述 准备创建快照 可选查看内容 逆转 编辑菜单Grub 返回盘 准备创建...

Global site tag (gtag.js) - Google Analytics