Saturday, June 22, 2013

linux in solid state drives (SDDs)

Hi, fellas

             I'm back after a long leave. Life is so strange. It contains many curves and straight paths. I came across too many curves. Anyways things are getting fine and I'm back with another article. This article deals with installing linux in solid state drives. Some of you may have already came across solid state drives. These solid state drives are much faster than traditional hard disks. And they are getting cheaper and cheaper.
Solid State Drives are the drives that contain no disks. It is a data storage device using integrated circuit assemblies as memory to store data persistently. They are compatible with traditional I/O hard disk drives.
This article deals with installing linux in Solid State Drives(SSDs).
If you install SSDs in your system, i.e., in the hardware of your system. It can speed up the boot speed, reduce the CPU clock time, increase the overall performance of the system. Since linux can handle old systems like pentium systems, celeron systems very well, these SSDs can be used to enhance the performance of linux.
So here is the tutorial for installing linux in SSDs.
1. Configuring BIOS or UEFI:
I guess that this will confuse you. A Solid State Disk, is sometimes only recognized properly by the BIOS or UEFI, when in the BIOS the feature AHCI has been activated for SATA (instead of IDE).
Note: doesn't the BIOS or UEFI of your computer offer the option to switch to AHCI? Then the BIOS will possibly detect the SSD automatically and automatically choose the right BIOS settings for it.
start your computer, press f2, go to BIOS->advanced and expand the section 'Integrated Peripherals'.
Screen shot has been provided for reference.



Then, under the header "External SATA 6GB/s Configuration", change IDE into AHCI. Namely for External SATA 6gb/s Controller Mode.


2. Check for updated firmware: Check the website of the SSD manufacturer, whether there's an updated version available of the firmware for your SSD. If so, apply it.

3. Optimizing the operating system for SSDs: 
Reserve 10 percent for overprovisioning:
It is wise to reserve as much as 20 to 25 percent of the storage capacity of an SSD for such un-allocated space. That's of course a huge slice out of the total storage capacity, which makes nobody happy. So just reserve 10 percent for un-allocated space. Here is the screenshot for it.


After giving 10 % for over-provisioning, choose ext4 for installation.

 --> Managing swap space:
If we don't hibernate the system frequently and have lot of RAM memory to run applications, then there will be no need for swap partition. If we use both SSD and HDD, i.e., a mix of SSD and HDD then it is better to place swap partitions in HDD.

--> eliminating timestamp writes when we read files and folders:
The 2 options 'noatime' and 'nodiratime' will stop timestamp writes into the HDD when we read files and folders. We can add these 2 options to fstab configuration file. Get root authority. Create a path to fstab configuration file. Edit the file to add those 2 options.
sudo -i
enter your password and you'll be super user.
cp /etc/fstab ~/fstab-backup
The above command will copy the backup file of fstab. If the edited fstab file doesn't work, then you can replace edited fstab file with that backup file.
gedit /etc/fstab
the above command opens fstab configuration file in gedit.
Edit the mounting options for your partitions by adding the text noatime and nodiratime to the lines defining your root (/) and other partitions if you have them (/home)
Example:
# / was on /dev/sda2 during installation 
UUID=587e0dc5-2db1-4cd9-9792-a5459a7bcfd2    /    ext4      noatime,nodiratime,errors=remount-ro         0           1 
# /home was on /dev/sda3 during installation 
UUID=2c919dc4-24de-474f-8da0-14c7e1240ab8    /home     ext4          noatime,nodiratime,defaults   0        2
Note: This step is very important. If you do any mistakes, then this can corrupt ubuntu.

Now there is a process related to cleaning the disks. You can control that process for installing linux into SSDs. Name of that process is TRIM. If we're running SSD for longer time, then this TRIM process can help to us to keep SSD in good state. Most of the modern SSDs support TRIM process. But older SSDs won't support TRIM process. Therefore you can initiate automatic TRIM. There are many ways to initiate an automatic TRIM. I've used rc.local method because most of the linux users knows this rc.local file.
Open terminal by pressing ctrl+alt+T. Type this command.
sudo gedit /etc/rc.local
Be sure to have super power before executing above command.
Above the line exit 0 in that file, you now add the TRIM command fstrim -v for every automatically mounted EXT4 partition.
An example has been provided.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
fstrim -v /
exit 0


After adding TRIM command, save rc.local file, reboot the system. 

Check your current swappiness setting:
Use this command to find the swappiness of your system.

cat /proc/sys/vm/swappiness

The result will be around 60.

You can change it by using this command.

sudo gedit /etc/sysctl.conf

Add the following lines
# Sharply reduce swap inclination
vm.swappiness=1
# Improve cache management
vm.vfs_cache_pressure=50

Save the file. Reboot the system. 
Now your ubuntu or linux operating system is almost ready to deal with SSDs. You can reduce the writing actions of Firefox, chromium to reduce overload  on SSDs.

For firefox:

Set the cache to 0:
Firefox panel: Edit - Preferences - Advanced
Tab Network
Cached Web Content: set it to 0.

For chromium:

Open chromium, press f12 to open developer's console. 
Click on gear icon at the right bottom. 
Settings window will open. Tick 'Disable cache'.

Reboot the system and you're done :)

If you've enabled hibernation, disable it and you enjoy your SSD carefree for many years :) 
Writing this article wasn't easy. I had to research a lot and had to learn a lot for this article. I hope that you'll find this article understandable :) 

No comments:

Post a Comment