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。 它允許您隨時凍結現有的邏輯卷,即使在系統運行時也可以隨時凍結現有的邏輯卷。 您可以繼續正常使用原始卷,但快照卷似乎是原始圖像,在創建時凍結在時間上。 您可以使用它來獲得一致的文件系統映像進行備份,而無需關閉系統。 您也可以使用它來保存系統的狀態,以便您可以稍后恢復到該狀態。 您甚至可以安裝快照卷并對其進行更改,而不會影響原始。