1

I'm on Fedora 23, Dell OptiPlex 745, Core 2 Duo, 2.13 GHz, 1066 MHz FSB and 4 gig of RAM; the drive is a Samsung 840 EVO solid state drive.

The swap file is currently at 4 gig. How can I change this size? I'd like to go to 8 Gig.

Janning
  • 21
  • 1
  • 4
  • It's probably a swap partition, rather than a file. Either way, you can't change its size while it's in use. Boot from a LiveCD, and use GParted to resize the partition, assuming there's adjacent free space – sawdust Jan 09 '16 at 21:48
  • Just in case it is an real file: `swapoff -a` (turns off all swap). Delete file. Create a bigger one (e.g. with dd). mkswap. Swapon. Done. – Hennes Jan 09 '16 at 21:56
  • hi, I took a screen shot (see image swap1a.jpg at www.aanning.com\ajissues\fedora_swap screenshot of the Disks app) – Janning Jan 10 '16 at 07:01
  • Keep in mind I'm very much a beginner in Linux, swap1a.jpg shows what I assume is a swap partition? I'm not sure at all what I have here, or how to make it go from 4 to 8 gig. I do know I have free space on the disk to do this. – Janning Jan 10 '16 at 07:02

1 Answers1

3

The proper way to go would be to resize some of the partitions and create additional swap partition or increase the one that you already have but with SSD drive the following should also work fine.

  1. Open terminal and switch to root:

    sudo -i
    
  2. Check how much swap space you currently have:

    swapon -s
    
  3. Create a file that will work as you swap file. dd will do this for us (create a file made of zeros). The file will have 4GB.

    dd if=/dev/zero of=/my4GBswap bs=1M count=4096
    
  4. Change permissions:

    chmod 600 /my4GBswap
    
  5. And make swap:

    mkswap /my4GBswap
    
  6. And enable it:

    swapon /my4GBswap
    
  7. Almost there. Now we need to make the changes persistent after reboots. So let's add this to fstab:

    echo "/my4GBswap swap swap defaults 0 0" >> /etc/fstab
    
  8. Make sure that it worked:

    swapon -s
    
BenMorel
  • 905
  • 4
  • 13
  • 33
morholt
  • 88
  • 1
  • 6
  • the below is my swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4079612 3305948 -1 I currently have a 4 gig swap file (see www.aanning.com\ajissues\fedora_swap screenshot swap1a.jpg) I want an 8 gig total swap file. I assume I would do a dd if=/dev/zero of=/my8GBswap bs=1M count=8192 chmod 600 /my8GBswap mkswap /my8GBswap swapon /my8GBswap echo "/my8GBswap swap swap defaults 0 0" >> /etc/fstab verify with swapon -s What will this do with my current 4gig swap? – Janning Jan 10 '16 at 09:13
  • http://www.aanning.com/ajissues/fedora_swap/1.txt – Janning Jan 10 '16 at 09:14
  • The above site is a text file with my other post, which is formatted more readable – Janning Jan 10 '16 at 09:15
  • The code from the file will ADD 8GB of swap to your current configuration. So right now you have 4GB (swap partition) if you create 8GB file you will get 4+8=12GB. So with the above you are not replacing your current swap with new you are adding some more swap to your current config. – morholt Jan 10 '16 at 09:28
  • Ah, ok, so its as simple as doing what you originally said, this will NOT alter or turn off my existing 4 gig, but, instead add to my 4 gig for a total of 8? Is my existing swap a file swap or a partition swap? I was thinking it is a partition type swap, if so, will this still work? – Janning Jan 10 '16 at 09:54
  • I went ahead and did your original suggestion. swapon -s gives the below...do I now have an 8 gig swap ? swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4079612 3299880 -1 /my4GBswap file 4194300 0 -2 – Janning Jan 10 '16 at 09:59
  • http://aanning.com/ajissues/fedora_swap/2.txt – Janning Jan 10 '16 at 10:03
  • http://www.aanning.com/ajissues/fedora_swap/swap2a.jpg – Janning Jan 10 '16 at 10:19
  • looking as swap2a.jpg in my link above...i'd say that did it ? – Janning Jan 10 '16 at 10:20
  • Yes, it did. That looks correct. – morholt Jan 10 '16 at 10:26
  • Very good! Thanks so much. Your solution was FAR easier than others there were suggested! – Janning Jan 10 '16 at 10:30
  • I was sharing your method with another trying to change his, and I'm being told "One thing to remember with Fedora (and likely RH7/CentOS 7 too) is that by default the initrd contains initialization code that includes the information on swap. Deleting/recreating/changing that specific swap partition will cause boot failures (the UUID of the swap device changes) until you rebuild the initrd with Dracut" Which I do not understand at all. ? – Janning Jan 10 '16 at 13:58
  • So that probably means that when you change swap partition (remove it and recreate it) it UUID changes and if it's mounted using UUID you might run into issues - but this should only require changing /etc/fstab file and that's it. But this got me thinking and I haven't used the above solution on desktop systems so I'm wondering if suspend/hibernate will work with swap files (never tested this) – morholt Jan 10 '16 at 16:25
  • I don't use suspend/hibernate. This box is my learning box, believe it or not, I've been an oracle developer for 20+ yrs...and successfully avoided ever getting more than toe deep into Linux! I'm at a consulting firm, "on the bench" for now, and using this box to install WEB logic and APEX. Would have put more RAM in, but its at max. The hard drive is a Samsung 840 EVO solid state, soSWAP is going to be fast. Bottom line is....I believe what you instructed me..gives me 8 gig total usable SWAP..didn't touch the partition. – Janning Jan 10 '16 at 20:17
  • ...I'm understanding this as, we added 4 gig to the existing SWAP area, via a SWAP file....I should be good to go? – Janning Jan 10 '16 at 20:17
  • I have that kind of config running for a while now on one of my VMs with Fedora 22. You are good to go. – morholt Jan 10 '16 at 20:40