community.general icon indicating copy to clipboard operation
community.general copied to clipboard

Remove -f from mkswap

Open GustavoPeredo opened this issue 1 year ago • 11 comments

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

GustavoPeredo avatar Feb 05 '24 17:02 GustavoPeredo

cc @abulimov @pilou- @quidame click here for bot help

ansibullbot avatar Feb 05 '24 17:02 ansibullbot

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 avatar Feb 08 '24 11:02 Thulium-Drake

@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?

GustavoPeredo avatar Feb 10 '24 12:02 GustavoPeredo

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?

pilou- avatar Feb 10 '24 15:02 pilou-

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 force module 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.

felixfontein avatar Feb 11 '24 11:02 felixfontein

Should not the force flags be used only when the force module 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.

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.

pilou- avatar Feb 11 '24 18:02 pilou-

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?

GustavoPeredo avatar Feb 12 '24 11:02 GustavoPeredo

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 .

felixfontein avatar Feb 13 '24 21:02 felixfontein

Would you say that's the best approach and the way to go?

GustavoPeredo avatar Feb 16 '24 04:02 GustavoPeredo

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.

felixfontein avatar Feb 17 '24 11:02 felixfontein