ソリッドステートドライブ

提供: ArchWiki
2022年11月8日 (火) 00:37時点におけるAshMyzk (トーク | 投稿記録)による版 (→‎継続的な TRIM: セクション名を変更)
ナビゲーションに移動 検索に移動

関連記事

この記事では、ソリッドステートドライブ (SSD) や他のフラッシュメモリベースのストレージデバイスの取り扱いに関するトピックをカバーしています。

特定の目的のために SSD をパーティショニングしたい場合、フラッシュメモリ向けに最適化されたファイルシステムのリストで検討すると良いかもしれません。

一般的な利用では、自由にファイルシステムを選び、#TRIM を有効化すると良いでしょう。

使用法

TRIM

Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling. A TechSpot article shows performance benchmark examples of before and after filling an SSD with data.

As of Linux kernel version 3.8 onwards, support for TRIM was continually added for the different filesystems. See the following table for an indicative overview:

File system Continuous TRIM
(discard option)
Periodic TRIM
(fstrim)
References
and notes
Btrfs Yes Yes
exFAT Yes Yes fstrim is supported since kernel 5.13, [1]
ext3 Yes Yes
ext4 Yes Yes "discard, nodiscard(*)" in [2]
F2FS Yes Yes
JFS Yes Yes [3]
NILFS2 Yes Yes
NTFS-3G No Yes since version 2015.3.14, [4]
VFAT Yes Yes fstrim is supported since kernel 4.19, [5]
XFS Yes Yes [6]
警告: Users need to be certain that their SSD supports TRIM before attempting to use it. Data loss can occur otherwise!

To verify TRIM support, run:

$ lsblk --discard

And check the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns. Non-zero values indicate TRIM support.

Alternatively, install hdparm package and run:

# hdparm -I /dev/sda | grep TRIM
        *    Data Set Management TRIM supported (limit 1 block)
ノート: There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See Wikipedia:Trim (computing)#ATA for more information.

定期的な TRIM

The util-linux package provides fstrim.service and fstrim.timer systemd unit files. Enabling the timer will activate the service weekly. The service executes fstrim(8) on all mounted filesystems on devices that support the discard operation.

The timer relies on the timestamp of /var/lib/systemd/timers/stamp-fstrim.timer (which it will create upon first invocation) to know whether a week has elapsed since it last ran. Therefore there is no need to worry about too frequent invocations, in an anacron-like fashion.

To query the units activity and status, see journalctl. To change the periodicity of the timer or the command run, edit the provided unit files.

連続的な TRIM

ノート: There is no need to enable continuous TRIM if you run fstrim periodically. If you want to use TRIM, use either periodic TRIM or continuous TRIM.

Instead of issuing TRIM commands once in a while (by default once a week if using fstrim.timer), it is also possible to issue TRIM commands each time files are deleted instead. The latter is known as the continuous TRIM.

警告: Before SATA 3.1 all TRIM commands were non-queued, so continuous trimming would produce frequent system freezes. In this case, applying #Periodic TRIM less often is better alternative. Similar issue holds also for a number of devices, see ata_device_blacklist in Linux source code, for which queued TRIM command execution was blacklisted due to serious data corruption. In such case, depending on the device, the system may be forced to send non-queued TRIM commands the SSD instead of queued TRIM. See Wikipedia:Trim_(computing)#Disadvantages for details.
ノート: Continuous TRIM is not the most preferred way to issue TRIM commands among the Linux community. For example, Ubuntu enables periodic TRIM by default [7], Debian does not recommend using continuous TRIM and Red Hat recommends using periodic TRIM over using continuous TRIM if feasible [8].

Using the discard option for a mount in /etc/fstab enables continuous TRIM in device operations:

/dev/sda1  /           ext4  defaults,discard   0  1
ノート: Specifying the discard mount option in /etc/fstab does not work with an XFS / partition. According to this thread, it has to be set using the rootflags=discard kernel parameter.

