Issue to disable swap partition

Hi,
RE: https://wiki.manjaro.org/index.php?title=Swap

Having only 4Gb of RAM, I created a swap partition as:
sudo swapon --show
sudo mkswap /dev/sdc2
sudo swapon /dev/sdc2
sudo bash -c "echo UUID=$(lsblk -no UUID /dev/sdc2) none swap defaults 0 0 >> /etc/fstab"

Works perfect, but now I add some more RAM and do not need swap partition anymore.
So, I
sudo swapoff /dev/sdc2
sudo mousepad to edit
/etc/fstab
and commented:

Blockquote
UUID=f5733821-ffd2-4f14-8ffd-03bf6b0adea8 / ext4 defaults,noatime 0 1
UUID=303a8e7e-8c4e-4142-b5ff-ae7aea35f0d8 none swap defaults 0 0

Then, Gparted to delete the swap partition and rebooted.
Reboot was ok, but couldn't access anymore harddrive
so I recreated the swap partition and uncommented /etc/fstab

What did I do wrong?

Thanks

You had obviously also commented out the root filesystem ─ the first of those two entries in /etc/fstab that you're showing in the quotes here-above. :wink:

1 Like

:question:

:thinking:

1 Like

OP probably means that the hardware rebooted, but after that, there would have been just a GRUB prompt, with or without an error message. :thinking:

:man_shrugging:

1 Like

Don't know if it matters much but you should also remove resume from /etc/mkinitcpio.conf HOOKS, if it's still there. Without swap it's pointless.

Btw why do you bother removing swap ?
Hiberbate is a good feature to have imo.
Why don't you just set swappiness to 0?

1 Like

That doesn't disable swap. It only minimizes the tendency to swap.

When I still had 8 GiB of RAM in my machine, it was still swapping ─ and erratically too ─ with vm.swappiness set to 0, and even now that I've got 16 GiB of RAM, creating a backup with timeshift also caused the kernel to start swapping.

So I've disabled swap on my system, although I still have both of my swap partitions, just in case I ever need to reactivate them. :wink:

Correct, and then the OP should also rebuild the initramfs so as to remove it there too, as well as that the resume=<UUID_here> should also be removed from /etc/default/grub.

So these are the necessary steps... :arrow_down:

  1. Comment out the swap partition in /etc/fstab.

  2. Remove resume=UUID=303a8e7e-8c4e-4142-b5ff-ae7aea35f0d8 from /etc/default/grub and run... :arrow_down:

sudo update-grub
  1. Remove the resume hook from /etc/mkinitcpio.conf and run...
sudo mkinitcpio -G

:slight_smile:

1 Like

@ [Aragorn]I'll try, but then
https://wiki.manjaro.org/index.php?title=Swap#Remove_Other_Swap
needs to be updated.

So I've disabled swap on my system, although I still have both of my swap partitions, just in case I ever need to reactivate them. :wink:

Precisely.

[quote="belive, post:1, topic:156836"]
Reboot was ok
[/quote]
:question:

Well, I could logging but at boot it takes 1min30 additional to search and solve issues.

Please post the output of the following commands:

  • cat /etc/fstab

  • sudo blkid

  • sudo parted -l

  • cat /etc/default/grub

  • cat /etc/mkinitcpio.conf | grep HOOKS

1 Like

You've got a point, but at the same time, one could argue that the removal of the swap partition and swap file as described in that section of the wiki is not intended as a literal guide for removing swap, but rather as an example of what you need to do if you want to make use of systemd-swap.

That all said, I'm not sure who's responsible for maintaining the Manjaro wiki. That would probably be one of the Manjaro team members ─ pinging @Moderator-Team, because they will know.

I thought swapoff already removes it from fstab and grub. I'm not sure though, i'll try when i get the chance.

No, the swapoff command simply disables swap in the current session, but it does not persist across reboots. :wink:

1 Like

Thanks for info.
So you're saying there is no way to limit swap use to only hibernate? That sucks.

1 Like

Well, if there is a way, then I'm not aware of it. :thinking: :man_shrugging:

1 Like

sudo mousepad /etc/fstab
and commented last line, namely

UUID=303a8e7e-8c4e-4142-b5ff-ae7aea35f0d8 none swap defaults 0 0

Gparted, and deleted swap partition.
Rebooted and everything fine.

@Aragorn
Wiki is then correct, no need of "sudo update-grub" and so forth.

Questions:
my understanding is that a swap partition has the advantage over a swap file, that
1/ it (can?) take all the partition, no dynamic shrink or grow as with a swap file or does it create a swap file into the swap partition?

2/ several OS can use the same swap partition (for instance, you installed N Linux and boot in one of the N OS )?
while if you don't have a swap partition every OS might need its very own swap file.

3/ hybernate takes place in swap partition or swap file or it's completely independant?

4/ eventhough there is no swap partition, systemd can enforce a swap file on the sys partition?

5/ If there is a swap partition, can systemd still enforce a swap file on the sys partition in case it would consider too small?? For instance, your fooling by creating a swap partition of 10Mb

To be more pratical, imagine you have:
Physically:

  • 8Gb RAM
  • 10Gb swap partition

At the moment you want to hibernate,
say the system as eaten up 7.5Gb of RAM and 1.5Gb of swap, aka all together 9Gb.
Will it store 7.5Gb as already 1.5Gb is on disk, or does it needs 9Gb??
Where will the system physically store the hibernation?

No, a swap partition is unformatted ─ there is no filesystem on that partition, and thus there aren't any files on it either. The kernel accesses the raw blocks directly. But the downside ─ at least, some people feel that it's a negative ─ is that the partition takes up a static amount of space on the drive.

With a swap file, the file itself must be set up with special attributes to allow the kernel to access the raw blocks, especially with an advanced filesystems like btrfs, which employs copy-on-write and inline compression. Those techniques may not be used on a swap file.

In addition to that, a swap file resides on a filesystem, which means that the kernel must pass through the filesystem layer in order to access the raw blocks the file is comprised of. Nowadays the performance impact of this is minimal and barely noticeable, if at all. But it's still not the natural way for the kernel to access swap, even though the advantage is that a swap file can more easily be resized if need be than a swap partition, and this is why many have begun using a swap file instead of a swap partition.

In essence, it's a hack for emergency situations ─ where you are suddenly in need of more swapping capacity than you had accounted for when you created the swap partition(s) ─ that is becoming the mainstream usage pattern, mostly because today's newbies come from an operating system that has always used swap files instead of a swap partition.

That is correct, albeit that I have to add the following... If you are dual-booting between GNU/Linux distributions with a single common swap partition, then you may of course not hibernate one system and boot into the other, because the hibernation process uses the swap partition to store the contents of the RAM before the hardware is powered down.

No, it indeed uses the swap space ─ file or partition ─ that the system has at its discretion.

Yes.

I'm afraid I can't answer that because I don't use systemd-swap. I have static swap partitions ─ one on the SSD containing my system and one on a HDD that contains my backups ─ and I prefer to decide for myself whether I'll enable swap or not. I also don't hibernate my system.

2 Likes

@Aragorn: Thanks very interesting answers.

2/ with a single common swap partition, then you may of course not hibernate one system and boot into the other

Good point.

Any idea, with "my example", I start to wonder in this example if a swap partition of 10Gb is sufficient, or must to be greater than 1.5Gb + 9Gb or I do miss a point with the answer to 3/ & 4/
I can image, the system copying the RAM swap into the filesystem to release space in the swap partition and then dump the hybernation onto the swap partition, but it's my imagination.

Forum kindly sponsored by