LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2016, 05:05 AM   #16
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled

I was told to do the below for 4 gig, it would add on to my existing 4gig to total 8 gig, I took a chance and ran the below:

dd if=/dev/zero of=/my4GBswap bs=1M count=4096

chmod 600 /my4GBswap

mkswap /my4GBswap

swapon /my4GBswap

echo "/my4GBswap swap swap defaults 0 0" >> /etc/fstab

verify with swapon -s

==========

swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 4079612 3299880 -1
/my4GBswap file 4194300 0 -2

Do I now have an 8 gig usable swap ???
correct me if I'm wrong, but it looks like its now 7.9 gig swap?

http://www.aanning.com/ajissues/fedora_swap/swap2a.jpg

Last edited by Janning; 01-10-2016 at 05:19 AM.
 
Old 01-10-2016, 07:31 AM   #17
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
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.
 
Old 01-10-2016, 08:58 AM   #18
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
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.
Being I'm new to Linux...what you just said, made under 10% sense to me. I did not do anything to my existing swap partition, I added a file swap...does that make a difference?
How do I rebuild the initrd with Dracut?
Are you saying if I reboot, it will crash?
Thanks James
 
Old 01-10-2016, 10:51 AM   #19
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by Janning View Post
Being I'm new to Linux...what you just said, made under 10% sense to me. I did not do anything to my existing swap partition, I added a file swap...does that make a difference?
How do I rebuild the initrd with Dracut?
Are you saying if I reboot, it will crash?
Thanks James
Adding a swap file doesn't change anything. It is only when the initrd has a reference to a swap partition that changes... the initrd uses the UUID, so it is even possible to change the swap partition, IF the UUID is forced (mkswap -U <uuid-string>) to the old value.
 
Old 01-10-2016, 10:57 AM   #20
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Adding a swap file doesn't change anything. It is only when the initrd has a reference to a swap partition that changes... the initrd uses the UUID, so it is even possible to change the swap partition, IF the UUID is forced (mkswap -U <uuid-string>) to the old value.
I just do not know Linux well enough to get that. Bottom line, will what I did work without error ? adding my4GBswap ?


swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 4079612 3299880 -1
/my4GBswap file 4194300 0 -2
 
Old 01-10-2016, 11:22 AM   #21
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Adding a swap device/file is not a problem.

Removing an added swap device/file is not a problem.

Changing one that was created during install can be a problem due to the initrd containing a reference to the swap file. When it doesn't exist, the boot system counts that as a corrupted system.
 
Old 01-10-2016, 11:30 AM   #22
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Adding a swap device/file is not a problem.

Removing an added swap device/file is not a problem.

Changing one that was created during install can be a problem due to the initrd containing a reference to the swap file. When it doesn't exist, the boot system counts that as a corrupted system.
ok.... did I technically add or change? I feel like I added and the issue you describe does not apply?
I appreciate your efforts... I just need to know if what I did, will work with no issue?
 
Old 01-10-2016, 09:27 PM   #23
wagscat123
Member
 
Registered: Jan 2009
Location: Maryland-Pennsylvania border, USA
Distribution: openSUSE 42.2, 42.3, Tumbleweed, OS X 10.10, Ubuntu 17.04, and Linux Mint 17.3/18.1
Posts: 660
Blog Entries: 9

Rep: Reputation: 89
An easier solution to avoid the mentioned initrd swap configuration issue would be to leave your current 4 GB swapfile intact, and just create a new 4 GB swapfile that's mounted at boot time so you have a total of 8 GB of swap. Here's a handy guide on how to create a swapfile, initiate it, mount it, and add it to fstab so it is mounted at boot time:

https://www.centos.org/docs/5/html/5...ting-file.html

Note: Yes these directions for an old version of CentOS, but the commands on this page of the guide are completely applicable to your situation. Just pull up a command line, and run the commands, with adjusting the block count to the right number per the guide and for wherever you wish to have your swapfile.

Last edited by wagscat123; 01-10-2016 at 09:32 PM.
 
Old 01-10-2016, 09:32 PM   #24
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by wagscat123 View Post
An easier solution to avoid the mentioned initrd swap configuration issue would be to leave your current 4 GB swapfile intact, and just create a new swapfile that's mounted at boot time. Here's a handy guide on how to create a swapfile, initiate it, mount it, and add it to fstab so it is mounted at boot time:

https://www.centos.org/docs/5/html/5...ting-file.html

