[Parted-maintainers] Bug#1021403: [parted] /usr/sbin/parted: invalid token: swap
Jean-Marc LACROIX
jeanmarc.lacroix at free.fr
Fri Oct 7 20:58:33 BST 2022
Le 07/10/2022 à 18:29, Colin Watson a écrit :
> Control: severity -1 normal
> Control: fixed -1 3.5-1
>
> On Fri, Oct 07, 2022 at 05:29:14PM +0200, Jean-Marc LACROIX wrote:
>> Severity: critical
>
> "makes unrelated software on the system (or the whole system) break, or
> causes serious data loss, or introduces a security hole on systems where
> you install the package"
>
> A difficulty with using the CLI, or even a missing feature in the CLI,
> doesn't fall into any of these categories.
>
>> According documentation available in man it seems possible to create one
>> partition of type "swap" by using "set" option on command line.
>>
>> After many tests done with Linux "parted" command and Ansible module
>> "parted", it seems that it is not possible to set one logical partition as a
>> swap partition with the flag option available into parted tool.
>>
>> My disk uses for test has following partitions...
>>
>> ansible at thinkpad-410:~$ sudo fdisk -l /dev/sda
>> Disque /dev/sda : 931,51 GiB, 1000204886016 octets, 1953525168 secteurs
>> Modèle de disque : HGST HTS721010A9
>> Unités : secteur de 1 × 512 = 512 octets
>> Taille de secteur (logique / physique) : 512 octets / 4096 octets
>> taille d'E/S (minimale / optimale) : 4096 octets / 4096 octets
>> Type d'étiquette de disque : dos
>> Identifiant de disque : 0x483880d2
>>
>> Périphérique Amorçage Début Fin Secteurs Taille Id Type
>> /dev/sda1 * 2048 48828415 48826368 23,3G 83 Linux
>> /dev/sda2 48830462 1953523711 1904693250 908,2G 5 Étendue
>> /dev/sda5 48830464 68360191 19529728 9,3G 8e LVM Linux
>> /dev/sda6 68362240 70361087 1998848 976M 82 partition
>> d'échange Linux / Solaris
>
> This says that it's already a swap partition, so I'm not sure why you
> need to set it as one. Can you explain further?
>
Yes,
Ansible is one tool which is able to manage idempotence feature.
Idempotence is originally a concept from Mathematics. As defined by
Wikipedia,
idempotence is the property of certain operations in mathematics and
computer science whereby they can be applied multiple times without
changing the result beyond the initial application.
Therefore, the designer should define only one variable (for example)
to indicate that /dev/sda6 is a logical partition located on an
extended partition with type swap. This therefore constitutes an
element of choice (the specification) which must be considered as
non-modifiable and therefore inviolable (!). Of course, if we modify
the specification, then the partition will have to change state.
On the first run, of course, because there is nothing on the disk,
then Ansible detect this feature and then force a command (parted) to
create the partition with swap type. But on the second pass (and later
pass), because this partition is already set to the exact type chosen
by designer, then no action is done (!)
> (On an MBR partition table like this, all that setting the "swap" flag
> does is set the partition type to 0x82.)
>
>> /dev/sda7 70363136 74266623 3903488 1,9G 8e LVM Linux
>> /dev/sda8 74268672 279068671 204800000 97,7G 8e LVM Linux
>>
>> and when i try to set one partition with swap, then ...
>>
>> ansible at thinkpad-410:~$ sudo /usr/sbin/parted -s -m -a optimal /dev/sda --
>> unit KiB set 6 swap on
>> /usr/sbin/parted: invalid token: swap
>>
>> I have also tried, but without success...
>>
>> ansible at thinkpad-410:~$ sudo /usr/sbin/parted -s -m -a optimal /dev/sda --
>> unit KiB set 6 swap on set 6 lvm off
>> /usr/sbin/parted: invalid token: swap
>
> This was fixed in parted 3.4.64. From the NEWS file:
>
> Add use of the swap partition flag to msdos disk labeled disks.
>
> But since it's already of the correct type, maybe you can just skip that
> bit on older versions of parted?
>
> (Or, if your automation is building the entire system from scratch, then
> another option might be to use GPT instead of MBR.)
>
Dear Colin,
First of all, many thanks for the quickly answer and of course for the
good news for this bug available in Debian Bookworm Release.
Please find some trace to verify behaviour with your new package
ansible at thinkpad-410:~$ apt-cache policy parted
parted:
Installé : 3.4-1
Candidat : 3.4-1
Table de version :
3.5-2 80
80 http://ftp.de.debian.org/debian bookworm/main amd64 Packages
*** 3.4-1 500
500 http://ftp.de.debian.org/debian bullseye/main amd64 Packages
100 /var/lib/dpkg/status
3.2-25 90
90 http://ftp.de.debian.org/debian oldstable/main amd64 Packages
ansible at thinkpad-410:~$ cat /etc/debian_version
11.5
ansible at thinkpad-410:~$ dpk -l |grep -v ii
-bash: dpk : commande introuvable
ansible at thinkpad-410:~$ dpkg -l |grep -v ii
Souhait=inconnU/Installé/suppRimé/Purgé/H=à garder
|
État=Non/Installé/fichier-Config/dépaqUeté/échec-conFig/H=semi-installé/W=attend-traitement-déclenchements
|/ Err?=(aucune)/besoin Réinstallation (État,Err: majuscule=mauvais)
||/ Nom Version
Architecture Description
+++-====================================-=================================-============-===============================================================================
ansible at thinkpad-410:~$
ansible at thinkpad-410:~$ cat
/etc/apt/sources.list.d/debian_apt_v_11_bullseye_* |grep -v "#" | grep -v ^$
deb http://ftp.de.debian.org/debian/ bullseye main contrib non-free
deb http://ftp.de.debian.org/debian/ bookworm main contrib non-free
deb http://ftp.de.debian.org/debian/ oldstable main contrib non-free
deb http://repository.spotify.com stable non-free
deb http://security.debian.org/debian-security bullseye-security main
contrib non-free
deb http://ftp.de.debian.org/debian bullseye-updates main contrib non-free
ansible at thinkpad-410:~$
ansible at thinkpad-410:~$ cat /etc/apt/preferences.d/* |grep -v "#" | grep
-v ^$
Package: dhcpcd5
Pin: release *
Pin-Priority: -1
Package: vmdb2
Pin: release o=Debian,l=Debian,n=bullseye
Pin-Priority: 920
Package: *
Pin: release o=Debian,l=Debian,n=bullseye/updates
Pin-Priority: 500
Package: *
Pin: release o=Debian,l=Debian,n=bullseye-update
Pin-Priority: 500
Package: *
Pin: release o=Debian,l=Debian,n=bullseye
Pin-Priority: 500
Package: *
Pin: release o=Debian,l=Debian,n=bullseye-backports
Pin-Priority: 100
Package: *
Pin: release o=Debian,l=Debian,n=buster
Pin-Priority: 90
Package: *
Pin: release o=Debian,l=Debian,n=bookworm
Pin-Priority: 80
Package: *
Pin: release o=Debian,l=Debian,n=sid
Pin-Priority: 70
Package: *
Pin: release o=Debian,l=Debian,n=experimental
Pin-Priority: 60
ansible at thinkpad-410:~$
Then of course, it is easy now to install new Debian package from
Bookworm ...
ansible at thinkpad-410:~$ sudo apt -t bookworm install parted
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances... Fait
Lecture des informations d'état... Fait
.................
Verify now that new parted package is correctly installed
ansible at thinkpad-410:~$ apt-cache policy parted
parted:
Installé : 3.5-2
Candidat : 3.5-2
Table de version :
*** 3.5-2 100
80 http://ftp.de.debian.org/debian bookworm/main amd64 Packages
100 /var/lib/dpkg/status
3.4-1 500
500 http://ftp.de.debian.org/debian bullseye/main amd64 Packages
3.2-25 90
90 http://ftp.de.debian.org/debian oldstable/main amd64 Packages
ansible at thinkpad-410:~$
Now is the time to test the real command and make sure everything is OK!
initial conditions....
ansible at thinkpad-410:~$ sudo fdisk -l /dev/sda
sudo fdisk -l /dev/sda
Disque /dev/sda : 931,51 GiB, 1000204886016 octets, 1953525168 secteurs
Modèle de disque : HGST HTS721010A9
Unités : secteur de 1 × 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 4096 octets
taille d'E/S (minimale / optimale) : 4096 octets / 4096 octets
Type d'étiquette de disque : dos
Identifiant de disque : 0x483880d2
Périphérique Amorçage Début Fin Secteurs Taille Id Type
/dev/sda1 * 2048 48828415 48826368 23,3G 83 Linux
/dev/sda2 48830462 1953523711 1904693250 908,2G 5 Étendue
/dev/sda5 48830464 68360191 19529728 9,3G 83 Linux
/dev/sda6 68362240 70361087 1998848 976M 82 partition
d'échange Linux / Solaris
/dev/sda7 70363136 74266623 3903488 1,9G 83 Linux
/dev/sda8 74268672 279068671 204800000 97,7G 83 Linux
ansible at thinkpad-410:~$ sudo /usr/sbin/parted -s -m -a optimal /dev/sda
-- unit KiB set 6 swap on
SELinux enabled state cached to: disabled
No filesystem is currently mounted on /sys/fs/cgroup.
Failed to determine unit we run in, ignoring: No data available
SELinux enabled state cached to: disabled
No filesystem is currently mounted on /sys/fs/cgroup.
Failed to determine unit we run in, ignoring: No data available
ansible at thinkpad-410:~$
Change now the type of partition ....
ansible at thinkpad-410:~$ sudo /usr/sbin/parted -s -m -a optimal /dev/sda
-- unit KiB set 6 lvm on
SELinux enabled state cached to: disabled
No filesystem is currently mounted on /sys/fs/cgroup.
Failed to determine unit we run in, ignoring: No data available
SELinux enabled state cached to: disabled
No filesystem is currently mounted on /sys/fs/cgroup.
Failed to determine unit we run in, ignoring: No data available
ansible at thinkpad-410:~$
and verif the new type ....
Disque /dev/sda : 931,51 GiB, 1000204886016 octets, 1953525168 secteurs
Modèle de disque : HGST HTS721010A9
Unités : secteur de 1 × 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 4096 octets
taille d'E/S (minimale / optimale) : 4096 octets / 4096 octets
Type d'étiquette de disque : dos
Identifiant de disque : 0x483880d2
Périphérique Amorçage Début Fin Secteurs Taille Id Type
/dev/sda1 * 2048 48828415 48826368 23,3G 83 Linux
/dev/sda2 48830462 1953523711 1904693250 908,2G 5 Étendue
/dev/sda5 48830464 68360191 19529728 9,3G 83 Linux
/dev/sda6 68362240 70361087 1998848 976M 8e LVM Linux
/dev/sda7 70363136 74266623 3903488 1,9G 83 Linux
/dev/sda8 74268672 279068671 204800000 97,7G 83 Linux
La partition 2 ne commence pas sur une frontière de cylindre physique.
ansible at thinkpad-410:~$
Congratulation Colin, the bug is dead !
Last question ?
Could you please give me the correct option to set one partition with
native Linux with parted ? (id=83)
--
-- mailto : jeanmarc.lacroix at free.fr --
More information about the Parted-maintainers
mailing list