Search

December 5, 2012

Installing Ubuntu 12.10 on an SSD, Part 2

Recently I took the plunge and put an SSD drive into my desktop. Since I needed to re-install the OS, I figured I would install the latest Ubuntu, version 12.10. I went over my trials and tribulations of getting the OS installed in part 1, today we are going to talk about some changes I made afterwards to support the SSD.

First things first: dealing with the swap partition. I had a swap partition on the old HDD but what is the point of having all your programs load quickly if swap is going to be on the old, slow disk? I decided to deactivate the swap partition and go with a swap file moving forward for maximum flexibility.

Everything I read said that modern linux kernels will perform just as well with a swap file as a swap partition. The only documented drawback I found was that the Ubuntu hibernate implementation (that’s the OS hibernate function not the Java Hibernate persistence engine) does not work with a swap file and requires a swap partition. Since I never use that functionality, I was good to go:

# Create the swap file as an empty, 8GiB file
sudo fallocate -l 8g /mnt/8GiB.swap
# The swap file should not be readable by normal users, otherwise they
# could snoop on the memory of other user's processes
sudo chmod 600 /mnt/8GiB.swap
# Format the file as swap
sudo mkswap /mnt/8GiB.swap
# Tell the OS about the new swap file
sudo swapon /mnt/8GiB.swap
# Check if it worked
cat /proc/meminfo
# Determine old swap partition device
sudo fdisk -l /dev/sdb
# Decommission the old swap partition (your specific partition will vary)
sudo swapoff /dev/sdb6

At this point there is some housekeeping to do in /etc/fstab file to ensure the changes persist on the next boot. Remove the line for the old swap partition and add the following for the new swap file:

/mnt/8GiB.swap  none            swap    sw              0       0

Now we want to balance the fact that the swap file is on the SSD with the desire to reduce writes to the SSD to prolong the life of the drive. (Although I am of the opinion that such concerns are overblown, I like the effect of this change anyway.) We will tell the system to prefer RAM over swap using the swappiness setting. Add (or edit) the following in /etc/sysctl.conf

vm.swappiness=1
vm.vfs_cache_pressure=50

If you are interested in the technical details as to what these settings do, check out the documentation at http://www.kernel.org/doc/Documentation/sysctl/vm.txt.

With the swap configuration complete, we turn our attention to a couple of other tweaks for the SSD performance. However, that will have to wait for the next entry.

Resources:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.