13

Why don't I have a swap partition in my installation?

$ lsblk
nvme0n1     259:0    0 238.5G  0 disk 
└─nvme0n1p1 259:1    0 238.5G  0 part /

Did I install Ubuntu/ Kubuntu wrong?

I thought it should be like this:

nvme0n1     259:0    0 238.5G  0 disk 
├─nvme0n1p5 259:3    0  15.9G  0 part [SWAP]
├─nvme0n1p1 259:1    0 222.6G  0 part /
└─nvme0n1p2 259:2    0     1K  0 part 

I just picked what was suggested during the installation. But it seems odd.

Zanna
  • 70,465
Run
  • 2,639

1 Answers1

26

There's nothing wrong. In fresh installations of 17.04 we have a swap file instead of a swap partition, as mentioned in the release notes (if you upgrade rather than install afresh, you will still have a swap partition).

The swap file is located at

/swapfile

You can always check the status of swap with the command swapon --show.
Here's my output in 17.04:

$ swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file 1.3G 62.2M   -1

You can also see if it's being used with the free command as usual

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        1.3G        152M         95M        423M        328M
Swap:          1.3G         62M        1.3G

See - working just fine.

According to the Arch wiki

There is no performance advantage to either a contiguous swap file or a partition, both are treated the same way.

It just provides a little more flexibility; it's easier to resize.

Minor note: Btrfs (alternative filesystem to ext4) does not support swap file usage, so you will need to create a swap partition yourself if you want to use Btrfs. But if you're brave enough to use Btrfs, you surely know what you're doing anyway ;)

Zanna
  • 70,465
  • @Zanna the /swapfile and a swap partition serve a similar function, except in the case of hibernation, correct? – heynnema Apr 29 '17 at 21:13
  • 1
    If I just upgraded an older system that installed with a swap partition to 17.04, should I delete my old swap partition? – cat Apr 29 '17 at 22:44
  • @cat - you should make that another question... – HorusKol Apr 30 '17 at 01:54
  • 1
  • btrfs has become production ready a while ago, it's only some features that are (still) experimental; it's not correct to treat the whole FS as experimental... – heemayl Apr 30 '17 at 03:05
  • @heynnema if you hibernate on a system with a swap file, RAM contents are written to the swap file - it's the same. But I'm still trying to get it working on my system – Zanna Apr 30 '17 at 04:05
  • Oh... does this new default mean that you'll have a hard time getting hibernation functionality if you don't think ahead of time to ditch defaults and add the swap partition? Or can you actually boot-resume from a swap file? – Ruslan Apr 30 '17 at 07:15
  • @Ruslan hibernation should work just as before, but it's always been a bit dicey. My device is a basketcase, and hibernation has presented me with different challenges in each version of Ubuntu. You can indeed (theoretically) resume from a swap file, as detailed in the Arch wiki. – Zanna Apr 30 '17 at 07:17
  • @heemayl, btrfs is not production-ready. I'm not aware of any data-loss bugs as long as you stick to basic functionality, but there are some non-obvious "gotchas" that could leave you with a permanently read-only filesystem, and others that could cause your computer to spend months or years performing an operation. – Mark Apr 30 '17 at 07:26
  • @Zanna my understanding is that the /swapfile will be max 2G by default, and doesn't have the same hibernation characteristics as a larger swap partition. To manually create a /swapfile, you need to use fallocate and then just create a /swapfile entry in /etc/fstab. You'd also want to remove the older swap definition in /etc/fstab, and delete the old swap partition. – heynnema Apr 30 '17 at 13:15
  • @Zanna clarification. You might look at Rinzwind's command strings to create/use /swapfile at https://askubuntu.com/questions/904628/default-17-04-swap-file-location/904632#904632 (fallocate, chmod, mkswap, swapon) and an entry in fstab. – heynnema Apr 30 '17 at 14:10