Now calls "/sbin/blockdev --rereadpt" after any changes to partition tables; should fix bug #214

This commit is contained in:
frisco 2009-05-29 05:56:14 +00:00
parent 9add2a7b34
commit 9cd3d7dd42
3 changed files with 47 additions and 2 deletions

View file

@ -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):

View file

@ -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)

View file

@ -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")