On the ext4 filesystem, the discard flag can also be set as a default mount option using tune2fs:

# tune2fs -o discard /dev/sdXY

Using the default mount options instead of an entry in /etc/fstab is particularly useful for external drives, because such partition will be mounted with the default options also on other machines. This way, there is no need to edit /etc/fstab on every machine.

ノート: The default mount options are not listed in /proc/mounts.

デバイス全体を trim する

If you want to trim your entire SSD at once, e.g. for a new install or if you want to sell the drive, you can use the blkdiscard command.

LVM

TRIM requests that get passed from the file system to the logical volume are automatically passed to the physical volume(s). No additional configuration is necessary.

No LVM operations (lvremove, lvreduce and all others) issue TRIM requests to physical volume(s) by default. This is done to allow restoring previous volume group configuration with vgcfgrestore(8). The setting issue_discards in /etc/lvm/lvm.conf controls whether discards are sent to a logical volume's underlying physical volumes when the logical volume is no longer using the physical volumes' space.

ノート: Carefully read the comment in /etc/lvm/lvm.conf before changing the issue_discards setting. It does not in any way affect TRIM requests that get passed from the file system to the disk (e.g. file deletions inside a file system) nor does it affect space management within a thin pool.
警告: Enabling issue_discards will prevent volume group metadata restoration with vgcfgrestore. There will be no recovery options in case of a mistakenly issued LVM command.

dm-crypt

警告: The discard option allows discard requests to be passed through the encrypted block device. This may or may not improve performance on SSD storage [9] but has security implications. See the following for more information:

For non-root filesystems, configure /etc/crypttab to include discard in the list of options for encrypted block devices located on an SSD (see dm-crypt/System configuration#crypttab).

For the root filesystem, follow the instructions from dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD) to add the right kernel parameter to the bootloader configuration.

パフォーマンスを最大化する

Follow the tips in Improving performance#Storage devices to maximize the performance of your drives.

セクタサイズ

See Advanced Format#Solid state drives.

SSD のメモリセルのクリア

On occasion, users may wish to completely reset an SSD's cells to the same virgin state they were at the time the device was installed, thus restoring it to its factory default write performance. Write performance is known to degrade over time even on SSDs with native TRIM support: TRIM only safeguards against file deletes, not replacements such as an incremental save.

The reset can be accomplished by following the appropriate procedure denoted in SSD memory cell clearing, either for #SATA or #NVMe SSDs.

ノート: If the reason for the reset is to wipe data, you may not want to rely on the SSD controller to perform it securely, e.g. if you do not trust the manufacturer or are wary of potential bugs. In this case, see Securely wipe disk#Flash memory for further information and examples to perform a manual wipe.

セキュリティ

Hdparm で "frozen" 状態と表示される

一部のマザーボードの BIOS は、初期化時に SATA デバイスに対して "security freeze" コマンドを発行します。同様に、一部の SSD (や HDD) の BIOS は、工場出荷時にすでに "security freeze" に設定されています。どちらにしても、以下の出力のように、デバイスのパスワードセキュリティ設定が frozen になります:

# hdparm -I /dev/sda
Security: 
 	Master password revision code = 65534
 		supported
 	not	enabled
 	not	locked
 		frozen
 	not	expired: security count
 		supported: enhanced erase
 	4min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.

デバイスのフォーマットやオペレーティングシステムのインストールといった操作は、"security freeze" の影響を受けません。

上記の出力は、デバイスが起動時に HDD パスワードによってロックされていないこと、そして frozen 状態によってデバイスを (実行時にパスワードを設定してデバイスをロックさせてしまうような) マルウェアから保護していることを示しています。

"frozen" 状態のデバイスにパスワードを設定したい場合、それに対応しているマザーボード BIOS が必要です。ハードウェア暗号化に必要なので、多くのノートパソコンでサポートされていますが、デスクトップやサーバーのボードではサポートがあるかどうかはっきりしないことがあります。

