LVM介绍

LVM介绍

LVM的强大之处,比之前的传统分区方式强太多(mbr)。下面主要翻译ubuntu wiki中lvm的介绍。

What is LVM
LVM stands for Logical Volume Management. It is a system of managing logical volumes, or filesystems, that is much more advanced and flexible than the traditional method of partitioning a disk into one or more segments and formatting that partition with a filesystem.


什么是lvm?
LVM表示逻辑卷管理。它是一个管理逻辑卷或文件系统的系统,也就是说比传统的将硬盘分成一个或多个部分的并且格式化后用一种文件系统分区的方式 要更先进和灵活。


Why use LVM?
For a long time I wondered why anyone would want to use LVM when you can use gparted to resize and move partitions just fine. The answer is that lvm can do these things better, and some nifty new things that you just can't do otherwise. I will explain several tasks that lvm can do and why it does so better than other tools, then how to do them. First you should understand the basics of lvm.


为什么用lvm?
很长一段时间我都在想为什么会有人去用lvm因为你可以用gparted很好的去重新改变分区大小和移动分区。答案是lvm可以把事情完成的更好,并且有很多惊艳的的新的事情其他的方式做不到。我会解释一些任务lvm可以做到和为什么他可以比其他的工具做的更加的好,然后如何去使用它。首先你得知道lvm的基础知识。


The Basics
There are 3 concepts that LVM manages:
Volume Groups
Physical Volumes
Logical Volumes
A Volume Group is a named collection of physical and logical volumes. Typical systems only need one Volume Group to contain all of the physical and logical volumes on the system, and I like to name mine after the name of the machine. Physical Volumes correspond to disks; they are block devices that provide the space to store logical volumes. Logical volumes correspond to partitions: they hold a filesystem. Unlike partitions though, logical volumes get names rather than numbers, they can span across multiple disks, and do not have to be physically contiguous.


卷组是物理和逻辑卷的命名集合。 典型的系统只需要一个卷组来包含系统上的所有物理和逻辑卷,我喜欢在机器名称之后命名我的名字。 物理卷对应于磁盘; 它们是提供存储逻辑卷的空间的块设备。 逻辑卷对应于分区:它们保存文件系统。 与分区不同,逻辑卷获取名称而不是数字,它们可以跨越多个磁盘,并且不必在物理上是连续的。


The Specifics
One of the biggest advantages LVM has is that most operations can be done on the fly, while the system is running. Most operations that you can do with gparted require that the partitions you are trying to manipulate are not in use at the time, so you have to boot from the livecd to perform them. You also often run into the limits of the msdos partition table format with gparted, including only 4 primary partitions, and all logical partitions must be contained within one contiguous extended partition.


LVM最大的优点之一是系统运行时大多数操作都可以在运行中完成。 您可以使用gparted进行的大多数操作都要求您尝试操作的分区当时不会使用,因此您必须从livecd启动才能执行它们。 您还经常遇到具有gparted的msdos分区表格式的限制,包括只有4个主分区,并且所有逻辑分区必须包含在一个连续的扩展分区中。


Resizing Partitions
With gparted you can expand and shrink partitions, but only if they are not in use. LVM can expand a partition while it is mounted, if the filesystem used on it also supports that ( like the usual ext3/4 ). When expanding a partition, gparted can only expand it into adjacent free space, but LVM can use free space anywhere in the Volume Group, even on another disk. When using gparted, this restriction often means that you must move other partitions around to make space to expand one, which is a very time consuming process that can result in massive data loss if it fails or is interrupted ( power loss ).


使用gparted,您可以扩展和收缩分区,但只有当它们不被使用时。 LVM可以在安装时扩展分区,如果其上使用的文件系统也支持(就像通常的ext3 / 4)。 扩展分区时,gparted只能将其扩展到相邻的可用空间,但LVM可以在卷组中的任何位置使用可用空间,甚至在另一个磁盘上。 当使用gparted时,这种限制通常意味着您必须移动其他分区才能扩展空间,这是一个非常耗时的过程,如果失败或中断(掉电)可能导致大量数据丢失。


