「ソリッドステートドライブ」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎概要: 削除)
(→‎使用法: 追加)
18行目: 18行目:
   
 
一般的な利用では、自由に[[ファイルシステム]]を選び、[[#TRIM]] を有効化すると良いでしょう。
 
一般的な利用では、自由に[[ファイルシステム]]を選び、[[#TRIM]] を有効化すると良いでしょう。
  +
  +
== 使用法 ==
  +
  +
=== TRIM ===
  +
  +
Most SSDs support the [[wikipedia:ATA_TRIM|ATA_TRIM command]] for sustained long-term performance and wear-leveling. A [https://www.techspot.com/review/737-ocz-vector-150-ssd/page9.html 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:
  +
  +
{| class="wikitable sortable"
  +
! File system !! Continuous TRIM <br> ({{ic|discard}} option) !! Periodic TRIM <br> (''fstrim'') !! References<br> and notes
  +
|-
  +
| [[Btrfs]] || {{Yes}} || {{Yes}} ||
  +
|-
  +
| [[Wikipedia:exFAT|exFAT]] || {{Yes}} || {{Yes}} || ''fstrim'' is supported since kernel 5.13, [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=654762df2ec7d61b05acc788afbffaba52d658fe]
  +
|-
  +
| [[ext3]] || {{Yes}} || {{Yes}} ||
  +
|-
  +
| [[ext4]] || {{Yes}} || {{Yes}} || "discard, nodiscard(*)" in [https://docs.kernel.org/admin-guide/ext4.html?highlight=discard,%20nodiscard(*)#options]
  +
|-
  +
| [[F2FS]] || {{Yes}} || {{Yes}} ||
  +
|-
  +
| [[JFS]] || {{Yes}} || {{Yes}} || [https://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY]
  +
|-
  +
| [[Wikipedia:NILFS|NILFS2]] || {{Yes}} || {{Yes}} ||
  +
|-
  +
| [[NTFS-3G]] || {{No}} || {{Yes}} || since version 2015.3.14, [https://www.mail-archive.com/ntfs-3g-devel@lists.sourceforge.net/msg01093.html]
  +
|-
  +
| [[VFAT]] || {{Yes}} || {{Yes}} || ''fstrim'' is supported since kernel 4.19, [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f663b5b38fffeb31841f8bfaf0ef87a445b0ffee]
  +
|-
  +
| [[XFS]] || {{Yes}} || {{Yes}} || [https://xfs.org/index.php/FITRIM/discard]
  +
|}
  +
  +
{{Warning|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]] {{Pkg|hdparm}} package and run:
  +
  +
{{hc|# hdparm -I /dev/sda {{!}} grep TRIM|
  +
* Data Set Management TRIM supported (limit 1 block)
  +
}}
  +
  +
{{Note|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 {{Pkg|util-linux}} package provides {{ic|fstrim.service}} and {{ic|fstrim.timer}} [[systemd]] unit files. [[Enabling]] the timer will activate the service weekly. The service executes {{man|8|fstrim}} on all mounted filesystems on devices that support the ''discard'' operation.
  +
  +
The timer relies on the timestamp of {{ic|/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 ====
  +
  +
{{Note|There is no need to enable continuous TRIM if you run {{ic|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 {{ic|fstrim.timer}}), it is also possible to issue TRIM commands each time files are deleted instead. The latter is known as the continuous TRIM.
  +
  +
{{Warning|Before [[Wikipedia:Serial ATA#SATA revision 3.1|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 {{ic|ata_device_blacklist}} in [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/libata-core.c 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.}}
  +
  +
{{Note|Continuous TRIM is not the most preferred way to issue TRIM commands among the Linux community. For example, Ubuntu enables periodic TRIM by default [https://askubuntu.com/questions/1034169/is-trim-enabled-on-my-ubuntu-18-04-installation], Debian does not recommend using [[Debian:SSDOptimization#Mounting SSD filesystems|continuous TRIM]] and Red Hat recommends using periodic TRIM over using continuous TRIM if feasible [https://web.archive.org/web/20160917183831/https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Storage_Administration_Guide/ch02s04.html].}}
  +
  +
Using the {{ic|discard}} option for a mount in {{ic|/etc/fstab}} enables continuous TRIM in device operations:
  +
  +
/dev/sda1 / ext4 defaults,'''discard''' 0 1
  +
  +
{{Note|1=Specifying the discard mount option in {{ic|/etc/fstab}} does not work with an XFS {{ic|/}} partition. According to [https://bbs.archlinux.org/viewtopic.php?id=143254 this thread], it has to be set using the {{ic|1=rootflags=discard}} [[kernel parameter]].}}
  +
  +
On the ext4 filesystem, the {{ic|discard}} flag can also be set as a [[Access Control Lists#Enable ACL|default mount option]] using ''tune2fs'':
  +
  +
# tune2fs -o discard /dev/sd'''XY'''
  +
  +
Using the default mount options instead of an entry in {{ic|/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 {{ic|/etc/fstab}} on every machine.
  +
  +
{{Note|The default mount options are not listed in {{ic|/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 [[Solid state drive/Memory cell clearing#Common method with blkdiscard|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 {{man|8|vgcfgrestore}}. The setting {{ic|issue_discards}} in {{ic|/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.
  +
  +
{{Note|Carefully read the comment in {{ic|/etc/lvm/lvm.conf}} before changing the {{ic|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.}}
  +
  +
{{Warning|Enabling {{ic|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 ====
  +
  +
{{Warning|The discard option allows discard requests to be passed through the encrypted block device. This may or may not improve performance on SSD storage [https://lore.kernel.org/linux-raid/508FA2C6.2050800@hesbynett.no/] but has security implications. See the following for more information:
  +
  +
* [[Debian:SSDOptimization#Mounting SSD filesystems]]
  +
* [[dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD)]]
  +
}}
  +
  +
For non-root filesystems, configure {{ic|/etc/crypttab}} to include {{ic|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 [https://www.anandtech.com/show/2738/8 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 [[Solid state drive/Memory cell clearing#SATA drive|#SATA]] or [[Solid state drive/Memory cell clearing#NVMe drive|#NVMe]] SSDs.
  +
  +
{{Note|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" 状態を表示している ====
  +
  +
Some motherboard BIOS' issue a "security freeze" command to SATA devices on initialization. Likewise some SSD (and HDD) BIOS' are set to "security freeze" in the factory already. Both result in the device's password security settings to be set to '''frozen''', as shown in below output:
  +
  +
{{hc|head=# hdparm -I /dev/sda |output=
  +
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.
  +
}}
  +
  +
Operations like formatting the device or installing operating systems are not affected by the "security freeze".
  +
  +
The above output shows the device is '''not locked''' by a HDD-password on boot and the '''frozen''' state safeguards the device against malwares which may try to lock it by setting a password to it at runtime.
  +
  +
If you intend to set a password to a "frozen" device yourself, a motherboard BIOS with support for it is required. A lot of notebooks have support, because it is required for [[Self-encrypting drives|hardware encryption]], but support may not be trivial for a desktop/server board. For the Intel DH67CL/BL motherboard, for example, the motherboard has to be set to "maintenance mode" by a physical jumper to access the settings (see [https://sstahlman.blogspot.in/2014/07/hardware-fde-with-intel-ssd-330-on.html?showComment=1411193181867#c4579383928221016762], [https://communities.intel.com/message/251978#251978]).
  +
  +
{{Warning|Do not try to change the above '''lock''' security settings with {{ic|hdparm}} unless you know exactly what you are doing.}}
  +
  +
If you intend to erase the SSD, see [[Securely wipe disk#hdparm]] and [[/Memory cell clearing]].
  +
  +
===== スリープから復帰したあとに SSD 状態を "frozen" にする =====
  +
  +
When waking up from sleep, the SSD will most likely have lost its "frozen" status, leaving it vulnerable to [https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase ATA SECURE ERASE] commands like those described in [[/Memory cell clearing]].
  +
  +
In order to prevent this issue, a script can be run [[Power management#Hooks in /usr/lib/systemd/system-sleep|after waking up from sleep]]:
  +
  +
{{hc|/usr/lib/systemd/system-sleep/ssd-freeze.sh|2=
  +
#!/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 のパフォーマンスを最大化させるヒント==
 
==SSD のパフォーマンスを最大化させるヒント==

2022年11月8日 (火) 00:20時点における版

関連記事

この記事では、ソリッドステートドライブ (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" 状態を表示している

Some motherboard BIOS' issue a "security freeze" command to SATA devices on initialization. Likewise some SSD (and HDD) BIOS' are set to "security freeze" in the factory already. Both result in the device's password security settings to be set to frozen, as shown in below output:

# 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.

Operations like formatting the device or installing operating systems are not affected by the "security freeze".

The above output shows the device is not locked by a HDD-password on boot and the frozen state safeguards the device against malwares which may try to lock it by setting a password to it at runtime.

If you intend to set a password to a "frozen" device yourself, a motherboard BIOS with support for it is required. A lot of notebooks have support, because it is required for hardware encryption, but support may not be trivial for a desktop/server board. For the Intel DH67CL/BL motherboard, for example, the motherboard has to be set to "maintenance mode" by a physical jumper to access the settings (see [10], [11]).

警告: Do not try to change the above lock security settings with hdparm unless you know exactly what you are doing.

If you intend to erase the SSD, see Securely wipe disk#hdparm and /Memory cell clearing.

スリープから復帰したあとに 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 のパフォーマンスを最大化させるヒント

パーティションアライメント

消去ブロックサイズに揃えたパーティションを使用することを強く推奨します。昔は、パーティション分けをするときに手動で計算して設定する必要がありました。現在では一般的なパーティションツールのほとんどが(最新バージョンを使っていれば)パーティションアライメントを自動的に行います:

  • fdisk
  • gdisk
  • gparted
  • parted

パーティションが調整されているか確認するには、以下のように /usr/bin/blockdev を使って問い合わせて下さい。'0' が返ってくれば、パーティションは揃えられています:

# blockdev --getalignoff /dev/<partition>
0

TRIM

ほとんどの SSD は長期間パフォーマンスを維持するために ATA_TRIM コマンドをサポートしています。ベンチマーク前後などの詳細は、この チュートリアルを見て下さい。

Linux カーネルバージョン 3.8 現在、次のファイルシステムが TRIM をサポートしています: Ext4, Btrfs, JFS, VFAT, XFS, F2FS

ntfs-3g バージョン 2015.3.14 から、NTFS ファイルシステムも TRIM がサポートされています [12]

VFAT はマウントフラグ discard によって TRIM をサポートしています、カーネル4.19以降はfstrimもサポートしています。

この記事のファイルシステムの選択のセクションにさらに詳しく書かれています。

TRIM のサポートを確認する

# hdparm -I /dev/sda |grep TRIM
        *    Data Set Management TRIM supported (limit 1 block)
        *    Deterministic read data after TRIM

"limit 1 block" や "limit 8 block" の意味は、wikipedia:TRIM#ATA を見て下さい。

fstrim で定期的に TRIM を適用する

ノート: この方法は VFAT ファイルシステムでは使えません。

(basebase-devel に含まれている) util-linux パッケージには fstrim.servicefstrim.timersystemd ユニットファイルが入っています。このタイマーを有効化すれば毎週サービスが実行され、discard をサポートしているデバイス上のマウント済みファイルシステム全てが trim されます。

タイマーは最後に実行してから一週間経過したことを知るために (最初に実行したときに作成される) /var/lib/systemd/timers/stamp-fstrim.timer のタイムスタンプを使います。そのため、何度も頻繁に実行される恐れはありません。

journalctlsystemctl status コマンドを使うことでユニットの活動状態を調べることができます:

# journalctl -u fstrim
...
<shows several log entries if enabled>
...
# systemctl status fstrim
● fstrim.service - Discard unused blocks
   Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static; vendor preset: disabled)
   Active: inactive (dead) since lun. 2015-06-08 00:00:18 CEST; 2 days ago
  Process: 18152 ExecStart=/sbin/fstrim -a (code=exited, status=0/SUCCESS)
 Main PID: 18152 (code=exited, status=0/SUCCESS)

juin 08 00:00:16 arch-clevo systemd[1]: Starting Discard unused blocks...
juin 08 00:00:18 arch-clevo systemd[1]: Started Discard unused blocks.
ノート: タイマーを調査したい時は .timer 拡張子を指定するようにしてください。

タイマーの実行間隔を変更したい場合は、ユニットファイルを編集してください。

マウントフラグで TRIM を有効にする

警告: discard フラグを使ってパーティションをマウントする前に SSD が TRIM をサポートしていることを確認してください。そうしないとデータが喪失する可能性があります。残念ながら SSD の TRIM の実行に関する BIOS の品質はバラバラであり、ファイルシステム開発者 Theodore Ts'o は discard マウントフラグの使用を推奨していません 。あなたの使用しているハードウェアについて不安があるのならば、代わりに fstrim で定期的に TRIM を適用するようにしてください。また、TRIM の他の欠点として、TRIM コマンドを実行すると特定のデバイス (特に Samsung 8* シリーズ) で深刻なデータ障害が発生する可能性があります [13]。データの破損が確認された後 [14]、Linux カーネルは多数の デバイス で TRIM コマンドの実行をブラックリスト化しています (2015年7月現在)。

/etc/fstab のエントリで discard オプションを使うことで TRIM コマンドが有効になります:

/dev/sda2  /boot       ext4  defaults,noatime,discard   0  2
/dev/sda1  /boot/efi   vfat  defaults,noatime,discard   0  2
/dev/sda3  /           ext4  defaults,noatime,discard   0  2

TRIM の一番大きな恩恵は速度です。SSD は効率的に ガーベジコレクション を行えるようになります。ただし、効果はモデルによって異なり、初期に製造された SSD の場合、逆効果が現れることもあります。このため、ディストリビューションによっては TRIM を使用しないように決定したところもあります (例えば Ubuntu。この記事関連するブループリント を参照)。

ノート:
  • SSD でブロックデバイス暗号化を使っている場合 TRIM はデフォルトでは有効になりません。詳しくは Dm-crypt/SSD の TRIM のサポートを参照。
  • fstrim を定期的に実行している場合 discard フラグは必要ありません。
  • ext3 の root パーティションで discard フラグを使用すると読み取り専用でマウントされます。

tune2fs で TRIM を有効にする (非推奨)

tune2fs を使って静的に trim フラグを設定することができます:

# tune2fs -o discard /dev/sdXY
警告: この方法を使うと mountdiscard オプションが現れなくなります

LVM で TRIM を有効にする

/etc/lvm/lvm.confissue_discards オプションを有効にしてください。

dm-crypt で TRIM を有効にする

/etc/crypttab を設定して SSD 上の暗号化されたブロックデバイスのオプションのリストに discard を含めて下さい。この discard オプションは discard リクエストが暗号化されたブロックデバイスを通過するのを許可します。これによって SSD ストレージのパフォーマンスは向上しますが、セキュリティに影響があります。このセクションを見て下さい。

I/O スケジューラー

デフォルトの CFQ (Completely Fair Queuing) スケジューラから NOOP または Deadline に切り替えたほうが良いでしょう。後者の2つは SSD のパフォーマンスを加速させます。例えば、NOOP スケジューラは全ての I/O リクエストに対して、ディスクに物理的に近いものを並び替えたりグループ化することなく、一つのシンプルなキューを実行します。SSD においては全てのセクタでシーク時間は同じであり、シーク時間に基づいて I/O キューを並び替える必要性には説得力がありません。

Arch ではデフォルトで CFQ スケジューラが有効にされています。/sys/block/sdX/queue/scheduler の中身を見て確認してください:

$ cat /sys/block/sdX/queue/scheduler
noop deadline [cfq]

表示されているスケジューラの中で角括弧で囲まれているのが現在使われているスケジューラです。

ユーザーは再起動することなくスケジューラを変更することができます:

# echo noop > /sys/block/sdX/queue/scheduler

または:

$ sudo tee /sys/block/sdX/queue/scheduler <<< noop

この方法は永続的ではありません (再起動で変更は失われます)。ファイルの中身をもう一度見て "noop" が使われるようになっていることを確認してください。

カーネルパラメータ (シングルデバイス)

システムの唯一のストレージデバイスが SSD である場合、elevator=noop カーネルパラメータでシステム全体の I/O スケジューラを設定できます。

1つのデバイスまたは HDD/SSD 混合環境で udev を使って設定する

上の方法は確かに動作しますが、あくまで回避策と考えられています。つまり、デバイスのスケジューラを一番最初に実行するシステムを使うのが好ましいでしょう。この場合、それは udev で、設定するのに必要なのはシンプルな udev ルールだけです。

設定するには、以下を作成してください:

/etc/udev/rules.d/60-schedulers.rules
# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"

Deadline/CFQ をお望みのスケジューラに設定してください。次に起動した時に変更が適用されるはずです。新しいルールが適用されているか確認するには:

$ cat /sys/block/sdX/queue/scheduler  # where X is the device in question
ノート: 上記の例で udev ルールの名前に60を使っていますが、終わりが .rules であればどんな名前でも付けられます。

SSD のスワップ領域

SSD 上にスワップパーティションを配置することが可能です。最新のデスクトップではメモリが2ギガ以上積まれておりスワップはほとんど使いません。ただしハイバネート機能を利用するシステムの場合は別です。以下のようにシステムの "swappiness" を減らすことで SSD にあるスワップへの書き込みを減らすことが推奨されます:

# echo 1 > /proc/sys/vm/swappiness

パフォーマンスの最大化の記事で推奨されているように行うこともできます:

/etc/sysctl.d/99-sysctl.conf
vm.swappiness=1
vm.vfs_cache_pressure=50

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

マザーボードの BIOS は初期化時に取り付けられたストレージデバイスに "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 パスワードによってロックされていないこと、そして凍結状態によってデバイスを (パスワードを設定してデバイスをロックさせてしまうような) マルウェアから保護していることがわかります。

凍結状態のデバイスにパスワードを設定したい場合、それに対応しているマザーボード BIOS が必要です。ハードウェア暗号化に必須なので、ノートパソコンでは大抵サポートされていますが、デスクトップやサーバーのボードではサポートがあるかどうかはっきりしないことがあります。例えば、Intel DH67CL/BL マザーボードの場合、設定にアクセスするには物理的なジャンパによってマザーボードを "maintenance mode" に設定する必要があります ([15], [16] を参照)。

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

SSD を消去するときは、ディスクの完全消去#hdparm下のセクションを見て下さい。

SSD Memory Cell Clearing

時々、SSD のセルを完全にリセットしてデバイスにインストールした時と同じ初めの状態にすることで 製造時の書き込みパフォーマンス を取り戻したいと思うことがあるかもしれません。SSD の書き込みパフォーマンスはネイティブの TRIM サポートを使っていても時間経過で落ちていきます。TRIM はファイル削除に対するセーフガードとして働くだけで、増加保存などの代わりにはなりません。

リセットは SSD メモリセルの消去の wiki 記事に書かれている3つのステップで簡単に行なえます。何らかの理由で SSD の BIOS を使わずにディスクのデータを消去したい場合はディスクの完全消去#フラッシュメモリを読んでください。

トラブルシューティング

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 で起動してファームウェアをアップデートしてください。

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

参照