Mounting swap partition via systemd

playstation

New Member
Joined
Jul 10, 2022
Messages
3
Reaction score
0
Credits
36
Hi, folks!

I'm currently studying for RHCSA, and I have no prior Linux experience, and I don't use Linux on a daily basis. Anyway, I'm currently trying to mount a new swap partition in my virtual machine with CentOS Stream 9. I know how to do it via editing /etc/fstab file: first we create partition with type linux-swap, then we make swap FS, then we run swapon to mount it, and then we edit /etc/fstab file to make sure the mount is persistent and run systemctl daemon-reload command. It works in my virtual machine: I run "free -m" command before and after described procedure, and it shows the increased swap, and it stays the same after reboot.

Now I'd like to do the same via systemd. I already learned how to mount regular partitions where I can store files etc, but mounting swap partition gave me some trouble.

I unmounted previously mounted swap, commented line in /etc/fstab, and then I created a file myswap.mount in /etc/systemd/system directory. Here are the contents of this file:

[Unit] Description=swap Conflicts=umount.target Before=local-fs.target umount.target [Mount] What=UUID=b1f040f6-485f-4c8b-8419-19d83c9bdca9 Where=swap Type=swap Options=defaults [Install] WantedBy=local-fs.target

Then I run systemctl daemon-reload command, but when I run systemctl enable --now myswap.mount it gives me an error: "Where= path is not absolute". Unfortunately, I don't understand how to specify where to mount it in my systemd config file. If I remove "Where=swap", I get this error message that I see via journalctl -ex command: "mount: /myswap: operation failed: Invalid argument." So I assume the problem is in my config file. Please could you tell me where is the issue and how to fix it?

Thanks in advance!
 


Lots to learn in linux. RHCSA is highly regarded in my neck of the woods.
What makes you think a swap partition is mounted?
Why does the mount point in the /etc/fstab file show "none" for the mount point of the swap partition?
What is the difference between "mounted", "created" and "enabled"?
Why doesn't the swap partition appear in the results of the command: mount, or in the file /proc/mounts?
How does the kernel get to know about the swap partition so that it can use it?

There a few man pages on swap: mkswap, swapon, swapoff, systemd.swap.
 
Lots to learn in linux. RHCSA is highly regarded in my neck of the woods.
What makes you think a swap partition is mounted?
Why does the mount point in the /etc/fstab file show "none" for the mount point of the swap partition?
What is the difference between "mounted", "created" and "enabled"?
Why doesn't the swap partition appear in the results of the command: mount, or in the file /proc/mounts?
How does the kernel get to know about the swap partition so that it can use it?

There a few man pages on swap: mkswap, swapon, swapoff, systemd.swap.

Hi, thank you for your reply. I already figured out the issue. First of all, I named my custom unit file wrong. I should have named it like dev-sdd6.swap. Also the contents of the file should be simplier:

[Unit]
Description="Using /dev/sdc6 as an extra swap partition"

[Swap]
What=b1f040f6-485f-4c8b-8419-19d83c9bdca9
Options=defaults

It worked on my VM.
 
I know it's an offtopic but I gotta ask: why would you need the swap to be mounted? You can't write anything manually on it anyway, only the system can, so I really don't see much point in having it mounted.
 
Hey guys, sorry for late reply. I was following Sander's RHCSA course and was trying to repeat what he did and maybe do a little extra. At this moment that issue is already solved.
 

Staff online

Members online


Top