Filesystems – How fstrim Interacts with dd

ddfilesystemsfstrim

I'd like to understand the interaction between fstrim and a file system driver (such as ext4). More precisely I'd like to understand whether dd interfere with this.

I've queried elsewhere about how the file system informs an SSD when a block is not used. This is important because it can help with wear levelling. This was my earlier question

When a partition is copied with dd or equivalent, every byte of every block gets copied regardless of whether it's used by the file system. Besides being slower on mostly empty file systems, this also tells the disk to store data in unused areas of the file system.

Will fstrim recover from this or is it incremental, only discarding after a file is deleted?

(Meta question) Is it now recommended that users call fstrim or similar after using dd to copy a disk?

Best Answer

Will fstrim recover from this or is it incremental, only discarding after a file is deleted?

It will recover from this, it discards all unused blocks. It doesn’t care about when the blocks became unused.

Is it now recommended that users call fstrim or similar after using dd to copy a disk?

Doing so will only add one trimming “instance” to the drive’s history, so it shouldn’t have any adverse consequences. Put another way, if it’s OK to run fstrim once a week, running it twice in one week after copying a volume isn’t going to make much difference over the drive’s lifetime. I don’t know whether it’s recommended.

I would recommend using a file system-aware tool instead, for example e2image for ext4 file systems; it won’t copy unused blocks when creating the image, and will even avoid writing blocks if their contents are identical to what’s already on the target.

Related Question