0

I'm preseeding my Debian installation quite successfully, but I have one problem. I want my swap partition to be labeled, but the installer is ignoring the label { } element. The partion is created, it has an UUID, but I want to mount by labels (multisystem environment with Windows, etc.) Other labels are created without problems.

I'm preseeding Debian Stretch.

d-i partman/early_command \
        string sfdisk --wipe-partitions always --delete /dev/sda 2 3 4
d-i partman-auto/disk string /dev/sda
d-i partman-auto/init_automatically_partition select biggest_free

d-i partman-auto/expert_recipe string                       \
    lk-part ::                                              \
            2000 2000 2000 linux-swap                       \
                    $primary{ }                             \
                    method{ swap }                          \
                    format{ }                               \
                    label{ SWAPPART }                       \
            .                                               \
            50000 50000 50000 xfs                           \
                    $primary{ }                             \
                    method{ format }                        \
                    format{ }                               \
                    use_filesystem{ }                       \
                    filesystem{ xfs }                       \
                    mountpoint{ / }                         \
                    label{ LKLINUX }                        \
            .                                               \
            40000 40100 -1 xfs                              \
                    $primary{ }                             \
                    method{ format }                        \
                    format{ }                               \
                    use_filesystem{ }                       \
                    filesystem{ xfs }                       \
                    mountpoint{ /tmp }                      \
                    label{ TEMPFS }                         \
            .
d-i partman/mount_style select label

Does anyone know why the label on swap is ignored?

After the installation, when I manually do:

swapoff /dev/sda2
mkswap --label SWAPPART /dev/sda2
swapon /dev/sda2

the label is present and displayed for example by blkid.

Best Regards
Kamil

  • What outputs are you listing? It is not clear that your label is not being accepted as everything you have posted shows your desired label being used. – kemotep Mar 28 '18 at 17:14
  • It is my preseed.cfg file, it is my config to be set on my disks during installation. After the installation partitions are created properly, but labels are set only on / and /tmp, but not on swap. – Kamil Apr 13 '18 at 18:02
1

I realize that this question is rather old, but just in case someone stumbles upon this, here is the answer:

The reason for the swap label being ignored is that the installer uses mkswap from busybox, which cannot set labels. [To verify this just boot into a netboot installer, switch to the second console (Alt+F2) and look at the mkswap binary.]

As a workaround I have created a debian package luh-label-swap which on install reformats the swap partitions (via preinstall script) preserving the UUIDs and setting labels swap, swap1, swap2 etc. and fixes the fstab entries as well.

You may find the package in our repository: http://ubuntu.repo.uni-hannover.de/ubuntu/pool/pub/l/luh-label-swap/ see below for the relevant code.

It's not a very elegant solution, but works for us. :)

Regards, Robert

These are the relevant parts:

debian/postinst

#!/bin/sh
# postinst script for luh-label-swap

set -e

# [..]

case "$1" in
    configure)
            cp -a /etc/fstab /etc/fstab.dpkg-old
            /usr/lib/luh-label-swap/label-swap
            echo "modified /etc/fstab; old version saved as /etc/fstab.dpkg-old."
    ;;
    abort-upgrade|abort-remove|abort-deconfigure)
    ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

/usr/lib/luh-label-swap/label-swap

#!/bin/bash
# /usr/lib/luh-label-swap/label-swap
#

FSTAB="/etc/fstab"

IAM="$(basename $0)"
unset NO
swapoff -a
for UUID in $(egrep '^UUID=[0-9a-f-]+\s+[[:alpha:]]+\s+swap' "$FSTAB" \
                | sed 's/^UUID=\([0-9a-f-]*\).*/\1/'); do
        echo "$IAM: found swap with UUID=$UUID"
        DEVICE="$(blkid -U "$UUID")"
        if [ -n "$DEVICE" ]; then
                LABEL="swap$NO"
                test -v $NO && NO+=1 || declare -i NO=1
                echo $IAM: mkswap --label "$LABEL" --uuid "$UUID" "$DEVICE"
                mkswap --label "$LABEL" --uuid "$UUID" "$DEVICE"  >/dev/null 2>&1
                echo $IAM: sed -i "s/^UID=$UUID/LABEL=$LABEL/" "$FSTAB"
                sed -i "s/^UUID=$UUID/LABEL=$LABEL/" "$FSTAB"
        fi
done
swapon -a

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.