community.general
community.general copied to clipboard
Remove -f from mkswap
SUMMARY
FIXES #7946
Simply removes the -f flag from the variable MKFS_FORCE_FLAGS variable
ISSUE TYPE
- Feature Pull Request
COMPONENT NAME
filesystem
ADDITIONAL INFORMATION
cc @abulimov @pilou- @quidame click here for bot help
I think this will break the ability to force create a swap file on a system that does not run busybox. So I doubt this is a good way forward. If busybox does not implement -f to force creation, I think it needs to be addressed differently.
@Thulium-Drake This is something I try to clarify in my original issue #7946 , the force option doesn't mean "format anyway" similar to other filesystem utilities force options; the use cases seem exclusively:
- Erasing the first block device
- Requesting a larger swap space than what's available on the device
It's possible to format a swapfile using mkswap /path/to/file source
I apologize in advance if your comment doesn't concern these cases but something else, if that's the case, could you give an example where it's needed to force create a swap file?
When a filesystem is created by this module, regardless of the force module parameter, the force flags switches (-f for the swap partitions) are used (since always).
Should not the force flags be used only when the force module parameter is enabled?
Erasing the first block device
I think that this is the main point of passing -f. The way I understand the mkswap man page, "mkswap will refuse to erase the first block on a device with a partition table" if this option is not supplied. It still succeeds, but prints a warning like
mkswap: foo: warning: don't erase bootbits sectors
(gpt partition table detected). Use -f to force.
(foo is the filename of a 100 MB file I created and created a partition table in with fdisk before calling mkswap foo).
It doesn't seem to care about filesystem signatures (when I ran mkfs.ext2 foo first it only said "mkswap: foo: warning: wiping old ext2 signature." when calling without -f).
Should not the force flags be used only when the
forcemodule parameter is enabled?
I think not. The way I understand the module and its force parameter is that by default, the module checks whether a filesystem already exists, and doesn't overwrite it unless you provide force. The "filesystem already exists" check of the mkfs commands is not really used, and that's why -f is always passed.
Should not the force flags be used only when the
forcemodule parameter is enabled?I think not. The way I understand the module and its
forceparameter is that by default, the module checks whether a filesystem already exists, and doesn't overwrite it unless you provideforce. The "filesystem already exists" check of themkfscommands is not really used, and that's why-fis always passed.
That makes sense :)
Then a fix would be to detect if Busybox is used and if so, remove the -f switch from the Swap.MKFS_FORCE_FLAGS.
Removing "-f" just seems like the better option. The user can supply "-f" in the flags parameter if they wish to erase the first block, but in most cases this is really not needed/wanted. Also it spares some CPU cycles, but that's whatevs :P
If we stick to detecting busybox, is there an already established way of checking this? Or would this need to be implemented?
If we stick to detecting busybox, is there an already established way of checking this? Or would this need to be implemented?
This would need to be implemented, I think. I would add a __init__() function to Swap, similar to VFAT.__init__(), that runs mkswap --version and checks whether its stderr output has a line starting with BusyBox .
Would you say that's the best approach and the way to go?
I'm not sure whether it's the best way forward, but it is one that looks implementable with a not too large amount of effort, and it looks safe in that it doesn't break backwards compatibility.