with complete_step(f"Inserting partition of {format_bytes(part_size)}{ss}..."):
args.partition_table.run_sfdisk(loopdev)
- # Required otherwise the partition removal will fail
- with open(loopdev, 'rb+') as f:
- ioctl_partition_add(
- f.fileno(),
- part.number,
- args.partition_table.partition_offset(part),
- args.partition_table.partition_size(part)
- )
-
with complete_step("Writing partition..."):
if ident == PartitionIdentifier.root:
luks_format_root(args, loopdev, False, False, True)
cast,
)
+from .syscall import ioctl_partition_add
+
PathString = Union[Path, str]
if device.is_block_device():
run(["sync"])
- run_with_backoff(["blockdev", "--rereadpt", device], attempts=10)
+
+ # Make sure we re-add all partitions after modifying the partition table.
+ with open(device, 'rb+') as f:
+ for p in self.partitions.values():
+ ioctl_partition_add(f.fileno(), p.number, self.partition_offset(p), self.partition_size(p))
@dataclasses.dataclass
die(f"{cmdline[0]} not found in PATH.")
-def run_with_backoff(
- cmdline: Sequence[PathString],
- check: bool = True,
- delay_interrupt: bool = True,
- stdout: _FILE = None,
- stderr: _FILE = None,
- *,
- attempts: int,
- **kwargs: Any,
-) -> CompletedProcess:
- delay = 0.0
- for attempt in range(attempts):
- try:
- return run(cmdline, check, delay_interrupt, stdout, stderr, **kwargs)
- except subprocess.CalledProcessError:
- if attempt == attempts - 1:
- raise
- time.sleep(delay)
- delay = min(delay * 2 + 0.01, 1)
-
- assert False # make mypy happy
-
-
def tmp_dir() -> Path:
path = os.environ.get("TMPDIR") or "/var/tmp"
return Path(path)