#swap
Zram is an alternative on Linux to swap partitions or swap files
For some distros this is even becoming the default. Fact is swapping to SSD drives can speed up their demise, and swapping to drives is slower than to RAM. Zram creates a compressed block device in memory and swaps to that.
So no creation of swap partitions or files, and this is probably better suited for those with 16 GB or more of RAM, although they do mention working with far smaller sizes.
The linked article is the one that really brought this to my attention, but looking deeper I realised there is more than one way of configuring this, so you may want to dig around first for more information and ensure you follow something fairly recent.
In the end, for my Manjaro setup I opted to install the zram-generator package (also look at their Github project page for info), and went with the default config file (you just need to copy it to /etc/systemd/zram-generator.conf, except for setting the host-memory-limit to none and disabling the zswap1 device creation. Well, hope that was correct, but the device is created and reporting, so I assume it is all good now.
See https://opensource.com/article/22/11/customize-zram-linux
#technology #Linux #zram #swap #opensource
#Blog, ##linux, ##opensource, ##swap, ##technology, ##zram
âto swap, or not to swap, that is the questionâ: definately swap Shakespeare
âto encrypt, or not to encryptâ (if it contains valuable data, encrypt)
âto lvm, or not to lvmâ (wellâŚ.)
because: one fine day, the user decides to open 1000x programs + serveral vms at the same time, why not right?
the system runs out of RAM AND SWAP space (it almost freezes, to death).
but behold!
instead of simply pulling the plug.
the admin decides to wait and work on device B, while device A is struggling to keep alive.
after aprox 15min⌠the kvm vm crashes (probably because it used the most RAM) while the other programs survive.
For some reason, the otherwise excellent Debian installer, per default decides to reserve only 1GByte of SWAP on an 1000GB SSD.
In past times, the rule of thumb was âat least half of RAM sizeâ, would even go as far and say: make swap = RAM size, why not? SSD space and NVMe space are getting cheaper and faster, nothing worse then running out of RAM & SWAP space (system enters undefined behavior, not only GNU Linux, OSX too)
letâs change that to something like 30GB of swap.
per default the user (probably) has chosen to use lvm2 (logical volume management) + luks2 encryption.
gparted is a pretty nice gui based program, that can do resize of ext4 partitions nicely, but it canât help with logical volume management.
<span style="color: #ff0000;"># HAVE A FULL BACKUP OF THE HARDDISK IN QUESTION!</span>
# <a href="https://dwaves.de/2021/04/11/ideallinux2021-updated-optimized-bootale-gnu-debian-10-9-64bit-non-free-based-usb-stick-the-live-system-that-keeps-changes-stored/">boot dwaves' live usb stick, or another live system</a>
# (it is Debian 10 based)
# IdealLinux stick, already has those requirements installed
<span style="color: #00ffff;">su - root
apt update
apt install lvm2 cryptsetup</span>
# first thing: find the partition in question
<span style="color: #00ffff;">lsblk -fs</span>
# might help too
<span style="color: #00ffff;">alias harddisks='lsblk -o '\''NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID'\'''</span>
# run the alias
<span style="color: #00ffff;">harddisks</span>
# look at the disk sizes...
# which one is (probably) the partition in question?
# found it? good, let's continue...
# decrypt the partition
<span style="color: #00ffff;">cryptsetup open /dev/sda5 encrypted</span>
*** enter decryption password ***
# make all volume groups active
<span style="color: #00ffff;">vgchange -ay</span>
2 logical volume(s) in volume group "IdealLinux2021-vg" now active
2 logical volume(s) in volume group "toplap-vg" now active <- that's the one
<span style="color: #00ffff;">vgdisplay</span>; # list all volume groups
--- Volume group ---
VG Name toplap-vg <-
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <931.02 GiB
PE Size 4.00 MiB
Total PE 238340
Alloc PE / Size 238340 / <931.02 GiB
Free PE / Size 0 / 0
<span style="color: #00ffff;">lvdisplay</span>; # list all logical volumes
--- Logical volume ---
LV Path /dev/toplap-vg/root <- the one to shrink down to 900GB
LV Name root
VG Name toplap-vg
LV Write Access read/write
LV Creation host, time toplap, 2022-05-17 03:48:56 -0400
LV Status available
# open 0
LV Size 930.06 GiB
Current LE 238096
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:3
--- Logical volume ---
LV Path /dev/toplap-vg/swap_1 <- the swap that is too small, will increase to 30GB
LV Name swap_1
VG Name toplap-vg
LV Write Access read/write
LV Creation host, time toplap, 2022-05-17 03:48:56 -0400
LV Status available
# open 0
LV Size 976.00 MiB
Current LE 244
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:4
# run a pre-resize filesystem check
<span style="color: #00ffff;">fsck -y -v -f /dev/toplap-vg/root</span>
# resize the root filesystem from 930GB to 900GB
<span style="color: #00ffff;">resize2fs /dev/toplap-vg/root 900G</span>
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/toplap-vg/root to 235929600 (4k) blocks.
The filesystem on /dev/toplap-vg/root is now 235929600 (4k) blocks long.
<span style="color: #00ffff;">lvreduce -L 900G /dev/toplap-vg/root</span>
WARNING: Reducing active logical volume to 900.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce toplap-vg/root? [y/n]: <span style="color: #00ffff;">y</span>
Size of logical volume toplap-vg/root changed from 930.06 GiB (238096 extents) to 900.00 GiB (230400 extents).
Logical volume toplap-vg/root successfully resized.
# post-resize filesystem check
<span style="color: #00ffff;">fsck -y -v -f /dev/toplap-vg/root</span>
<span style="color: #00ffff;">
lvextend -l +100%FREE /dev/toplap-vg/swap_1</span>
Size of logical volume toplap-vg/swap_1 changed from 976.00 MiB (244 extents) to <31.02 GiB (7940 extents).
Logical volume toplap-vg/swap_1 successfully resized.
<span style="color: #00ffff;">mkswap /dev/toplap-vg/swap_1</span>
mkswap: /dev/toplap-vg/swap_1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 31 GiB (33302769664 bytes)
<span style="color: #00ffff;">sync; sync; sync;</span>
# reboot system
<span style="color: #00ffff;">shutdown -r now</span>;
it worked?
possibly related Links:
also checkout:
cudos:
https://www.casesup.com/category/knowledgebase/howtos/how-to-shrink-an-lvm-volume-safely-on-linux
#linux #gnu #gnulinux #opensource #administration #sysops #gnu-linux #debian #storage #ram #swap
Originally posted at: https://dwaves.de/2022/05/19/gnu-linux-debian-how-to-shrink-resize-lvm2-luks-encrypted-root-partition-how-to-enlarge-swap-space/
GNU Linux (Debian) - how to resize lvm2 luks encrypted root partition - how to enlarge SWAP space
âto swap, or not to swap, that is the questionâ: definately swap Shakespeare
âto encrypt, or not to encryptâ (if it contains valuable data, encrypt)
âto lvm, or not to lvmâ (wellâŚ.)
because: one fine day, the user decides to open 1000x programs + serveral vms at the same time, why not right?
the system runs out of RAM AND SWAP space (it almost freezes, to death).
but behold!
instead of simply pulling the plug.
the admin decides to wait and work on device B, while device A is struggling to keep alive.
after aprox 15min⌠the kvm vm crashes (probably because it used the most RAM) while the other programs survive.
For some reason, the otherwise excellent Debian installer, per default decides to reserve only 1GByte of SWAP on an 1000GB SSD.
In past times, the rule of thumb was âat least half of RAM sizeâ, would even go as far and say: make swap = RAM size, why not? SSD space and NVMe space are getting cheaper and faster, nothing worse then running out of RAM & SWAP space (system enters undefined behavior, not only GNU Linux, OSX too)
letâs change that to something like 30GB of swap.
per default the user (probably) has chosen to use lvm2 (logical volume management) + luks2 encryption.
gparted is a pretty nice gui based program, that can do resize of ext4 partitions nicely, but it canât help with logical volume management.
<span style="color: #ff0000;"># HAVE A FULL BACKUP OF THE HARDDISK IN QUESTION!</span>
# <a href="https://dwaves.de/2021/04/11/ideallinux2021-updated-optimized-bootale-gnu-debian-10-9-64bit-non-free-based-usb-stick-the-live-system-that-keeps-changes-stored/">boot dwaves' live usb stick, or another live system</a>
# (it is Debian 10 based)
# IdealLinux stick, already has those requirements installed
<span style="color: #00ffff;">su - root
apt update
apt install lvm2 cryptsetup</span>
# first thing: find the partition in question
<span style="color: #00ffff;">lsblk -fs</span>
# might help too
<span style="color: #00ffff;">alias harddisks='lsblk -o '\''NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID'\'''</span>
# run the alias
<span style="color: #00ffff;">harddisks</span>
# look at the disk sizes...
# which one is (probably) the partition in question?
# found it? good, let's continue...
# decrypt the partition
<span style="color: #00ffff;">cryptsetup open /dev/sda5 encrypted</span>
*** enter decryption password ***
# make all volume groups active
<span style="color: #00ffff;">vgchange -ay</span>
2 logical volume(s) in volume group "IdealLinux2021-vg" now active
2 logical volume(s) in volume group "toplap-vg" now active <- that's the one
<span style="color: #00ffff;">vgdisplay</span>; # list all volume groups
--- Volume group ---
VG Name toplap-vg <-
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <931.02 GiB
PE Size 4.00 MiB
Total PE 238340
Alloc PE / Size 238340 / <931.02 GiB
Free PE / Size 0 / 0
<span style="color: #00ffff;">lvdisplay</span>; # list all logical volumes
--- Logical volume ---
LV Path /dev/toplap-vg/root <- the one to shrink down to 900GB
LV Name root
VG Name toplap-vg
LV Write Access read/write
LV Creation host, time toplap, 2022-05-17 03:48:56 -0400
LV Status available
# open 0
LV Size 930.06 GiB
Current LE 238096
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:3
--- Logical volume ---
LV Path /dev/toplap-vg/swap_1 <- the swap that is too small, will increase to 30GB
LV Name swap_1
VG Name toplap-vg
LV Write Access read/write
LV Creation host, time toplap, 2022-05-17 03:48:56 -0400
LV Status available
# open 0
LV Size 976.00 MiB
Current LE 244
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:4
# run a pre-resize filesystem check
<span style="color: #00ffff;">fsck -y -v -f /dev/toplap-vg/root</span>
# resize the root filesystem from 930GB to 900GB
<span style="color: #00ffff;">resize2fs /dev/toplap-vg/root 900G</span>
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/toplap-vg/root to 235929600 (4k) blocks.
The filesystem on /dev/toplap-vg/root is now 235929600 (4k) blocks long.
<span style="color: #00ffff;">lvreduce -L 900G /dev/toplap-vg/root</span>
WARNING: Reducing active logical volume to 900.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce toplap-vg/root? [y/n]: <span style="color: #00ffff;">y</span>
Size of logical volume toplap-vg/root changed from 930.06 GiB (238096 extents) to 900.00 GiB (230400 extents).
Logical volume toplap-vg/root successfully resized.
# post-resize filesystem check
<span style="color: #00ffff;">fsck -y -v -f /dev/toplap-vg/root</span>
<span style="color: #00ffff;">
lvextend -l +100%FREE /dev/toplap-vg/swap_1</span>
Size of logical volume toplap-vg/swap_1 changed from 976.00 MiB (244 extents) to <31.02 GiB (7940 extents).
Logical volume toplap-vg/swap_1 successfully resized.
<span style="color: #00ffff;">mkswap /dev/toplap-vg/swap_1</span>
mkswap: /dev/toplap-vg/swap_1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 31 GiB (33302769664 bytes)
<span style="color: #00ffff;">sync; sync; sync;</span>
# reboot system
<span style="color: #00ffff;">shutdown -r now</span>;
it worked?
possibly related Links:
also checkout:
cudos:
https://www.casesup.com/category/knowledgebase/howtos/how-to-shrink-an-lvm-volume-safely-on-linux
#linux #gnu #gnulinux #opensource #administration #sysops #gnu-linux #debian #storage #ram #swap
Originally posted at: https://dwaves.de/2022/05/19/gnu-linux-debian-how-to-resize-lvm2-luks-encrypted-root-partition-how-to-enlarge-swap-space/
to swap or not to swap? That is the question. why would one disable the swap partition? it has no dissadvantages keeping it (except the loss of a bit of harddisk space) systems do not become "faster" by disabling the swap partition,[...]
#linux #gnu #gnulinux #opensource #administration #sysops #gnu-linux #debian #swap #ram
Originally posted at: https://dwaves.de/2022/01/26/gnu-linux-debian-to-swap-or-not-to-swap-that-is-the-question-how-to-fix-annoying-startup-boot-dealying-boot-message-begin-running-scripts-local-block-mdadm-no-arrays-found-in-config-file-or-au/
I still don't get why #Debian #Linux does not do a proper full disk #encryption with /boot and /swap encrypted and #grub with the encryption setup while having #swap so big that it is sufficient for hibernation to disk. Why?