Note: Yes these directions for an old version of CentOS, but the commands on this page of the guide are completely applicable to your situation. Just pull up a command line, and run the commands, with adjusting the block count to the right number per the guide and for wherever you wish to have your swapfile.
Did you see my post 16 ? .... Isn't this pretty much what I've done ?
 
Old 01-10-2016, 09:34 PM   #25
wagscat123
Member
 
Registered: Jan 2009
Location: Maryland-Pennsylvania border, USA
Distribution: openSUSE 42.2, 42.3, Tumbleweed, OS X 10.10, Ubuntu 17.04, and Linux Mint 17.3/18.1
Posts: 660
Blog Entries: 9

Rep: Reputation: 89
Thanks for pointing that out. It looks like you did just that. The output of swapon -s shows you have ~8 GB of swap now. Is everything booting correctly without any issues? You only added a swap file, if you haven't changed the old swapfile since posting swapon -s.

Last edited by wagscat123; 01-10-2016 at 09:35 PM.
 
Old 01-10-2016, 09:45 PM   #26
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by wagscat123 View Post
Thanks for pointing that out. It looks like you did just that. The output of swapon -s shows you have ~8 GB of swap now. Is everything booting correctly without any issues? You only added a swap file, if you haven't changed the old swapfile since posting swapon -s.
I have not rebooted yet, if you read all of this post, and I have another post in another forum...I have not got clear cut answer whether or not it may crash if I reboot. I think I'm ok as is, but, never know, someone may post another command I need to do prior to reboot.
 
Old 01-10-2016, 10:14 PM   #27
wagscat123
Member
 
Registered: Jan 2009
Location: Maryland-Pennsylvania border, USA
Distribution: openSUSE 42.2, 42.3, Tumbleweed, OS X 10.10, Ubuntu 17.04, and Linux Mint 17.3/18.1
Posts: 660
Blog Entries: 9

Rep: Reputation: 89
If you give the results of "swapon -s" and "cat /etc/fstab", I'll be table to tell whether you crash on reboot or not (in in whether you modified your old swap file). But you sound pretty good
 
Old 01-10-2016, 10:16 PM   #28
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by wagscat123 View Post
If you give the results of "swapon -s" and "cat /etc/fstab", I'll be table to tell whether you crash on reboot or not (in in whether you modified your old swap file). But you sound pretty good
Ok? How do I look ?

[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 4079612 3175128 -1
/my4GBswap file 4194300 0 -2


[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Nov 2 13:24:23 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/fedora_localhost-root / ext4 defaults 1 1
UUID=9ca37d73-71d1-44d1-beac-09c6dbb27737 /boot ext4 defaults 1 2
/dev/mapper/fedora_localhost-home /home ext4 defaults 1 2
/dev/mapper/fedora_localhost-swap swap swap defaults,x-gvfs-show 0 0
/my4GBswap swap swap defaults 0 0
 
Old 01-10-2016, 10:31 PM   #29
wagscat123
Member
 
Registered: Jan 2009
Location: Maryland-Pennsylvania border, USA
Distribution: openSUSE 42.2, 42.3, Tumbleweed, OS X 10.10, Ubuntu 17.04, and Linux Mint 17.3/18.1
Posts: 660
Blog Entries: 9

Rep: Reputation: 89
You left your initial swap file intact, initrd will be happy. You're good to reboot

Last edited by wagscat123; 01-10-2016 at 10:33 PM.
 
Old 01-10-2016, 10:35 PM   #30
Janning
Member
 
Registered: Nov 2014
Posts: 66

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by wagscat123 View Post
You left your initial swap file intact, initrd will be happy. You're good to reboot
the way I understand it is, I left the initial 4 gig swap "partition" intact, and added a 4 gig swap file...for a total of 8 gig swaping? I now have a 4 gig partition and a 4 gig file, for swap. I assume its ok to mix partition and file for SWAP.

Last edited by Janning; 01-10-2016 at 10:36 PM.
 
  


Reply

Tags
swapfile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I have to change the size of my swap partition if I add RAM? piratetux! Puppy 2 04-17-2009 12:05 PM
Can I change swap size (x86_64 7.10)? ChootarLaal Ubuntu 3 03-13-2008 03:26 PM
Change the swap size ust Linux - General 11 06-17-2005 12:04 AM
HowTo Change swap file size gee Linux - Newbie 2 02-26-2004 09:40 PM
change swap partition size? jamaso Linux - General 4 07-03-2002 10:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration