Setting up an SSD on Xubuntu Linux
This is the second part of a “split” article about buying a ThinkPad and setting up an SSD on Xubuntu. The first part is here.
I recently bought myself an Intel 310 SSD, and I want to describe its installation and setup in more detail. First, it needs to be physically installed. Here’s how: Service Videos, see “FRU Removals/Replacements” > “WWAN Adapter”. In fact, this site has everything you need to rebuild a ThinkPad laptop.
Next, we’ll need a utility to analyze I/O activity. I liked iotop:
$ sudo iotop -oa
Where:
- -o - only show processes or threads actually doing I/O
- -a - show accumulated I/O instead of bandwidth
This gives us aggregated information about processes that are actively using our SSD.
I’ll say right away that I used Ext4 and did NOT disable journaling, and I put swap on the other HDD that came with the laptop. An article that includes disabling journaling is here. The comments there also say that discard (also known as TRIM) will stop working if you disable journaling!
You can check the drive’s speed like this:
$ sudo hdparm -t /dev/sdb1
Setting up fstab and enabling TRIM
We’ll mount our SSD with the following additional options:
- noatime - don’t record access times for files, because we don’t need unnecessary writes to the SSD;
- nodiratime - don’t record access times for directories, because we don’t need unnecessary writes to the SSD;
- discard - enable TRIM. TRIM will extend our SSD’s lifespan.
TRIM is a command that allows the operating system to notify a solid-state drive which data blocks are no longer in use and can be used by the drive to prepare for writing. TRIM (SSD command) — Wikipedia
Here’s an excerpt from the article How Long Will Your SSD Last?:
SSD flash memory is made up of blocks, which in turn consist of pages. Data is written to individual pages within blocks, and it is impossible to update data simply by overwriting the old data. What’s more, only an entire block can be erased! So first, the data that is still needed is moved from the pages of one block to another, and only then is the entire block containing the remaining, unneeded data erased, freeing it up for new writes. This process is called garbage collection. TRIM is an operating system capability that marks unneeded data in a special way. This means the controller doesn’t need to move it by writing it to other blocks. This increases write speed and, most importantly, significantly reduces the number of rewrite cycles.
Edit /etc/fstab to look like this:
# My SSD
UUID=<ВАШ_UUID> / ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
# My SWAP
UUID=<ВАШ_UUID_ДЛЯ_SWAP> none swap sw 0 0
# Memory FS for /tmp and /var/tmp
tmpfs /tmp tmpfs defaults 0 0
tmpfs /var/tmp tmpfs defaults 0 0
You can disable swap altogether with the swapoff command (see also swapon and their parameters; to disable it completely, comment out the swap entry in /etc/fstab), provided, of course, that you have enough RAM. This is the approach I’d recommend: if you’re running out of memory and swap is being used heavily, buy more memory, and keep swap for emergencies only.
You’ll need to reboot to apply the settings.
Now let’s check whether TRIM works
The point of this test is to have TRIM erase data on our drive. To do that, we need to create a file, then delete it and check the data sectors where the file was located.
Create a file:
# cd /
# dd if=/dev/urandom of=testfile count=10 bs=512k oflag=direct
10+0 records in
10+0 records out
5242880 bytes (5.2 MB) copied, 0.885252 s, 5.9 MB/s
# hdparm --fibmap testfile
testfile:
filesystem blocksize 4096, begins at LBA 2048; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 5866496 5876735 10240
Copy begin_LBA and paste it into the following command:
# hdparm --read-sector 5866496 /dev/sdb
/dev/sdb:
reading sector 5866496: succeeded
0c0b a504 8ced cbd8 8f18 f667 694d 3ee0
3516 a8fc e4ae 0859 8cd5 01fe 786e 3f84
569b e0db 6aa1 89c3 e617 8ace 30fd 9a7d
5d2a 51f6 3419 77d8 060f c540 a42b 2219
cecb 2c36 12ec d875 d2ba e86a 4e99 6b89
a84c e40d bf0e aea4 dfcc 72e0 2f46 9200
c449 f8d2 34b5 7018 372c c704 6d49 6cef
8fad ed14 4e39 486c 09e9 8e67 a086 bbad
b229 8d79 0be2 6bef 950e 9089 a95e b633
d1e6 8bca 01dc 0054 7302 9f38 6b93 e09a
7cff 4a08 c017 0a21 6f43 6710 31df 3392
0f8f ed46 4e4b b0d9 5415 9f5e 9d32 fe10
3423 beda bd5a 981b 0fd9 985d 16fe 3b92
79c0 7b8c a220 3bc0 1458 0645 5aa3 5ff9
bd28 8a0d f280 a3ab b3d7 ca05 4d22 312e
43ce 5f3b 9d7b d66b ba35 d257 7be1 6ecd
afc8 205a 36c3 f6e1 743d df89 7373 9a95
7aea 091c 7986 58bc 169c c3dc 794d a613
157e 51ad e5fe e91b a3e1 d40c d0f2 2626
5643 3ec9 006c 68e4 947a bec7 29b4 077e
c79b 9195 fd8f bb06 2cd1 6aad 5ffb 23d9
aefb 52a8 0a55 94e3 4da1 2ce3 06bc 249f
a428 66b1 4530 690f c744 3a23 6237 2043
4759 d5c6 8020 2689 f0fd b046 34f8 8e0d
4c63 e760 0f0b 0264 02cc 8faf f2fa ce82
6e1e 7410 2ee7 f838 99f6 dd73 fccb 4164
3120 35e0 a388 da2c 655d c140 42bd 1569
87ab 9d83 9f75 eb7e e8d1 61ed b24f 0f09
c454 4c35 006d e831 67cd 0161 a6a6 fb25
79db b76c eeb1 21fb a15f 8756 f35b 5ffe
7111 7b58 5453 37f3 32d1 2d92 3f37 b4c5
7982 884b 1c63 8488 0f67 8f5f 2fa5 30ad
Yep, everything looks good: there’s data in the sectors. Now let’s delete the file and see whether TRIM kicks in:
# rm testfile
# sync
# hdparm --read-sector 5866496 /dev/sdb
/dev/sdb:
reading sector 5866496: succeeded
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
If you got all zeros, TRIM is working.
If not, check your fstab and leave a comment—I’ll help.
Setting up grub
Add “elevator=noop” to the file “/etc/default/grub”. This option is needed to disable HDD head parking (which is enabled by default). Since an SSD has no physical need to do this, we’ll disable it:
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash elevator=noop"
For the changes to take effect, run:
$ sudo update-grub
Setting up delayed disk writes
Since I’m not disabling journaling, I need to configure the system to accumulate more data in the buffer and flush it to disk less often. This is better for the laptop’s battery life (since the disk will be idle for a while) and for the lifespan of the SSD itself. Edit “/etc/sysctl.conf” to look like this:
# Включаем режим
vm.laptop_mode = 5
# Устанавливаем таймаут, по истечении которого будут сбросаны данные на диск (6000 == 60 секунд, по умолчанию этот параметр равен 500, т.е. 5 секунд)
vm.dirty_writeback_centisecs = 6000
As far as I understand, “vm.dirty_writeback_centisecs” is the same thing as “commit” in fstab. If I’m wrong, please correct me.
For the changes to take effect, run:
$ sudo sysctl -p
More details on this and much more can be found at Disks and Filesystems / Tips & Tricks / LessWatts.org.
Setting up SWAP
I don’t use this setting myself, for the reasons I’ve already mentioned above, but I’ll include it anyway for the sake of completeness. There is a setting called “vm.swappiness” that specifies a sort of coefficient: if it’s high, swap is used heavily; if it’s low, swap is used rarely. More details here: What Is the Linux Kernel Parameter vm.swappiness?. Edit “/etc/sysctl.conf”:
# По умолчанию этот параметр равен "60"
vm.swappiness = 10
For the changes to take effect, run:
$ sudo sysctl -p
Use zRAM instead of SWAP
I recommend getting rid of disk-based SWAP altogether and using only zRAM for SWAP
Setting up FireFox
To extend the SSD’s life, I decided to disable the browser cache (only on disk; this doesn’t affect the in-memory cache). To do this, go to “about:config” and edit the following options:
browser.cache.disk.enable -> false
browser.cache.disk_cache_ssl -> false
You can view browser cache statistics by going to “about:cache”; you’ll also find the cache locations there, and so on. Two parameters are also available for these statistics:
- “about:cache?device=memory” — a listing for the in-memory cache;
- “about:cache?device=disk” — a listing for the disk cache.
What else is there to read about SSDs?
Comments are closed. Read the original discussion in Russian →
