3

I checked the man page for mkswap and was left confused whether mkswap tests whether a partition is of type 82 before formatting it.

Background: I am using Ubuntu 11.04, and I had just set up my swap partition to be encrypted, using ecryptfs-setup-swap, which adds a reference to the encrypted swap partition to /etc/fstab and to the actual partition to /etc/crypttab. The actual partition is referred to by the device name, /dev/sdb1 in my case. If I understand correctly, during boot, the virtual partition is created and formatted as a swap partition, generating a new UUID each time, so it cannot be specified by UUID. This leaves me concerned that if I install a new hard drive or otherwise rearrange the physical drives, mkswap would try to format the wrong partition. If it fails because the partition isn't a swap partition, then no problem, as swap is rarely used. If it succeeds in formatting the wrong partition, then big problem.

2
  • What is the point of re-creating a swap partition every boot? Sep 8, 2011 at 1:15
  • The virtual swap space is enctypted with a randomly generated key which doesn't persist between reboots, so the virtual swap space has to be re-created with a new key at each boot.
    – bgvaughan
    Sep 8, 2011 at 4:05

2 Answers 2

3

No, Linux mkswap doesn't care about the partition type, and doesn't check what was previously on the device either. It would be a good idea for you to to check either the partition type (but why would it be 82 in your case — shouldn't it be fd indicating a device mapper container?), or the previous content of the partition (check that there isn't a recognized filesystem, e.g. with file).

3

Definitely not. Don't forget that mkswap can also be run on a file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .