What happens to a filesystem upon a quick format on an SSD?

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
TD15

What happens to a filesystem upon a quick format on an SSD?

Post by TD15 »

What would happen to a filesystem upon using quick format on the previous one?
I have an SSD, say for example I completely delete the windows partition and merge it with my linux partition, what would happen to the data that the NTFS filesystem was pointing to? Given that the ext4 partition has no reference to that data, will it be able to TRIM the old data or it will stay lingering until an overwrite occurs?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: What happens to a filesystem upon a quick format on an SSD?

Post by rene »

A quick format in the sense of mkfs of an ext4 filesystem would in fact by default trim immediately; see man mke2fs, the -E discard option description. However, you have nothing to worry about anyway even if it would not; what fstrim (set up by default weekly in Ubuntu/Mint) does is trim the space that the filesystem finds to not be in use: even if the format wouldn't have trimmed things already certainly what it does quite by design is reset all filesystem structures pointing to any old data, meaning that the first regular fstrim discards them at that level; nothing "stays lingering".
TD15

Re: What happens to a filesystem upon a quick format on an SSD?

Post by TD15 »

rene wrote: Sat Jun 19, 2021 10:10 am nothing "stays lingering".
It seems that windows behaves differently in this scenario. I used a recovery tool and found lingering files on my windows partition from almost a year, and trimming does nothing to them (These are likely the remains of a previous windows installation). I want to get rid of them because soon I will be done with windows and will delete its partition and extend the mint one.

Will a full format overwrite this mess caused by windows?
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: What happens to a filesystem upon a quick format on an SSD?

Post by rene »

The first fstrim after said extend will grab them so frankly it seems you'd need to do exactly nothing even I'd take as given that a Windows-sides TRIM would leave blocks not invalidated (which I don't really but oh well).

A nonquick format, i.e., one that overwrites, is only guaranteed to be effective if you overwrite the entire drive: an SSD's logical sector map is a mere software construct with the SSD deciding which physical block some given logical one points to at any given time, and specifically due to the SSD then not needing to slow-erase a block before it writes new data to "that same block": it just maps an already erased block in its place and writes to that.

Anycase, first sentence above seems most relevant, but overwriting all free space on the entire drive certainly works. You can do this also with e.g.

Code: Select all

sudo dd if=/dev/zero of=/where/ever/zero bs=1M
to overwrite all free space on the filesystem mounted on /where/ever/ with zeroes. Remove the "zero" files only after all filesystems on that same drive have been filled in that manner, again due to the above.
TD15

Re: What happens to a filesystem upon a quick format on an SSD?

Post by TD15 »

rene wrote: Sat Jun 19, 2021 11:19 am The first fstrim after said extend will grab them so frankly it seems you'd need to do exactly nothing even I'd take as given that a Windows-sides TRIM would leave blocks not invalidated (which I don't really but oh well).
I think this is just a side effect of some files staying after reinstalling windows which destroyed old filesystem and left some files with no reference to be trimmed. Some of these files was partially overwritten according to the tool.

If fstrim will grab the loose files and trim them then thats great!
One more question: Can fstrim TRIM a windows partition?
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: What happens to a filesystem upon a quick format on an SSD?

Post by rene »

Well, that's the point then more or less; fstrim does not trim "them", does not trim files but trims free space, trims "nonfiles" if you will. As such all that's needed for fstrim to tell the SSD firmware that some logical blocks are unused are for said blocks to not be part of a file or some filesystem-structure according to that filesystem.

This would be not different on Windows either and moreover, while TRIM itself would not (necessarily) cause an erase of a physical block or at the very least not immediately certainly it should cause further reads from that physical block to no longer retrieve the former data due to it having been marked invalid, so frankly I'm having trouble piecing together a situation where TRIM reportedly didn't.

Anycase. Yes, first run of e.g. fstrim -av after you have expanded your Linux filesystem to include the space formerly occupied by the Windows filesystem is going to cause all not actively used space on said expanded Linux filesystem to be trimmed; to be marked free, and as such nothing from that former Windows filesystem should after that be able to be retrieved on a normal, software level; it'll all be gone.

As to your specific question (which I saw only a little later); yes, as far as I can see NTFS-3G (which is on Ubuntu/Mint used as the NTFS filesystem "driver") supports fstrim since NTFS-3G 2015.3.14, apparently since Ubuntu 16.04/Mint 18.
TD15

Re: What happens to a filesystem upon a quick format on an SSD?

Post by TD15 »

rene wrote: Sat Jun 19, 2021 1:19 pm Well, that's the point then more or less; fstrim does not trim "them", does not trim files but trims free space, trims "nonfiles" if you will. As such all that's needed for fstrim to tell the SSD firmware that some logical blocks are unused are for said blocks to not be part of a file or some filesystem-structure according to that filesystem.

This would be not different on Windows either and moreover, while TRIM itself would not (necessarily) cause an erase of a physical block or at the very least not immediately certainly it should cause further reads from that physical block to no longer retrieve the former data due to it having been marked invalid, so frankly I'm having trouble piecing together a situation where TRIM reportedly didn't.

Anycase. Yes, first run of e.g. fstrim -av after you have expanded your Linux filesystem to include the space formerly occupied by the Windows filesystem is going to cause all not actively used space on said expanded Linux filesystem to be trimmed; to be marked free, and as such nothing from that former Windows filesystem should after that be able to be retrieved on a normal, software level; it'll all be gone.

As to your specific question (which I saw only a little later); yes, as far as I can see NTFS-3G (which is on Ubuntu/Mint used as the NTFS filesystem "driver") supports fstrim since NTFS-3G 2015.3.14, apparently since Ubuntu 16.04/Mint 18.
Thanks for your time and valuable information!
Locked

Return to “Storage”