例えば、Intel DH67CL/BL マザーボードの場合、設定にアクセスするには物理的なジャンパによってマザーボードを "maintenance mode" に設定する必要があります ([10], [11] を参照)。

警告: よくわからないときは hdparm を使って上記のロックセキュリティ設定を変更しないで下さい。

SSD を消去するときは、ディスクの完全消去#hdparmソリッドステートドライブ/メモリセルの消去 を見て下さい。

スリープから復帰したあとに SSD 状態を "frozen" にする

When waking up from sleep, the SSD will most likely have lost its "frozen" status, leaving it vulnerable to ATA SECURE ERASE commands like those described in /Memory cell clearing.

In order to prevent this issue, a script can be run after waking up from sleep:

/usr/lib/systemd/system-sleep/ssd-freeze.sh
#!/bin/sh
if [ "$1" = 'post' ]; then
	sleep 1
	if hdparm --security-freeze /dev/disk/by-id/ata-name-of-disk; then
		logger "$0: SSD freeze command executed successfully"
	else
		logger "$0: SSD freeze command failed"
	fi	
fi

ハードウェア暗号化

As noted in #Hdparm shows "frozen" state setting a password for a storage device (SSD/HDD) in the BIOS may also initialize the hardware encryption of devices supporting it. If the device also conforms to the OPAL standard, this may also be achieved without a respective BIOS feature to set the passphrase, see Self-encrypting drives.

トラブルシューティング

SSD の問題は Linux 固有の問題ではないファームウェアのバグである可能性も存在します。SSD に関しては、問題のトラブルシューティングを始める前に、ファームウェアのアップデートが存在しないか確認してみてください:

ファームウェアのバグであったとしても、解決できることがあります。ファームウェアにアップデートが存在しなかったり、ファームウェアのアップデートをしたくない場合、以下のセクションを見て下さい。

NCQ エラーを解消する

SSD や SATA チップセットによっては Linux Native Command Queueing (NCQ) が正しく動作しないことがあります。dmesg に以下のようなエラーが表示されます:

[ 9.115544] ata9: exception Emask 0x0 SAct 0xf SErr 0x0 action 0x10 frozen
[ 9.115550] ata9.00: failed command: READ FPDMA QUEUED
[ 9.115556] ata9.00: cmd 60/04:00:d4:82:85/00:00:1f:00:00/40 tag 0 ncq 2048 in
[ 9.115557] res 40/00:18:d3:82:85/00:00:1f:00:00/40 Emask 0x4 (timeout)

起動時に NCQ を無効にするには、ブートローダーの設定におけるカーネルコマンドラインに libata.force=noncq を追加してください。ポート 1 のディスク 0 の NCQ だけを無効化するには次を使用: libata.force=1.00:noncq

また、sysfs を使うことで再起動せずに特定のドライブの NCQ を無効化することもできます:

# echo 1 > /sys/block/sdX/device/queue_depth

問題が解決しなかったり他の問題が発生する場合は、バグレポートを作成してください。

SATA の電源管理関連のエラーを解消する

SATA Active Link Power Management (ALPM) が有効になっている場合にエラーを吐く SSD も存在します (例: Transcend MTS400)。ALPM はデフォルトで無効になっており、省電力デーモンによって有効になります (例: TLP, Laptop Mode Tools)。

省電力デーモンを使っていて SATA 関連のエラーが表示される場合、バッテリーと AC 電源のプロファイルを max_performance に設定して ALPM を無効化してみてください。

ファームウェア

ADATA

ADATA は Linux (i686) で利用できるユーティリティを、ここ にある彼らのサポートページに用意しています。モデルを選択すれば最新のファームウェアへのリンクが表示されます。

最新の Linux アップデートユーティリティはファームウェアと一緒に入っており root で実行してください。最初にバイナリファイルに対して適切なパーミッションを設定する必要があるかもしれません。

