5

What are the benefits of putting swap into a logical volume over using direct disk access?

For example, with a fresh, default install of RHEL5 or 6, a volume group is created on the default disk along with one other small non-logical partition (for /boot). Inside the volume group, a swap space is created along with the mount point for /.

What are the benefits (if any) to having swap be inside a logical group instead of directly on the disk?

2 Answers 2

6

The benefits are:

  • more flexibilty if you want to change the size of swap
  • you don`t need a partition for swap

AFAIK this - once existing drawback does NOT exist any more:

  • not possible to resume from swap
5
  • 1
    how is it not flexible to change the size of swap by going direct to disk instead of a logical volume? I can add/delete/resize at will (and if I resize smaller (for whatever reason), I can always take that space and add it to my VG as an extension)
    – warren
    Nov 10, 2011 at 23:12
  • @warren, you change change the LVM volumes while the system is live. If you didn't leave free space, on your physical devices, then you will probably need to repartition the system offline, when not using LVM.
    – Zoredache
    Nov 11, 2011 at 1:16
  • @Zoredache (sorry for necro however) incorrect. There is no way to online resize swap, you can however add new swap on a different device and toggle it on or off as you desire (the kernel will automatically move swap content between swaps). Therefore it is better not to use LVM for swap.
    – DustWolf
    Jul 11, 2022 at 9:38
  • @DustWolf I didn't mention swap in my comment. and I did mention 'volumes', so I am almost certain the point I was trying to make that you could change other volumes and not just the swap. Having everything under LVM gives you more flexibility. Still, I think it would depend on what you mean online. I believe you could grow the size of the LV that contains swap without having to go offline, or unmounting anything, The new space, just wouldn't actually be usable yet. After growing the LV you could unmount, mkswap, and remount without rebooting..
    – Zoredache
    Jul 11, 2022 at 19:06
  • @DustWolf Also, I am not sure why you think it is better to not use LVM for swap. I don't think the ability to add other swaps as needed automatically translates into meaning swap is better outside LVM. Also, I will point out that most Linux installers will put swap on LVM when you are installing with CryptSetup+LUKS, since it is easier to just encrypt the single LVM device instead of lots of smaller partitions, and encrypting your swap is pretty important if you doing full disk encryption.
    – Zoredache
    Jul 11, 2022 at 19:14
3

There is very few benefits to doing this as far as I can tell. You can create more swap on demand and add it to total swap, along with setting up policies for which swap space to use when.

Many of the typical benefits of volume management do not really apply when the data you are keeping goes stale on a restart of a service or a reboot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .