hello friends! new(ish)!

Storage devices

From InstallGentoo Wiki v2
(Redirected from Hard Drive)
Jump to navigation Jump to search

Here you will find information on the various devices which can store your data.

For data security, Fucko and Encryption might be of use to you.

For securely wiping data, Data Destruction might be of use to you as well.

Primary storage

Hard Disk Drive

A 4TB Seagate Hard Drive

A Hard Disk Drive (often abbreviated HDD) is a data storage device used for storing and retrieving digital information using one or more rigid ("hard") rapidly rotating disks (platters) coated with magnetic material. Invented in 1972 by IBM under the name "Smart Drives", hard drives work by a magnetic head on an acutator arm "inscribing" (or writing) data to the platter. Think of someone writing in a book, where the pen is the magnetic head and the platter is the paper. Data is accessed in a random-access manner, meaning that individual blocks of data can be stored or retrieved in any order rather than sequentially.

Solid State Drive

a 2.5" solid state drive

A Solid State Drive (often abbreviated SSD) is a data storing device that stores data via flash memory as opposed to a hard drive, which uses a physical spinning disc. They can be found in both desktops and laptops. They have recently risen in popularity due to their rapid loading times. However, they are still pretty new, and because of this they are more susceptible to failures and problems than the tried and tested hard drives.

Generally, instead of being used to store all of a user's data, solid state drives are used to store the operating system, while a hard drive is used to store additional data. Files which require frequent loading (e.g. commonly used applications/games) are best suited to an SSD, whereas occasionally accessed files (e.g. your pirated movie collection) will just waste the precious SSD space.

Encryption and sanitization is an issue on SSDs as operating systems can never be certain where their data is being written to. The firmware on SSD drives includes wear levelling, which both extends the life of the drive and abstracts the physical location of any data stored.

Picking an SSD

When shopping for an SSD one must realize that, as the price point goes up, so does the quality of the NAND flash memory, the flash controller and so on, although probably not linearly.

NAND flash memory types
TLC (three-level cell)
  • Typically the lowest performing, with the lowest endurance and reliability;
  • 3-5,000 erase cycles per cell;
  • By far the cheapest.


MLC (multi-level cell)
  • Medium range performance, endurance, and reliability;
  • 10,000 erase cycles per cell;
  • Generally available on medium/high-end consumer grade SSDs as it is only marginally more expensive than TLC.


eMLC (enterprise multi-level cell)
  • Slightly improved version of MLC NAND;
  • 20-30,000 erase cycles per cell.


SLC (single-level cell)
  • Highest performance, cost, endurance, and reliability;
  • 90-100,000 erase cycles;
  • Lowest power consumption.


As far as density goes, it's TLC (3-bits) > MLC = eMLC (2-bits) > SLC (1-bit). The lower the density, the higher the endurance. Similarly, the higher the capacity, the higher the longevity due to an increased amount of cells.

Wear-levelling

Flash controllers manage the data stored on the flash memory by keeping track of the movement of data across segments in order to ensure erasures and re-writes are distributed evenly, preventing any one cell from reaching its write /erase ceiling before the others, which still happens, but it mitigates the issue. Generally speaking, more expensive consumer-grade models tend to have more expensive flash NAND, like MLC, as well as higher quality flash controllers*.

* - Crucial being the exception to the rule, as their SSD lineup ONLY features MLC NAND flash whilst being affordable.

Encryption support

Most SSDs offer builtin hardware encryption—supporting OPAL, the IEEE 1667 spec, SED (self-encrypting drives), and so on, depending on the brand and the SSD. Be careful when picking one based on this, as encryption is hard to implement properly.

Protocol
SATA (III)
  • High compatibility rate;
  • Throughput ceiling of up to 6Gbit/s (which equates to around ~550MB/s maximum);
  • Supports AHCI, which was designed from the ground up for HDDs and therefore causes inefficiencies for SSDs;
  • Small form factor, doesn't require expansion slots;
  • Cheaper, consumer-grade;


PCIe (3.0)
  • Slightly lower compatibility rate due to requiring UP TO (usually 2-4x) PCIe slots;
  • Throughput ceiling is 1970MB/s for 2x, 3940MB/s for 4x, and 7880MB/s for 8x;
  • Supports AHCI and NVMe, thus boosts lower latency than its SATA counterpart for all NVMe drives;
  • Potentially better flash controllers;
  • Might have additional features
  • Require expansion slots;
  • Expensive, enterprise-grade.


SATAe
  • Hybrid connector for PCIe based on the PCIe standard that supports both PCIe 2-3.0 and SATA. Motherboard support was introduced in 2014.
  • SATA drives will benefit from the standard SATA features and PCIe drives will benefit from the standard PCIe features.
Connector
SATA
SATA III: the most common connector for consumer grade desktop SSDs.
mSATA: mSATA follows the SATA spec, offering a theoretical maximum of 550 MB/s. Deprecated by M.2.


