diff options
Diffstat (limited to 'backend/raw_write.py')
| -rwxr-xr-x | backend/raw_write.py | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/backend/raw_write.py b/backend/raw_write.py index 7a7ae18..9a340b0 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -198,8 +198,13 @@ class Dumper(object): return False return True - def _do_format(self, target, label, key, fs_type, order=3): - logging.debug("Start doing persistence partition") + def _do_format(self, target, label, key, fs_type, order=b"3"): + logging.debug(f"Start doing partition on {target} with label {label} in order {order}") + if order == b"1": + logging.debug("Erasing MBR") + # First erase MBR and partition table , if any + # execute(["dd", "if=/dev/zero", "of=%s" % device_path, "bs=512", "count=1"]) + self._do_write("/dev/zero", target, 512, False, 0, 0) p = Popen(["fdisk", target], stdin=PIPE, stderr=PIPE) # commands: # n : new @@ -208,7 +213,7 @@ class Dumper(object): # default first sector # default last sector # w : write and quit - outs, errs = p.communicate(input=b"n\np\n" + bytes(order) + b"\n\n\nw\n") + outs, errs = p.communicate(input=b"n\np\n" + order + b"\n\n\nw\n") working = True while working: time.sleep(0.5) @@ -223,7 +228,7 @@ class Dumper(object): if rc == 1: # the error is Re-reading the partition table failed.: Device or resource busy logging.error( - _("Error {} while doing persistent partition: {}").format( + _("Error {} while doing partition: {}").format( rc, errs.decode("utf-8") ) ) @@ -249,7 +254,7 @@ class Dumper(object): else: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -266,7 +271,7 @@ class Dumper(object): if key == "": # example mkfs.ext4 -L mgalive-persist /dev/sdf3 self.return_message = _("Additional partition added. Formatting...") - path = target + str(order) + path = target + str(order, "utf-8") # Format partition according to the fs_type specified fs_type = fs_type.lower() if fs_type == "fat32": @@ -300,23 +305,24 @@ class Dumper(object): if rc == 0: self.return_state = True self._progress = 100 - self.return_message = _("Persistent partition done") + self.return_message = _("Partition done") else: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) self.finished.set() return - logging.info("Persistent partition done") + logging.info("Partition done") if not self.udev_wait(_("formatting partition")): return else: # example cryptsetup luksFormat /dev/sdb3 - self.return_message = _("Persistent partition added. Encrypting...") - base_target = os.path.basename(target) + str(order) + self.return_message = _("Partition added. Encrypting...") + logging.debug(f"Encrypting {str(order, 'utf-8')}") + base_target = os.path.basename(target) + str(order, "utf-8") process = Popen( - ["cryptsetup", "luksFormat", "-q", target + str(order), "-d", "-"], + ["cryptsetup", "luksFormat", "-q", target + str(order, "utf-8"), "-d", "-"], stdin=PIPE, stderr=PIPE, ) @@ -334,13 +340,13 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while encrypting partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() return self._progress = 50 - self.return_message = _("Persistent partition encrypted. Opening...") + self.return_message = _("Partition encrypted. Opening...") # cryptsetup open /dev/sdb3 crypt_sdb3 if not self.udev_wait("creating encrypted partition"): return @@ -349,7 +355,7 @@ class Dumper(object): [ "cryptsetup", "luksOpen", - target + str(order), + target + str(order, "utf-8"), "crypt_" + base_target, "-d", "-", @@ -371,7 +377,7 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -380,7 +386,7 @@ class Dumper(object): if not self.udev_wait(_("opening encrypted partition")): return self._progress = 60 - self.return_message = _("Persistent partition opened. Formatting...") + self.return_message = _("Partition opened. Formatting...") # mkfs.ext4 -L mgalive-persist /dev/mapper/crypt_sdb3 process = Popen( [ @@ -407,7 +413,7 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -432,12 +438,12 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) else: self.return_state = True - self.return_message = _("Persistent partition done") + self.return_message = _("Partition done") logging.info(self.return_message) if not self.udev_wait(_("closing encrypted partition")): return |
