Optimization of Ubuntu (and other Linux-s) for SSD

Good day to all who read. In this mini-article, I would like to collect and consider the main points of optimizing the work (and, of course, extending the life cycle) of solid-state drives. Almost all information can be easily found on the net, but here I will try to mention a couple of pitfalls.

The first thing you should start with is choosing a file system. If the system is on the desktop, then there won’t be any special questions - take journaling ext4 - which has a lot of advantages over other FS. Yes, there will be more write cycles to the media, but there will be a guarantee that in the event of a power failure you will not lose data. On laptops, netbooks - there are batteries, and the probability of disconnection due to loss of power is almost zero (but, of course, anything can happen), and therefore journaling is usually recommended to be turned off. If you really want to do this, then after installing the system we boot from liveCD, and write in the terminal. Other methods are not recommended - lose TRIM support. Also, do not turn off the log by adding the writeback parameter

tune2fs -O ^has_journal /dev/sda1
e2fsck -f /dev/sda1


"in the fstab configuration - the system will not start due to a mounting error (if the trim was turned on before).

The next thing to consider is the swap file. Under my nickname (now ubuntu 11.04) code is usually written, movies are watched in HD and actively During this time, the swap file was never needed, the maximum RAM consumption was 1GB, out of 2 available in the netbook.
If your scenario of using the system is similar to mine, or you do not have a desktop, the swap file is not needed. Otherwise, transfer it to the HDD If logging can still be left, see with its relative harmlessness, the swap partition is clearly evil, devouring both limited rewriting cycles and expensive gigabytes, the amount of which modern SSDs can not yet boast.

Well, the system is installed - you can do optimization! The very first step is to enable TRIM - the main technology that should extend the life and load distribution of the SSD.
It becomes very simple - open fstab (for example like this),

gksudo gedit /etc/fstab

look for the lines
“UUID = [NUMS-AND-LETTERS] / ext4 errors = remount-ro 0 1”
and replace it with
“UUID = [NUMS-AND-LETTERS] / ext4 disсard, errors = remount-ro 0 1 ”

Usually, by default the trim is disabled, but I post a way to check it - go under the root and execute the commands

1. dd if=/dev/urandom of=tempfile count=10 bs=512k oflag=direct// write 5MB of random data

2. hdparm --fibmap tempfile// Look for any starting LBA address from file

3.hdparm --read-sector [ADDRESS] /dev/sdX// Read the data from the starting LBA address of the file, replace [ADDRESS] with your Starting LBA address from the output of the previous command

4. rm tempfile // Now delete the temporary file and synchronize the FS:
5. sync

Repeat step 3 - and look at the console output. If zeros are displayed, then the trim works. If you fixed fstab, rebooted, but the trim did not activate - look for errors in invalid logging disconnection.

Further, it is worth remembering that our Nix loves to maintain a variety of logs. And either transfer them to the HDD, or keep them in RAM until the system reboots. I believe that if you do not have a server at home, then the second option is optimal, and it is implemented by adding the following lines to fstab
tmpfs / tmp tmpfs defaults 0 0
tmpfs / var / tmp tmpfs defaults 0 0
tmpfs / var / lock tmpfs defaults 0 0
tmpfs / var / spool / postfix tmpfs defaults 0 0


By default, every time you open a file, the system leaves a mark on the time of the last open - extra write operations. It’s easy to disaccustom - add
disсard, errors = remount-ro 0 to fstab before a
couple more options -
relatime, nodiratime The first allows you to record only the change time (sometimes it is necessary for some programs to work stably), the second one cancels the recording of access time to directories. In principle, instead of relatime, you can put noatime , which will not update anything at all.

After that, it is worth setting up deferred recording - the kernel will accumulate data waiting to be written to disk and write it either in case of urgent need, or after a timeout. I set the timeout to 60 seconds, someone to 150.
To do this, open /etc/sysctl.conf and add the parameters
vm.laptop_mode = 5 // Turn on
vm.dirty_writeback_centisecs = 6000 mode in scc. Those. 100 units = 1 second

And finally, turn off the I / O scheduler that was once needed for better positioning of the HDD heads. To do this, go into the config of the hornbeam / etc / default / grub
and in the line
GRUB_CMDLINE_LINUX_DEFAULT = "quiet splash" insert the parameter elevator = noop
Along the way, you can remove unnecessary and uninformative splash screens by reducing the start time of the system by another second, simply by removing quiet splash .

Here are the main points. Then it’s worthwhile to show your imagination - for example, transfer it somewhere, or completely disable the browser cache and so on. As a reward for the manipulations done, your SSD will serve you faithfully, and with every start it will delight you with a good speed.

Update
Many people notice the need to align partitions. Thanks to comrade isden for the link to the topic. wiki.archlinux.org/index.php/SSD#Partition_Alignment
If you do not want to take risks, then it is better not to disable the log. Then the trim will be guaranteed to work, and some data protection from major system failures.

Below are a few links for which I received information.
vasilisc.com/ssd_ubuntu
tokarchuk.ru/2011/01/enable-trim-support-in-ubuntu
sites.google.com/site/linuxoptimization/home/ssd

Also popular now: