[elbe-devel] [PATCH 5/5] elbepack: use sfdisk to change partition type

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue Mar 5 16:11:59 CET 2024


sfdisk is the "scripted" version of fdisk.
It provides a interface suitable for scripting without having to feed
cryptic input commands to fdisks stdin.
It also does not generate spurious output.

Furthermore it can lock the blockdevice to avoid raceconditions.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/finetuning.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index ce98fc8c1bdb..5f3500b6d9f6 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -701,10 +701,7 @@ class SetPartitionTypeAction(ImageFinetuningAction):
         part_nr = self.node.et.attrib['part']
         part_type = self.node.et.attrib['type']
 
-        cmd = f'fdisk {loop_dev}'
-        inp = f't\n{part_nr}\n{part_type}\nw\n'
-
-        do(cmd, stdin=inp)
+        do(f'sfdisk --lock --part-type {loop_dev} {part_nr} {part_type}')
 
 
 @FinetuningAction.register('rm_apt_source')
-- 
2.44.0



More information about the elbe-devel mailing list