PDA

View Full Version : 18.04 and Swap Partition



kazakore
May 2nd, 2018, 02:48 PM
Does 18.04 still use a Swap Partition? I specified one on installed (16GB, same as my RAM) and it shows as being there in gparted. However if I run htop I can see there is only 2GB of Swap and the output of this:


~$ cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 2097148 0 -2

indicating a swap file, rather than partition, and definitely not what I configured for it!

What has gone wrong here and how can I fix it? I assume I can add the swap partition to fstab like with normal partitions or is it treated differently?


For completeness my fstab as it is at the moment (not added anything I want mounted at boot as yet.)

~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=4a2abba6-0813-4420-8f4d-6a0434a7976f / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=A27D-524E /boot/efi vfat utf8,umask=007,gid=46 0 1
/swapfile none swap sw 0 0

VMC
May 2nd, 2018, 03:13 PM
Your fstab shows a swapfile, not a swap partition. From terminal, what does 'sudo blkid' show.

oldfred
May 2nd, 2018, 03:26 PM
With 18.04 a swapfile is the default.
It should use a swap partition if it finds one during install. It found both of mine & I only want one per install.
And unless hibernating (Which is not recommended) you do not need a large swap.

kazakore
May 2nd, 2018, 04:03 PM
Your fstab shows a swapfile, not a swap partition. From terminal, what does 'sudo blkid' show.

That's what I said!


/dev/sda1: UUID="A27D-524E" TYPE="vfat" PARTUUID="f752042e-1098-4ea4-b9fe-d2813a683599"
/dev/sda2: UUID="4a2abba6-0813-4420-8f4d-6a0434a7976f" TYPE="ext4" PARTUUID="627744ce-4d22-4dfe-824a-98b00bb02c8c"
/dev/sda5: UUID="4d281b03-f778-45f7-8783-a7bfdd328146" TYPE="swap" PARTUUID="96d038af-3980-40d6-b536-3f5e1ea12c0f"
/dev/sda6: UUID="A216-2A48" TYPE="vfat" PARTLABEL="DATA" PARTUUID="7ef27ac0-30b3-412d-8b17-006154dfb12c"
/dev/sda3: PARTUUID="9e773f2c-bd83-44d0-80b3-11f0db626353"
/dev/sda4: PARTUUID="ae601d44-3ef6-47c9-945b-ba9d12426e46"



The post below yours seems to indicate that the default install has gone from a partition to a file though. Maybe it broke when I did a fix-install as it seems I initially managed to enter the password twice different to how I thought and at the time that seemed the quickest way to give it a new one (I know there is a better way to change any user password but reinstall seemed easier at the time as it needed no research.)

VMC
May 2nd, 2018, 04:36 PM
If you know how you can edit fstab and add the swap partition UUID:

replace:


/swapfile none swap sw 0 0

with


UUID=4d281b03-f778-45f7-8783-a7bfdd328146 swap swap defaults, noatime 0 2

oldfred
May 2nd, 2018, 05:02 PM
@ VMC
I do not think swap uses the defaults or other settings to mount. And space between defaults & noatime is an issue for a normal mount.

My swap (commented out with#) with 16.04 and I just looked at 18.04's swap and it is identical:
# swap was on /dev/sda4 during installation
#UUID=7f429d54-b2e9-417a-ab13-b93af50f5159 none swap sw 0 0

kazakore
May 2nd, 2018, 06:13 PM
If you know how you can edit fstab and add the swap partition UUID:

replace:


/swapfile none swap sw 0 0

with


UUID=4d281b03-f778-45f7-8783-a7bfdd328146 swap swap defaults, noatime 0 2


Thanks for that. I now know I can add it to fstab as I expected but couldn't quite remember. Most other places show the line as generally being

UUID=<UUID> none swap defaults 0 0
as opposed to what you have put. My current line did make me wonder if it should have the sw option in the current version. Whether to use defaults, swap, both or it doesn't matter I've had conflicting reads when having a quick look (but I'll check my previous install when I get home.)


# The 'sw' option indicates that the swap partition is to be activated
# with 'swapon -a'.
Not sure if that's something that's needed each boot. From limited, brief reading I didn't think it should be needed for a partition explicitly formatted for swap usage...

But in part I posted as it seemed very strange that it didn't use the space I formatted as Swap when installing initially so I had a number of questions more related to that, as well as how to get it working properly.
1. Has anybody else experience weirdness with this? If it's more than a one-off it may need addressing.
2 Unless Ubuntu has decided to go with a swap file, rather than partition. From one of the above posts it seems they may as standard now. Are there any benefits to using one method or the other?

I'm sure I had a related Q3 but my mind has just gone blank.....

VMC
May 2nd, 2018, 09:49 PM
So your swap partition was active before installing ubuntu? Odd. Normally it see's the swap partition and formats it, and uses it. I haven't paid much , as my swap partition has always been were its at for some time.

Does the command "free" show your swap partition as active now.

VMC
May 3rd, 2018, 05:40 AM
@oldfred. The original fstab I showed came from my manjaro install I was on at the time. I need to recheck that, thanks.

kazakore
May 3rd, 2018, 08:36 AM
So your swap partition was active before installing ubuntu? Odd. Normally it see's the swap partition and formats it, and uses it. I haven't paid much , as my swap partition has always been were its at for some time.

Does the command "free" show your swap partition as active now.


Now that I've added the partition to fstab it does and everything is as I would expect. Prior to that I was getting a 2GB swap file, rather than my 16GB swap partition. Don't know why but guess it's not something to worry about too deeply.