When we make a swap using a regular physical drive, we just use fdisk and make a partition with type swap, using the swap code for that partition, followed by mkswap and swapon commands.

But what if, in the case of lvm, we have to specify the partition type to be lvm using the lvm code, and then just make a pv, vg and lv, and then mkswap on that partition followed by swapon (please correct me if I am wrong).

So my question is: why we don't need the partition to be of type swap in the lvm case; what is the logic behind this?

  • 1
    Because, you are creating a logical volume (LV) not a partition on a physical drive. These are two different concepts when it comes to storage and do not follow the same procedure at the low level operations. – MelBurslan Apr 12 '16 at 13:34
  • So you mean that lvm handles or encapsulates that swap partition type thing in itself? – Ijaz Ahmad Khan Apr 12 '16 at 13:36
  • 1
    In a round-about way of saying YES. But it actually doesn't need to do anything as swap partition only needs a raw volume, which what a logical volume is. During fdisk operation, by telling the program that this will be a swap partition, you are actually making the partition a raw volume (by modifying partition headers). – MelBurslan Apr 12 '16 at 13:42

Linux pretty much ignores partition types, it cares more about the content on those partitions. So you don't need a swap partition type to use swap in Linux, and thus there is no issue with LVM not having partition types either.

But you have to use the correct partition type to stop Windows from attempting to format your Linux data/swap partitions... it's also useful for humans to be able to tell what's what when just looking at the partition table.

  • Ok , so you mean , its not mandatory for the partition to be of type swap , we can just mkswap on any partition? – Ijaz Ahmad Khan Apr 12 '16 at 13:43
  • 1
    @IjazKhan that's correct. Possibly a little scary, but true. – roaima Apr 12 '16 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.