Situation: increase swap size (/dev/sda3) greater than Ram (8 GB) when HD 128 GBMotivation: 8 GB RAM is too little; 30 GB free space in my SSD; I want to turn 20 GB to SSD swapCharacteristics of systemSwap non-immutable/changeable. I cannot find any evidence why /mnt/.swapfile should be immutable so you do not need the change the file attributes of the swapfilesudo lsattr /mnt/.swapfile -------------e-- /mnt/.swapfileCommand sudo fdisk -lu /dev/sda gives Disk /dev/sda: 113 GiB, 121332826112 bytes, 236978176 sectors Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: gptDisk identifier: 082F85CA-EE3E-479C-8244-858B196FA5BADevice         Start       End   Sectors   Size Type/dev/sda1       2048      4095      2048     1M BIOS boot/dev/sda2       4096 220323839 220319744 105.1G Linux filesystem/dev/sda3  220323840 236976127  16652288     8G Linux swapCommand df -h givesFilesystem      Size  Used Avail Use% Mounted onudev            3.9G     0  3.9G   0% /devtmpfs           793M  9.4M  784M   2% /run/dev/sda2       104G   74G   25G  75% /tmpfs           3.9G   54M  3.9G   2% /dev/shmtmpfs           5.0M  4.0K  5.0M   1% /run/locktmpfs           3.9G     0  3.9G   0% /sys/fs/cgrouptmpfs           793M   64K  793M   1% /run/user/1000Allocate more disk space for Swap in /dev/sda3.My unsuccessful workflow for the task when HD and Swap on the same partition, /dev/sda3masi@masi:~$ sudo -iroot@masi:~# swapoff /dev/sda3root@masi:~# swapon[blank]    root@masi:~# dd if=/dev/zero of=/dev/sda3 bs=20480 count=1Mdd: error writing '/dev/sda3': No space left on device416308+0 records in416307+0 records out8525971456 bytes (8.5 GB, 7.9 GiB) copied, 18.7633 s, 454 MB/sroot@masi:~# mkswap /dev/sda3Setting up swapspace version 1, size = 8 GiB (8525967360 bytes)no label, UUID=245cb42c-1d4e-4e21-b544-16b64af962d6root@masi:~# swapon -p 99 /dev/sda3root@masi:~# swaponNAME       TYPE      SIZE USED PRIO/dev/sda3  partition   8G   0B   99root@masi:~# vi /etc/fstab ...HD and Swap on same Partition - Current Workflow [Ijaz, cas, FarazX]Merging. Use fallocate at the beginning instead dd because no need to put zeros masi@masi:~$ sudo fallocate -l 20G /mnt/.swapfilemasi@masi:~$ sudo mkswap /mnt/.swapfile Setting up swapspace version 1, size = 20 GiB (21474832384 bytes)no label, UUID=45df9e48-1760-47e8-84d7-7a14f56bbd72masi@masi:~$ sudo swapon /mnt/.swapfileswapon: /mnt/.swapfile: insecure permissions 0644, 0600 suggested.masi@masi:~$ sudo chmod 600 /mnt/.swapfilemasi@masi:~$ free -m              total        used        free      shared  buff/cache   availableMem:           7925        1494         175         196        6255        5892Swap:         28610           0       28610Add the following line in your /etc/fstab which is better than adding the thing to your runlevels (/etc/rc.local), where I put the swapfile to the /mnt/.swapfile to maintain Linux/Unix philosophy and maintain the integrity of my system backup scripts; If swapping to an SSD, use the discard option so that the blocks are trimmed on every reboot, so not sw# http://unix.stackexchange.com/a/298212/16920# http://unix.stackexchange.com/a/298543/16920# If swap is on SSD, trim blocks each time at startup./mnt/.swapfile  none    swap    defaults,discard      0        0# If swap on External HDD, just use sw.#/media/masi/SamiWeek/.swapfile  none    swap    sw      0        0SourcesHow to increase swap space? https://askubuntu.com/a/178726/25388 General discussion about increasing swap space for beginners. Linux Partition HOWTO for HDDs, not SSDs: 4. Partitioning requirements. http://www.tldp.org/HOWTO/Partition/requirements.html So do not put your swap to outer tracks on SSDs but use defaults,discard options to trim your blocks as proposed by @cas. System: Linux Ubuntu 16.04 64 bitLinux kernel: 4.6Linux modules: wlHardware: Macbook Air 2013-midRam: 8 GBSSD: 128 GB    
How to Allocate More Space to Swap and Increase its Size Greater than Ram?
linux;linux kernel;swap
You just want to increase the swap size on your system using the space from sda2. Your sda2/dev/sda2       104G   74G   25G  75%  / You can add additional swap space to your system by using swap file created on / that will utilize your sda2. Just do:dd if=/dev/zero of=/swapfile bs=20480 count=1Mand then do:sudo mkswap /swapfile  sudo swapon /swapfile and check, you swap space will increase by that amount using free -m and yes , to enable it at boot time add the entry in /etc/fstab /swapfile     none     swap     sw     0     0