PCIe
2-8x: require expansion slots and are ever-so-slightly lower latency by themselves (given two SSDs with the same controller interface, as opposed to NVMe vs AHCI).


SATAe
Physical interface is able to accommodate PCIe, as well as SATA devices.


M.2
M.2 is akin to SATAe, and is the current connector standard for mobile SSDs and supports PCIe, as well as SATA-based SSDs, despite being generally aimed towards PCIe-based SSDs only.
Read the respective product specifications first: if they match PCIe-to-PCIe or SATA-to-SATA, you're good to go.
Controller Interface

AHCI (supported by SATA and PCIe) vs NVMe (only supported by PCIe).

High-level comparison of AHCI and NVMe*
  AHCI NVMe
Maximum queue depth One command queue;
32 commands per queue
65535 queues;
65536 commands per queue
Uncacheable register accesses
(2000 cycles each)
Six per non-queued command;
nine per queued command
Two per command
Message Signaled Interrupts (MSI-X)
and interrupt steering
A single interrupt;
no steering
2048 MSI-X interrupts
Parallelism
and multiple threads
Requires synchronization lock
to issue a command;
Limited support
No locking
Efficiency
for 4 KB commands
Command parameters require
two serialized host DRAM fetches
Gets command parameters
in one 64-byte fetch
Latency
6.0 µs 2.8 µs

* - Most of the credit goes to Wikipedia

Hostcontroller.png

Tweaks

Keep your SSD's firmware up to date. On Linux, check the firmware version by running # hdparm -I /dev/sdx | grep Firmware, where x is your SSD drive.

TRIM

TRIM lets an OS know which SSD blocks are not being used and can be cleared. Not doing this will force the SSD to TRIM the space it wants to write to RIGHT before writing the data, every single time there's a block of non-indexed data (which is what happens when one deletes a file).

Unix-like

To enable TRIM, create a cron job as follows:

# echo -e "#\x21/bin/sh\\nfstrim -v /" | sudo tee /etc/cron.daily/trim
# chmod +x /etc/cron.daily/trim
Windows

To check if TRIM is enabled, simply run fsutil behavior query DisableDeleteNotify—0 means it's enabled, 1 means it's disabled. If it's disabled, run fsutil behavior set DisableDeleteNotify 0 to turn it on.

Hibernation

Disable hibernation as it not only is unstable, it will also result in lots of extra writes to one's SSD.

Cache to RAM

Make most apps cache to RAM. Those that don't support it by default, can be forced to, by using a RAMdisk that copies the cache from disc to RAM, symlinks it, and then copies it back to the main drive every n seconds (Linux's anything-sync-daemon, for instance).

Swap

Disable it completely if you have RAM to spare, depending on your use case. Alternatively, keep it VERY low, as some software can malfunction if it fails to detect a swap partition.

Linux specific
fstab

Use the noatime mount option in /etc/fstab for every ext4 SSD partitions. Noatime is a mount option in Linux which disables atime updates on the file system, save for when they're modified. By adding noatime to your fstab, you greatly reduce SSD load, which translates to longer SSD life and even performance gains. Relatime is fine too (atime is updated once a day or when you modify the file) and less likely to cause issues.


tmpfs

Mount /tmp as tmpfs in /etc/fstab, if your kernel supports it, by issuing none /dev/shm tmpfs defaults 0 0.


sysctl

sysctl is used to modify kernel parameters at runtime. In order to configure it, access /etc/sysctl.conf. To prevent wear, we are going to increase the cache, reduce swappiness, and try to keep things in the OS page cache in memory for longer.

vm.dirty_background_ratio = 10 // percentage of memory pages that still need to be written to disk, keep it somewhat low to prevent heavy disk I/O
vm.dirty_ratio = 60 // the percentage of total system memory to store dirty pages (vm.dirty_ratio will allow kernel to flush dirty data to disk less often with bigger writes, though net size of said writes remains unchanged)
vm.dirty_writeback_centisecs = 500 // is how often the pdflush/flush/kdmflush processes wake up and check to see if work needs to be done
vm.dirty_expire_centisecs = 3000 // how many seconds something can be in cache before it needs to be written
vm.swappiness = 5

The con to keeping things in the OS page cache in memory for longer is that you run an increased risk of data loss/corruption in case of an abrupt loss of power, as RAM is volatile. If you value your data, keep that number low.

Secondary storage

External drives

it's easy as plugging and playing

If you want an external drive for storing or backing up your data, be it an SSD or a mechanical drive, it is actually wise to instead purchase an internal drive and an external case for it. The reason being that most external drives come pre-installed with unneeded bloatware, such as cloud sync software, back-up programs and manuals. External drives may not even function like normal drives, although this is not a common occurrence.

So by purchasing a plain old internal drive instead, you avoid the hassle of dealing with things that you normally shouldn't have to deal with when buying new drives.