I have a drive (SD card) with a few ext4 partitions but also some unallocated space. The fstrim
utility can only work within a filesystem. Before I reinvent the wheel and write one, is there another utility that can TRIM the unallocated space (or that can TRIM an explicitly specified range)?
I can verify that the majority of the unallocated space on the device is not currently known to be free by the controller, as I've observed that, on this particular card, reads to trimmed space return 0's, but a scan of the device shows plenty of garbage data left over.
Edit: I am having an issue using hdparm
. The example below discards the first sector, but I am seeing the same results regardless of the range I specify. fstrim
has no issues on the device:
root@ubuntu:~# hdparm --please-destroy-my-drive --trim-sector-ranges 0:1 --verbose /dev/mmcblk0
/dev/mmcblk0:
trimming 1 sectors from 1 ranges
outgoing cdb: 85 0d 06 00 01 00 01 00 00 00 00 00 00 40 06 00
outgoing_data:
00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ioctl(fd,SG_IO): Invalid argument
FAILED: Invalid argument
I am investigating further but does anybody have any insight?
blkdiscard
on them which trims the entire device.blkdiscard
does not seem to be available in my standard package repositories (Ubuntu 12.04, doesn't seem to be present inutil-linux
).hdparm
working for me for some reason, but I grabbed the util-linux source from github.com/karelzak/util-linux/tree/stable/v2.23, built it (./autogen.sh ; ./configure ; make blkdiscard
) and it's working great. Still mystified abouthdparm
butblkdiscard
does exactly what I want. Bonus: There's no need to make a temporary filesystem first, you can usesfdisk -l
to figure out the space between partitions and haveblkdiscard
trim it.blkdiscard
being able to work with offset/length options. So the temporary partitions I suggested aren't even necessary. Nice!