Skip to content

Instantly share code, notes, and snippets.

@3DRaven
Created June 24, 2025 15:38
Show Gist options
  • Select an option

  • Save 3DRaven/e434c7199b3715d9641c686b3628e035 to your computer and use it in GitHub Desktop.

Select an option

Save 3DRaven/e434c7199b3715d9641c686b3628e035 to your computer and use it in GitHub Desktop.
Compressed Swap file on ubuntu 25.04
  1. Ubuntu 25.04 because LVM VDO (compression) not supported on early versions (I tried 24.04)
  2. Installed kernel 6.14
  3. apt install lvm2
  4. create partition ${your partition number} for swap
  5. sudo pvcreate /dev/nvme0n1${your partition}
  6. sudo vgcreate vg /dev/nvme0n1${your partition}
  7. sudo lvcreate --type vdo -L ${your size}G -V ${your size}G --compression y --deduplication n vg/lv_swap
  8. sudo vgchange -ay # activation all created VDO for tests before reboot
  9. sudo blkid /dev/vg/lvol0 # remember UUID ${your uuid}
  10. sudo nano /etc/fstab # append UUID=${your uuid} none swap sw 0 0 to it
  11. sudo systemctl edit --force --full dev-vg-lvol0-swap.service # unit for activation VDO before fstab mounting with content:
### /etc/systemd/system/dev-vg-lvol0-swap.service
[Unit]
Description=Activate LVM volumes before mounting filesystems
DefaultDependencies=no
Before=local-fs-pre.target
After=systemd-udev-settle.service
 
[Service]
Type=oneshot
ExecStart=/usr/sbin/vgchange -ay
 
[Install]
WantedBy=local-fs-pre.target
  1. sudo systemctl enable dev-vg-lvol0-swap.service
  2. sudo reboot, if you have some problems, just wait timout, it will boot again :)
  3. swapon --show # used swaps
  4. sudo vdostats --human-readable # compression statistics

Pros: speed up access to data in swap (less data must be loaded from disk) Cons: memory to work VDO and CPU for compression

You can try to use deduplication too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment