2

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?

3
  • 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. Commented Apr 12, 2016 at 13:34
  • So you mean that lvm handles or encapsulates that swap partition type thing in itself? Commented Apr 12, 2016 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). Commented Apr 12, 2016 at 13:42

1 Answer 1

4

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.