Thomas-Tsai / partclone

Partclone provides utilities to backup a partition smartly and it is designed for higher compatibility of the file system by using existing library.
GNU General Public License v2.0
306 stars 104 forks source link

feature request: btrfs zerofree #225

Open axet opened 1 year ago

axet commented 1 year ago

Hello!

Looking at partclone source code it does the job very well and already has all features for implementing zerofree btrfs utility on top of current source tree.

Can partclone has new option or separate binary for zerofree purpose?

It seems partclone '*bitmap' has used / unused sectors already collected. Only missing zerroing unused sectors option. Implementing option for cleaning unused space would not take much time and can be helpfull for many users / purposes.

EDIT: https://gitlab.com/axet/zerofree-partclone/-/compare/40f45930dff8db08000df3501c27923e70ac4107...master?from_project_id=45986830&straight=false

Thomas-Tsai commented 1 year ago

Thank you for your suggestion. I'm not sure why users need to zero their unused blocks. Could you provide more information on the reason behind this? I also looked into your suggestion of using zerofree and it seems like it can be added to partclone.

As for alternative solutions, one method is for the user to clone the partition and zero all the blocks before restoring it. This will result in a clear, zeroed partition. Another option is to use ddrescue, such as the command 'ddrescue --force -m domainFile /dev/zero /dev/sdX log.txt', where the domain file can be created by partclone.

axet commented 1 year ago

It is like most important feature I was missing in btrfs! Thanks to partclone now it is possible.

Most obvious use case - to reduce image size before create dd of entire drive. You zerofree /dev/sda2 then dd if=/dev/sda | gzip > sda.gz Resulting image will be much smaller and easier to send. For example when you want to report issues with btrfs you may want send not 'btrfs send' but actual HDD image.

Sure you can use clonezilla or partclone with specific partition. But it would be much easier to zerofree a selected partition before gzipping everying.

Another - compacting virtual disk in virtualbox. First stopping virtual machine, then zerofree selected partition. Then run compact on virtual image. This is only been possible for ext4.

https://www.google.com/search?q=zerofree+btrfs

BTW it is already done in my repo. Only one source file changed - zerofree.c and few Makefiles. Please check url I provided.

Thomas-Tsai commented 1 year ago

Because the main function of partclone is backup, using zerofree without backup may potentially damage the file system, which poses a significant risk to users.

Therefore, regarding the requirement for zerofree, after our discussion, we suggest the following:

It can be included as an option for partclone, for example, -Z or --zerofree.
We recommend adding a description of the risks associated with using zerofree.

We would like to hear your suggestions. Thank you.

axet commented 1 year ago

Since partclone is a backup utility better to keep "writing" zerofree as separated binary with different usage screen and options.

Booth utilities relay on proper handling data and potentially will cause serious issues, including data loss. I would not make zerofree any special in that case. If a backup weren't a backup - restoring a backup will cause a data loss.