Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blkdiscard all unpartitioned space #2804

Open
rdiez opened this issue Feb 24, 2024 · 5 comments
Open

blkdiscard all unpartitioned space #2804

rdiez opened this issue Feb 24, 2024 · 5 comments
Labels
TODO We going to think about it ;-)

Comments

@rdiez
Copy link

rdiez commented Feb 24, 2024

Could you add an option to TRIM all unpartitioned space on a disk?

Some background information is here:

https://unix.stackexchange.com/questions/97143/utility-to-trim-unallocated-space-on-drive

@karelzak
Copy link
Collaborator

blkdiscard provides --offset and --length to address the area to discard and sfdisk --list-free prints unpartitioned areas. All you need is to use it together :-) Yes, it's pretty dangerous.

I'm not sure if we want to link blkdiscard for this purpose. It sounds like an unusual use case.

@rdiez
Copy link
Author

rdiez commented Feb 27, 2024

Linux only automatically trims mounted partitions. If you clone an SSD with Clonezilla, or write an image with dd to an SD card for a Raspberry Pi, any old data not overwritten will never be trimmed. If you delete a partition with gnome-disks or the like, I doubt it would get trimmed. For example, sfdisk can delete partitions, but it does not mention trimming at all. It feels a little silly leaving that opportunity unused. Even creating a partition to cover all empty space will probably not trim it until the global systemd fstrim.timer kicks in, perhaps next week.

If blkdiscard could automatically trim unused space and on demand, I am guessing that many people would use it after running dd or the like. Otherwise, most people won't bother, which would be a shame in terms of performance and/or wear leveling.

You could argue that you should trim the whole disk beforehand, but trim is often only an afterthought when performance suffers, or you may get the disk from somebody else who didn't. Besides, you may only be writing or shrinking one partition.

Do you know of any tool or script to automatically trim unpartitioned space? Even though sfdisk is touted as "script-oriented", it doesn't seem like a 5-minute job.

@karelzak
Copy link
Collaborator

What about adding ---trim to fdisks? It has all the information (offsets & sizes of the areas). We can use it, for example, when you delete a partition or on demand when you create a new partition. Would it make more sense in fdisks?

@rdiez
Copy link
Author

rdiez commented Feb 27, 2024

I don't really mind which tool. I don't have a good overview anyway.

For me, the main thing would be the ability to trim the unpartitioned space. Otherwise, you would have to create and delete partitions just for that purpose, which is a pain, especially if there are holes (several of them).

But trimming deleted or newly-created partitions is a good idea too.

I just realised that this is not just a thing for real disks or even some SD cards: apparently QEMU also honours TRIM commands and releases space in .qcow2 virtual disk files.

@karelzak
Copy link
Collaborator

OK, I'll think about it for the fdisks, including unpartitioned space.

@karelzak karelzak added the TODO We going to think about it ;-) label Feb 28, 2024
karelzak added a commit to karelzak/util-linux-work that referenced this issue Apr 12, 2024
We currently have blkdiscard(8), but it can be difficult to use for
unpartitioned areas or for partitions when working with a whole-disk
device.

This commit adds BLKDISCARD support to fdisk, so that the user does
not have to specify any range, but instead follows the partition
table.

* The new command "T" (trim) allows for discarding sectors on a
  partition.
* The new command "U" (unpartitioned) allows for discarding sectors on
  unused areas.

Addresses: util-linux#2804
Signed-off-by: Karel Zak <[email protected]>
karelzak added a commit to karelzak/util-linux-work that referenced this issue Apr 16, 2024
We currently have blkdiscard(8), but it can be difficult to use for
unpartitioned areas or for partitions when working with a whole-disk
device.

This commit adds BLKDISCARD support to fdisk, so that the user does
not have to specify any range, but instead follows the partition
table.

Addresses: util-linux#2804
Signed-off-by: Karel Zak <[email protected]>
karelzak added a commit to karelzak/util-linux-work that referenced this issue Apr 17, 2024
We currently have blkdiscard(8), but it can be difficult to use for
unpartitioned areas or for partitions when working with a whole-disk
device.

This commit adds BLKDISCARD support to fdisk, so that the user does
not have to specify any range, but instead follows the partition
table.

Addresses: util-linux#2804
Signed-off-by: Karel Zak <[email protected]>
karelzak added a commit to karelzak/util-linux-work that referenced this issue Apr 17, 2024
We currently have blkdiscard(8), but it can be difficult to use for
unpartitioned areas or for partitions when working with a whole-disk
device.

This commit adds BLKDISCARD support to fdisk, so that the user does
not have to specify any range, but instead follows the partition
table.

Addresses: util-linux#2804
Signed-off-by: Karel Zak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO We going to think about it ;-)
Projects
None yet
Development

No branches or pull requests

2 participants