Skip to contentSkip to conversation

mkfs command in grub

DISCUSSION [email protected] 2 participants 2 messages Mar 13, 2006 – Mar 28, 2006

lore
Share & tools
lore
#0 lore raw

Tomáš, unfortunately your solution to the swap sharing problem is suboptimal -- swapping through filesystem code to a file in a VFAT filesystem will quite likely be a order of magnitude slower than raw partition access. It's OK if you are a casual Linux user, but not acceptable if you are a casual Windows user like me :).

Okuji, it's a matter of theoretical purism vs pragmatical problem solving. As Marco already said, we can't change the behaviour of non-free software. Hence we need to manipulate the swap partition before booting Windows in this particular (and very common) use-case. Preparing the swap partition for Windows is possible from a Linux shutdown script, but this solution is fragile (one can imagine plenty of cases when the script will not be run), and is not really Linux's responsibility (preparing a partition for another OS). Which brings us back to the fact that in this particular case it is the bootloader's responsibility. I agree that this functionality should not be part of the core, but as GRUB 2 is supposedly modular (haven't seen the code though), it should be available as a module.

Could someone who knows the code please envisage what should be done in order to implement the mkfs module?

#1 lore raw
Quoted 2 lines · [email protected] writes:

Could someone who knows the code please envisage what should be done in order to implement the mkfs module?

First of all, I would not call the command mkfs. Better just restrict the functionality to swap, that can give you some assertions to begin with.

First just have a look at the hello command and how it is implemented. Have a look at hello.c, for example. After that, study some of the more fancy commands and how to read from and write to disk.

I think you can make a simple command like:

mkswap
--linux-swap
--fat

And an argument for the disk, so you can have:
mkswap --linux-swap (hd0,2)
or:
mkswap --fat (hd0,2)

I think creating the swap filesystem is rather trivial. For linux swap it might be just a single block you have to write. For fat it is just a few and this might be less trivial.

By assuming it is just used for swap, you can make sure mkswap can not erase the wrong partition. It happens that some BIOSes swap disk numbers, you certainly do not want to erase data from the wrong disk. So I think you can better check if it is a swap partition you are erasing. So either one of these two checks have to be true:

- The partition is linux swap.
- The partition is fat and has a certain label ("swap", for example).

I have no idea if this will work. For example, you might have to change the partition type too.

Besides all this, this is not a guarantee that if you implement such feature, it will make it into GRUB. But I am certainly willing to answer your questions.

--
Marco