swap file

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Bunz_of_Steel

swap file

Post by Bunz_of_Steel »

I have fresh install Mint 14 with 32G ram and OCZ Vertex 4 SSD(256G), 2TB HDD.
Looking to optimize my system and considering moving swap to HDD not SSD. Gathering not good idea to swapoff -a right? Just not sure how to move swap file. Guessing something like turnswap off and then add it using mkswap? I have used Linux before but I'm no expert either. Would appreciate a little hand holding here as I'm not sure what the steps are or if I am going down the wrong path. Any advice or insight appreciated, thx!


# swapoff /dev/device
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29507
Joined: Wed Jul 06, 2011 3:58 am

Re: swap file

Post by xenopeek »

First check, do you use swap? With 32 GiB RAM I'd figure the only reason to have swap is so you can hibernate (suspend to disk), if you don't do that you don't need swap at all.

You can easily configure swap not to be used, by editing your /etc/fstab line and commenting out (putting a # in front of) the line for your swap. That disables swap upon reboot. You can indeed disable swap temporarily with swapoff -a. But I'm guessing you have a swap partition, and you want to reclaim the space currently used for swap on your SSD to one of your other partitions there. You can not do that while booted in to your current Linux Mint installation (you can't resize a partition you are using).

So, the steps are:
  1. Edit your /etc/fstab file and comment out the line that has swap on it. To edit this file, run the command:

    Code: Select all

    gksudo gedit /etc/fstab
    The line you want to comment out (by insert a # as the first character of that line) would look similar to:

    Code: Select all

    UUID=cbfe9ae2-e86e-4d3e-89f8-db639633723a   swap    swap   sw   0   0
  2. After saving that file, reboot your computer and boot from your Linux Mint installation ISO. Start GParted from there.
  3. Using GParted, you can delete the swap partition on your SSD. Then resize an existing partition either right before or right after the swap partition, to absorb the freed up disk space. Apply all changes and next step.
  4. Switch GParted to work on your second hard disk, and resize and existing partition there to make room for a swap partition if there isn't free disk space enough. Then create a new partition as type Linux swap. Apply all changes and next step.
  5. Reboot your computer and log in to your current Linux Mint installation.
  6. Run the following command, and copy the UUID value of your swap partition you just created:

    Code: Select all

    sudo blkid
  7. Edit your /etc/fstab file again, uncomment (remove the # from in front of the line) the line you commented out earlier and replace the current UUID value on that line with the one from your command. Save and close the file, then run the following command to enable swap now:

    Code: Select all

    sudo swapon -a
If you get into trouble with GParted, or not sure how to proceed, please share a screenshot so we can see what you see.
Image
bigj231

Re: swap file

Post by bigj231 »

I agree with xenopeek. You won't need swap with 32GB of RAM. I never suspend to disk, and I don't use more than 4GB of my 6GB, so I don't even have swap on my laptop SSD. If you want to suspend to disk, then make your swap on the HDD, and set the swapiness to something like 5.

Code: Select all

echo "vm/swappiness=5" >> /etc/sysctl.conf
Do that after you finished xenopeek's guide though.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: swap file

Post by catweazel »

Bunz_of_Steel wrote:I have fresh install Mint 14 with 32G ram and OCZ Vertex 4 SSD(256G), 2TB HDD.
Looking to optimize my system and considering moving swap to HDD not SSD.
Some tips to keep your SSD alive a lot longer...

Turn off ext4 journalling
When installing Mint, before running the installer, open a terminal and turn off journalling, and set the fs to be checked at regular intervals:

Code: Select all

$ sudo mke2fs -t ext4 -O ^has_journal /dev/sda1
$ sudo tune2fs -o journal_data_writeback /dev/sda1
$ sudo tune2fs -m 5 /dev/sda1
$ sudo tune2fs /dev/sda1 -i 7d
$ sudo tune2fs /dev/sda1 -c 15
$ sudo tune2fs -l /dev/sda1
Then run the installer and choose to install to the SSD with / as the mount point, but don't format it. The installer will give you a warning that can be ignored.

When the install is completed, reboot and edit etc/fstab. Change the / mount point options to:

Code: Select all

data=writeback,noatime,discard
Making use of RAM
While you're editing fstab, mount tmp and logs into RAM so they get deleted on every reboot or shutdown:

Code: Select all

tmpfs        /tmp        tmpfs   noatime,nodev,nosuid,noexec,mode=1777   0       0
tmpfs        /var/log    tmpfs   defaults,noatime,mode=0755              0       0 
If you use firefox, set it to use memory as for its cache:

Code: Select all

about:config
Add a new string key named:

Code: Select all

browser.cache.disk.parent_directory
set its value to:

Code: Select all

/tmp
The other tips you've received to set swapiness and not have a swap partition can also be applied. However in xenopeeks example, he's using the fact that you've already created the swap partition. Simply don't create one during the next installation you do. That way you don't have to later delete the partition or comment out the entry in fstab. If you get a warning about no swap during the installation, simply ignore it.

When you've added /tmp and /var/logs to fstab, don't use mount -a. You need to delete the contents of /var/log as root then reboot. If you don't do this then /var/log won't mount.

Also, see this thread http://forums.linuxmint.com/viewtopic.php?f=47&t=126397, and read the wiki at the link.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Bunz_of_Steel

Re: swap file

Post by Bunz_of_Steel »

Thank all for quick responses and advice is right on! I went with a new install as this install is about a day old only and nothing vital on it. Following along with TehGhodTrole and ran the commands to turn off ext4 journaling. Chose to install to / and did NOT format. Did have like two warning that I chose to ignore. Below is a copy of my fstab

cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=522567a9-0f7d-475c-b495-661dc5569599 / ext4 errors=remount-ro 0 1


I believe my next step is to change the /mount point options so I need to add line below to fstab?
/dev/sda1 / ext4 data=writeback,noatime,discard
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: swap file

Post by catweazel »

Bunz_of_Steel wrote:I believe my next step is to change the /mount point options so I need to add line below to fstab?
/dev/sda1 / ext4 data=writeback,noatime,discard
Yes, and well done, btw. Oops. Don't forget the 0 1 at the end. Your fstab line should look like this:

Code: Select all

UUID=522567a9-0f7d-475c-b495-661dc5569599 / ext4  data=writeback,noatime,discard 0 1
You can add the two tmpfs lines I gave you above exactly as they are.

writeback changes the data order. noatime stops the file system from date/timestamping files, and discard controls the SSDs TRIM to fill empty space in the background.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Bunz_of_Steel

Re: swap file

Post by Bunz_of_Steel »

Done deal-O here now. I added the tmp and logs into ram running fine and no kernal panics :). Thanks for the advice all, really appreciate the expertise. To think folks pay for help like this for M$ and don't get near the accurate or timeliness :P Next step to start looking at the TRIM & scheduler as I think they have an affect on SSD longevity.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: swap file

Post by catweazel »

Bunz_of_Steel wrote:Thanks for the advice all, really appreciate the expertise.
You're welcome. Funny nic, btw.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Locked

Return to “Beginner Questions”