I created a partition called /dev/sda3 as a swap partition, and changed the ID to 82 (Linux Swap) via fdisk. If this partition was recognized as a swap partition (seen in the output of fdisk -l and blkid), then why couldn't I proceed straight to swapon /dev/sda3? Why did I have to execute mkswap /dev/sda3? Another question, is partition information exclusive from data? So if I changed a filesystem type via fdisk would data be affected?

fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008d6ed

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          32      256000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              32        1566    12317696   83  Linux
/dev/sda3            1566        2610     8390105   82  Linux swap / Solaris


/dev/sda3: LABEL="SWAP" UUID="63f1807e-7cc6-4339-92b2-b1958fcf285e" TYPE="swap"
  • Take a look at the mkswap man page. It explains why. First 3-4 paragraphs. – slm Oct 1 '14 at 4:44
  • Had a look again. Cheers @slm. – user Oct 2 '14 at 22:53

fdisk creates a partition but doesn't format it. Before you can use your swap partition, you need to format it first. This is done with mkswap.

The same rules apply for any other file systems. You need to create the partition and format it before using it.

|improve this answer|||||

The mkswap command writes a header (starting at 0x400 in order to skip any disk label etc.) to the swap partition or swap file for some housekeeping like version, last page etc. And it ends with the magic string SWAP-SPACE or SWAPSPACE2 at the end to identify it as such. (SOURCE)

It isn't really formatted, like a filesystem partition, just a header and then space where the memory pages being swapped out will be be put.

|improve this answer|||||

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.