Moving Partitions
Moving partitions with gparted is usually only necessary in the first place because of the requirement that partitions be physically contiguous, so you probably won't ever need to do this with LVM. If you do, unlike gparted, LVM can move a partition while it is in use, and will not corrupt your data if it is interrupted. In the event that your system crashes or loses power during the move, you can simply restart it after rebooting and it will finish normally. When I got my SSD drive, I simply plugged it in, booted it up, and asked lvm to move my running root filesystem to the new drive in the background while I continued working. Another reason you might want to move is to replace an old disk with a new, larger one. You can migrate the system to the new disk while using it, and then remove the old one later.


通过gparted移动分区通常只是首先需要,因为要求分区在物理上是连续的,所以你可能不需要这样做与LVM。 如果这样做,与gparted不同,LVM可以在使用中移动分区,如果数据中断,则不会损坏数据。 如果您的系统在移动过程中崩溃或断电,您可以在重新启动后重新启动它,并且它将正常完成。 当我得到我的SSD驱动器,我只是插入它,启动它,并要求lvm将我的运行根文件系统移动到新的驱动器在后台,当我继续工作。 您可能想要移动的另一个原因是用新的较大的磁盘替换旧的磁盘。 您可以在使用它时将系统迁移到新磁盘,然后再删除旧磁盘。


Many Partitions
If you like to test various Linux distributions, or just different version of Ubuntu, or both, you can quickly end up with quite a few partitions. With conventional msdos partitions, this becomes problematic due to its limitations. With LVM you can create as many Logical Volumes as you wish, and it is usually quite easy since you usually have plenty of free space left. Usually people allocate the entire drive to one partition when they first install, but since extending a partition is so easy with LVM, there is no reason to do this. It is better to allocate only what you think you will need, and leave the rest of the space free for future use. If you end up running out of the initial allocation, adding more space to that volume is just one command that completes immediately while the system is running normally.


如果你喜欢测试各种Linux发行版,或者只是不同版本的Ubuntu,或者两者兼容,你可以快速地结束相当多的分区。 使用常规的msdos分区,由于其限制,这成为问题。 使用LVM,您可以根据需要创建尽可能多的逻辑卷,通常很容易,因为您通常有足够的可用空间。 通常人们在首次安装时将整个驱动器分配到一个分区,但是由于使用LVM扩展分区非常简单,所以没有理由这样做。 最好只分配你认为需要的东西,并留下剩下的空间供将来使用。 如果最终用完初始分配,则向该卷添加更多空间只是一个在系统正常运行时立即完成的命令。


Snapshots
This is something you simply can not do without LVM. It allows you to freeze an existing Logical Volume in time, at any moment, even while the system is running. You can continue to use the original volume normally, but the snapshot volume appears to be an image of the original, frozen in time at the moment you created it. You can use this to get a consistent filesystem image to back up, without shutting down the system. You can also use it to save the state of the system, so that you can later return to that state if you mess things up. You can even mount the snapshot volume and make changes to it, without affecting the original.


快照。这是你根本不能做的,没有LVM。 它允许您随时冻结现有的逻辑卷,即使在系统运行时也可以随时冻结现有的逻辑卷。 您可以继续正常使用原始卷,但快照卷似乎是原始图像,在创建时冻结在时间上。 您可以使用它来获得一致的文件系统映像进行备份,而无需关闭系统。 您也可以使用它来保存系统的状态,以便您可以稍后恢复到该状态。 您甚至可以安装快照卷并对其进行更改,而不会影响原始。

确实lvm比传统的分区方式要方便灵活快捷很多。后面有些事google翻译翻的,懒得打字,但是也基本看出lvm的强大之处了。

推荐阅读更多精彩内容

  • 难道我就没能力吗?难道我没有一点优点吗?我想我应该是有的,但是为什么找不到方法,让自己的作用放大,让我身上的...
    伊人_c275阅读 67评论 0 0
  • 今天中午我自己在会议室看了几个视频。我手机上有下载的关于健身的视频。但是我悲催的发现,自己穿了不适合运动的皮鞋。我...
    雀岛札记阅读 48评论 0 0
  • 不知什么时候开始,信息网络已经遍布家乡的各个角落,家家户户都用上了信息高速公路,人们通过网络认知事物,交流感情,快...
    千岁寒阅读 218评论 0 0
  • 01 风和,日暖。 苏柒的心情极差。这已经是她相的第三十次亲了。 苏柒看着镜子里的自己,那张脸眉目清秀,个子不高,...
    木陶眠阅读 138评论 3 6