Comments on How to Add a Swap File On Ubuntu

A swap file in Ubuntu is a dedicated file on the hard drive used as virtual memory when RAM is full, enhancing system performance by providing additional space for temporarily storing data that is not actively used by the CPU.

4 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Jens Huehne

It should probably be mentioned that a standard install of Ubuntu would already have created and activated a decently sized swap partition. A swap file is rather uncommon in Linux so this is useful only if you have installed without a swap partition and are loath to re-partition your drive.

By: iswinar

swap file is good if theres a memory limitation

By: Ernst Kloppenburg

This guide should really be updated to use fallocate instead of dd, because it is a lot fastere.g.:fallocate -l 256k /swapfile

By: John Deputy

Do remember, it is not possible to create a 'swapfile' on a BTRFS filesystem volume.

If you are doing this on a VM such as HyperV/Vmware, no need to shutdown the guest, just add a new drive with a fixed size for the swap drive, and then:

a) type "fdisk -l"this will give you the list of drives and the new drive should come up as /dev/sd*

b) type: "mkswap /dev/sd*"(the one you just added, sourced from the fdisk)

c) note the UUID, and simply edit the fstab file replacing the /swapfile part of the line with the UUID from step (b).

d) type "swapon -a"

e) type "top"you should see the swap size show the size of the drive you assigned.

Reboot the guest.

Do note that if you have multiple virtual scsi controllers, it may throw the drive mapping off, which means you will need to re-order the drives accordingly. Always a good idea to add a new drive to the 'last' virtual scsi-controller if you have more than one so that it keeps its order during virtual bios assignment.

Hope the above helps anyone else doing gods work in a virtual environment.