diff --git a/plugins/partition/partition.py b/plugins/partition/partition.py index 2e360bd..4832e07 100644 --- a/plugins/partition/partition.py +++ b/plugins/partition/partition.py @@ -436,9 +436,29 @@ class partition(cryptobox.plugins.base.CryptoBoxPlugin): # very ugly - maybe a uml bug? # it seems, like this can be avoided by running uml with the param "aio=2.4" (output, error) = proc.communicate() - if proc.returncode != 0: + fdisk_status = proc.returncode + if fdisk_status != 0: self.cbox.log.debug("partitioning failed: %s" % error) - return proc.returncode == 0 + ##Every time we update a partition table, force the kernel + ##to reread it and update /proc/partitions. This particularly + ##applies to internal hard disks. + rereadpt_proc = subprocess.Popen( + shell = False, + stdin = subprocess.PIPE, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + args = [ + self.cbox.prefs["Programs"]["super"], + self.cbox.prefs["Programs"]["CryptoBoxRootActions"], + "plugin", + os.path.join(self.plugin_dir, "root_action.py"), + "rereadpt", + self.blockdevice.devnodes[0]]) + (output, error) = rereadpt_proc.communicate() + rereadpt_status = rereadpt_proc.returncode + if rereadpt_status != 0: + self.cbox.log.info("failed to reread the modified partition table: %s" % error) + return (fdisk_status == 0) def __get_sfdisk_layout(self, param_parts, is_filled): diff --git a/plugins/partition/root_action.py b/plugins/partition/root_action.py index b8713a8..fd61868 100755 --- a/plugins/partition/root_action.py +++ b/plugins/partition/root_action.py @@ -25,6 +25,7 @@ __revision__ = "$Id$" ## necessary: otherwise CryptoBoxRootActions.py will refuse to execute this script PLUGIN_TYPE = "cryptobox" +BLKDEV_BIN = "/sbin/blockdev" SFDISK_BIN = "/sbin/sfdisk" MKFS_BIN = "/sbin/mkfs" LABEL_BIN = "/sbin/e2label" @@ -46,6 +47,15 @@ def __partitionDevice(device): proc.wait() return proc.returncode == 0 +def __rereadPartitions(device): + proc = subprocess.Popen( + shell = False, + args = [ + BLKDEV_BIN, + "--rereadpt", + device]) + proc.wait() + return proc.returncode == 0 def __formatPartition(device, type): import time, threading @@ -105,6 +115,9 @@ if __name__ == "__main__": elif args[0] == "label": if len(args) != 3: raise "InvalidArgNum" result = __labelPartition(args[1], args[2]) + elif args[0] == "rereadpt": + if len(args) != 2: raise "InvalidArgNum" + result = __rereadPartitions(args[1]) else: sys.stderr.write("%s: invalid action (%s)\n" % (self_bin, args[0])) sys.exit(1) diff --git a/src/cryptobox/tests/tools.py b/src/cryptobox/tests/tools.py index 4fabafd..4c78962 100644 --- a/src/cryptobox/tests/tools.py +++ b/src/cryptobox/tests/tools.py @@ -100,6 +100,18 @@ def prepare_partition(blockdevice): if proc.returncode != 0: raise Exception, "could not partition the device (%s): %s" \ % (blockdevice, output.strip()) + ##Make sure the kernel knows about the changes we just made + rereadpt_proc = subprocess.Popen( + shell = False, + stdin = subprocess.PIPE, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + args = [ '/sbin/blockdev', '--rereadpt', blockdevice ]) + (output, error) = rereadpt_proc.communicate() + rereadpt_status = rereadpt_proc.returncode + if rereadpt_status != 0: + raise Exception, "could not reread partition table on %s: %s" \ + % (blockdevice, output.strip()) ## formatting format_device(blockdevice + "1", "vfat") format_device(blockdevice + "2", "ext3")