0

I am partitioning an external 1TB HDD for a small embedded Linux system. I want to encrypt the swap partition. According to the cryptsetep FAQ, you need to use kernel device names (/dev/sda, etc) in /etc/crypttab:

Specifying it directly by UUID does not work, unfortunately, as the UUID is part of the swap signature and that is not visible from the outside due to the encryption and in addition changes on each reboot.

This may become a problem if I attach/rearrange drives later and the device name changes. For example, say the swap is on /dev/sda3. Then I attach a different drive which becomes /dev/sda, pushing the original drive to /dev/sdb. If there exists a third partition on the new drive (now called sda3), it will try to encrypt that drive and use it as swap.

One option given is to make sure sure the partition number is not present on additional disks. So, finally, my question:

Can I use non-contiguous partition numbers? Will they persist across reboots? In other words, could I do this? Note the gap between sda4 and sda8:

/dev/sda1    primary    /boot
/dev/sda2    primary    /
/dev/sda3    primary    /home
/dev/sda4    extended
/dev/sda8    swap (encrypted)

If so, I would feel pretty safe about never seeing sda8 on any other drive.

6
  • 1
    another approach with uuid/label and offset wiki.archlinux.org/title/Dm-crypt/… Commented May 17, 2022 at 21:56
  • you will not be able to add sda5 or sda6 or sda7 later, even if you leave plenty of space, without starting all over (and even then there are limitations). be sure these partitions fulfill this device's needs for the life of this usage.
    – Skaperen
    Commented May 17, 2022 at 23:45
  • why not make /dev/sda4 be your swap space?
    – Skaperen
    Commented May 17, 2022 at 23:48
  • your partitioning tool may or may not support non-contiguous partition numbers. if you need to find a tool that does, ask a new question.
    – Skaperen
    Commented May 17, 2022 at 23:52
  • given how trippy the scheme used for the extended partitions is, what with it being more like a linked list than any sort of table, you might have a hard time building that sort of setup. It would probably be much easier with GPT partitioning, since there the table is just a straightforward array.
    – ilkkachu
    Commented May 18, 2022 at 0:10

1 Answer 1

2

Partition numbers cannot conflict. Physically cannot.

The partitions are recorded in a Partition Table, special place in the 0-block of the disk. These records are not a named records, they are placed in an array. The index in that array (plus one) later become a number in the list of partitions you see in terminal. Read wiki for example: https://en.wikipedia.org/wiki/Disk_partitioning

And yes, Partition Table can have empty cells. Ot is just an indexed array. Any record in it can have a zero for Partition Type and all tools would know that this record is empty.

3
  • 1
    partitions 5 and above (extended) are not in one single array in the 0-block.
    – Skaperen
    Commented May 17, 2022 at 23:54
  • 1
    Thanks! I didn't mean they would conflict on the same device. I meant that if I was using sda3, for example, and then added a different drive which became sda (and pushed the original drive to sdb. Then if the new drive had a partition #3, Linux would try to use the new driver's sda3 for the encrypted swap. Thanks for the rest!
    – bitsmack
    Commented May 18, 2022 at 0:29
  • (sorry for the typos in my comment; I was on my phone and I wasn't careful...)
    – bitsmack
    Commented May 18, 2022 at 0:48

You must log in to answer this question.

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