我有一个带有几个ext4分区的驱动器(SD卡),但是还有一些未分配的空间。该fstrim
实用程序只能在文件系统内工作。在我重新发明轮子并写一个轮子之前,是否有另一个实用程序可以对未分配的空间进行修剪(或者可以对明确指定的范围进行修剪)?
我可以确认的是,大部分的设备上未分配的空间是不是目前已知的控制器是免费的,因为我观察到,这种特殊的卡上,读取到修剪空间返回0的,但该设备显示的扫描剩下大量垃圾数据。
编辑:我在使用时遇到问题hdparm
。下面的示例舍弃了第一个扇区,但是无论我指定的范围如何,我都会看到相同的结果。fstrim
设备上没有任何问题:
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
我正在进一步调查,但是有人有见识吗?
blkdiscard
在我的标准软件包存储库中似乎不可用(Ubuntu 12.04,似乎没有在中提供util-linux
)。
hdparm
由于某种原因,我一直无法为我工作,但是我从github.com/karelzak/util-linux/tree/stable/v2.23抓取了util-linux源,构建了它(./autogen.sh ; ./configure ; make blkdiscard
),并且运行良好。仍然是个谜,hdparm
但blkdiscard
确实是我想要的。附:无需先创建一个临时文件系统,您可以sfdisk -l
用来找出分区之间的空间并进行blkdiscard
修剪。
blkdiscard
至不知道能够使用offset / length选项。因此,我建议的临时分区甚至不是必需的。真好!
blkdiscard
在其上使用以修剪整个设备。