Score:2

Extend or create new swap file

pe flag

I have a kubuntu installation (Kubuntu 21.04), which during install created a swap file of 1Gb. Tryed to create a swap file of 4GB, using the following commands:

$ sudo -s
# dd if=/dev/zero of=/swapfile bs=1G count=4
# chown root:root /swapfile
# chmod 600 /swapfile
# ls -lh /swapfile
# mkswap /swapfile
# swapon /swapfile
# echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

And after it was like there was no swap, and my system had to be repaired (used a repair disk). Kubuntu is installed in an encrypted lvm2pv partition,(/dev/kubuntu-vg). Inside it there are /dev/kubuntu-vg/root mounted at / and /dev/kubuntu-vg/swap_1 ).

Should I try again and how to proceed? Thanks in advance.

waltinator avatar
it flag
swap files have to be contiguous, else the swapper gets confused.
heynnema avatar
ru flag
I'm not 1000% sure that you can use a /swapfile on an encrypted lvm. You may have to create a small swap partition on disk and then edit your /etc/fstab, or enlarge your /dev/kubuntu-vg/swap_1 and re-edit your /etc/fstab.
G Ugauga avatar
pe flag
@heynnema I can see with KDE partitionmanager, that swap file is inside encrypted volume. That means it is created , used encrypted and deleted after poweroff (??). I thought of creating a swap partition instead, but I am afraid of resizing an encrypted partition with all my data inside.
heynnema avatar
ru flag
The swap_1 partition (which is different than the /swapfile that you created) has no real data in it, and can be resized/extended using lvm commands. You should back out your /swapfile and the mods to /etc/fstab and work on extending swap_1 if you can. Show me `swapon -s` and `free -h`.
G Ugauga avatar
pe flag
@heynnema thanks for your support. $ swapon -s Filename Type Size Used Priority /dev/dm-2 partition 999420 9508 -2
heynnema avatar
ru flag
Yes. Back out your /swapfile and /etc/fstab changes. In terminal do "apropos lvm" and you'll see a resize command there, then do "man resize_command_name" for instructions. Report back later.
G Ugauga avatar
pe flag
@heynema I did as you proposed. I extended swap_1 partition and it was Ok. It helped me because initially thought it was a swap file. I will try later creating a swap file on my older laptop.
Score:2
cn flag

I'm scared of dd, I use fallocate

  • Create the swap file:

    sudo fallocate -l XG /swapfile

    Where X is the swapfile size in GB

    sudo mkswap /swapfile
    sudo chmod 0600 /swapfile
    sudo swapon /swapfile
    
  • Reboot:

    sudo reboot
    
  • There is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.