为什么要使用 LVM?它创造了更多的边界(更少的自由)

gue*_*tli 3 lvm

我有一个在 VM 中运行的 linux 服务器。管理程序是 VMWare。

This setup was done by a former admin:

server:~ # pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  system lvm2 a--  119,84g    0

server:~ # vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  system   1   3   0 wz--n- 119,84g    0

server:~ # lvs
  LV   VG     Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  home system -wi-ao--- 97,84g                                          
  root system -wi-ao--- 20,00g                                          
  swap system -wi-ao---  2,00g                    
Run Code Online (Sandbox Code Playgroud)

I ask myself: Why?

It is great that you can do a lot of interesting things with LVM. But why?

Why not create one blockdevice/partition/filesystem?

Swapping could get done into a file.

One partition/filesystem would give me less block devices. This means the directories in the file system have more space to grow.

If I use one block device with one filesystem it is less likely to run out of disk space.

Example: If the files of "root system" need more than 20GByte, and "home" has space left, then everything is fine.

Here is an simplified ascii art of the LVM setup:

+--------------------+
|                    |
|  Filesystem        |
|                    |
|---------------------
|                    |
|  Logical Volume    |
|                    |
|---------------------
|                    |
|  Volume Group      |
|                    |
----------------------
|                    |
|  Physical Volume   |
|                    |
|---------------------
|                    |
|  Block device      |
|                    |
+--------------------+
Run Code Online (Sandbox Code Playgroud)

Background: This is not a high available system. A reboot at night is always possible.

Joh*_*ald 7

Using LVM in general enables several features. Just a couple:

  • Extending a volume is one step and online: lvextend --resize.
  • Partitioning is not required. Without LVM, the common use case of resizing root fs requires downtime and probably editing partition tables from a second system.
  • Snapshots are always available, even without such a feature on the storage system or hypervisor.
  • Extreme use cases may require a volume backed by more one disk (LUN). Rare these days. But might as well standardize on the more flexible LVM.

(Some of the details are specific to Linux LVM, but LVM in general is implemented on many operating systems. On UNIX, AIX and HP-UX predate Linux and have similar LVMs.)


That particular allocation resembles defaults on distros like Red Hat reflecting some recommendations they have given for a long time.

To store user data separately from system data, create a dedicated partition within a volume group for the /home directory. This will enable you to upgrade or reinstall Red Hat Enterprise Linux without erasing user data files.

Paging space could be in a more convenient file, yes. I think this requires certain file systems. Directly on a block level device works regardless of file system, and it is obvious the space is not available for regular files. Further, you could move this paging space volume to fast less durable storage like a single local SSD.

Some administrators go further and isolate say /var on its own volume and /tmp on tmpfs. That way log files and such will not fill up space required for software in /usr.

就个人而言,如果没有大小要求,我会从/home较小的开始,比如 20 GB。这会在 VG 中留下 70 GB 的可用空间,以用于下一个需要的任何内容lvextend。这也是长期以来的建议。我怀疑这不是自动分区默认值,因为用户数据往往会无限增长,并且他们希望使用该空间以防容量规划不再被重新访问。

保留未分配的超额容量,仅将存储容量分配给您立即需要的那些分区。您可以随时分配可用空间,以满足出现的需求。