Skip to content

Commit

Permalink
Find partition, fix #121
Browse files Browse the repository at this point in the history
  • Loading branch information
lvps committed Oct 22, 2024
1 parent 39361e3 commit 25f00b2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions basilico.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,19 @@ def close_at_end(self, _cmd: str, _nothing: str):
# noinspection PyUnresolvedReferences
reactor.callFromThread(reactor.callLater, CLOSE_AT_END_TIMER, try_stop_at_end)

@staticmethod
def _get_last_linux_partition_path_and_number(dev: str) -> tuple[str, str] | tuple[None, None]:
# Use PTTYPE to get MBR/GPT (dos/gpt are the possible values)
# PARTTYPENAME could be useful, too
output = subprocess.getoutput(f"lsblk -o PATH,PARTN,PARTTYPE -J {dev}")
jsonized = json.loads(output)
for entry in reversed(jsonized["blockdevices"]):
if entry["partn"] and entry["path"]: # lsblk also returns the device itself, which has no partitions
# GPT or MBR Linux partition ID
if entry["parttype"] == "0fc63daf-8483-4772-8e79-3d69d8477de4" or entry["parttype"] == "0x83":
return entry["path"], entry["partn"]
return None, None

def cannolo(self, _cmd: str, dev_and_iso: str):
parts: list[Optional[str]] = dev_and_iso.split(" ", 1)
while len(parts) < 2:
Expand Down Expand Up @@ -628,11 +641,13 @@ def cannolo(self, _cmd: str, dev_and_iso: str):
else:
success = self.dd(iso, dev)
if success:
success = run_command_on_partition(dev, f"sudo growpart {dev} 1") # FIXME: se ha più partizioni non funziona
part_path, part_number = self._get_last_linux_partition_path_and_number(dev)

success = run_command_on_partition(dev, f"sudo growpart {dev} {part_number}")
if success:
success = run_command_on_partition(dev, f"sudo e2fsck -fy {dev}1")
success = run_command_on_partition(dev, f"sudo e2fsck -fy {part_path}")
if success:
success = run_command_on_partition(dev, f"sudo resize2fs {dev}1")
success = run_command_on_partition(dev, f"sudo resize2fs {part_path}")
if success:
pass
else:
Expand Down

0 comments on commit 25f00b2

Please sign in to comment.