Crucial

Crucial は ISO イメージを使ってファームウェアをアップデートする方法を提供しています。ここ から製品を選んで "Manual Boot File" をダウンロードすることでイメージを入手できます。

ノート: Crucial が提供している ISO イメージはハイブリッドではありません。dd コマンドを使ってイメージを MBR が存在しないデバイスにコピーした場合、デバイスが起動できなくなります。

M4 Crucial モデルを使っている場合、smartctl でファームウェアのアップグレードが必要かどうかチェックすることが可能です:

$ smartctl --all /dev/sdX
==> WARNING: This drive may hang after 5184 hours of power-on time:
http://www.tomshardware.com/news/Crucial-m4-Firmware-BSOD,14544.html
See the following web pages for firmware updates:
http://www.crucial.com/support/firmware.aspx
http://www.micron.com/products/solid-state-storage/client-ssd#software

上記のような警告が表示された場合は重要なデータをバックアップしてから直ちにアップグレードを行うことが推奨されます。ISO イメージと Grub を使用して Crucial MX100 のファームウェアをアップデートする手順は こちら を参照してください。

Intel

Intel は Intel® Solid-State Drive Toolbox ソフトウェアが対応していないオペレーティングシステム向けに、Linux ライブシステムベースの Firmware Update Tool を用意しています。

Kingston

Kingston は Sandforce コントローラを搭載しているドライブのファームウェアをアップデートする Linux ユーティリティを用意しています。Kingston の SSD のサポートページ で見つけることができます。使用している SSD のモデルにあわせてページを開いてください。例えば SH100S3 SSD のサポートは HyperX のサポートページ です。

Mushkin

マイナーな Mushkin ブランドのソリッドステートドライブも Sandforce コントローラーを使っており、ファームウェアをアップデートする Linux ユーティリティ (Kingston のものとほとんど同じ) が存在します。

OCZ

OCZ は Linux 用の Command Line Online Update Tool (CLOUT) を用意しています。ocz-ssd-utilityAUR, ocztoolboxAUR, oczcloutAUR パッケージでインストールすることができます。

Samsung

Samsung は Magician Software 以外の方法によるアップデートを"サポートしない"としていますが、不可能ではありません。Magician Software を使ってファームウェアのアップデートを起動する USB ドライブを作成することができるようですが、一番簡単な方法はファームウェアのアップデート用のブータブル ISO イメージを使用することです。イメージは ここ から入手することが可能です。また、samsung_magicianAUR[リンク切れ: パッケージが存在しません] パッケージでインストールすることができます。Magician がサポートしているのは Samsung ブランドの SSD だけです。OEM 供給されている Samsung 製の SSD はサポートされていません (Lenovo 向けの SSD など)。

ノート: Samsung はファームウェアアップデートをわかりやすく提供していません。ファームウェアアップデートに関連するページが4つあり、それぞれで別々の方法が示されています。

(Microsoft Windows で Samsung の "Magician" ソフトウェアを使わずに) Linux で作成したライブ USB スティックからファームウェアアップデートを実行したい場合は、この記事 を参照してください。

SanDisk

SanDisk は SanDisk SSD Toolkit でサポートされていないオペレーティングシステムにおいて SSD のファームウェアアップデートをするための ISO ファームウェアイメージを作成しています。SSD のモデルだけでなく、SSD の容量にあわせて適切なファームウェアを選択する必要があります (例: 60GB または 256GB)。適当な ISO ファームウェアイメージを焼いたら、PC を再起動して新しく作成した CD/DVD ブートディスクで起動してください (USB スティックからでも動作するかもしれません)。

ISO イメージには Linux カーネルと initrd が含まれています。それらを /boot パーティションに展開して GRUBSyslinux で起動してファームウェアをアップデートしてください。

ファームウェアのアップデートが列挙された一つのページは存在しませんが (サイトがわかりづらい)、以下が関連するリンクです:

参照