summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2017-07-04 11:54:31 -0400
committerJoey Hess2017-07-04 11:56:06 -0400
commitaa171af9aee49b0dbd2800d19a029e3506423f3f (patch)
tree082b7cb00f69de0de4a85cccf7c40998e3335c49
parent442d36e6d1b3306a992dfd44e762a49aae8a8264 (diff)
Diskimage.imageExists: Align disk image size to multiple of 4096 sector size
Since some programs (such as VBoxManage convertdd) refuse to operate on disk images not aligned to a sector size. This commit was sponsored by Boyd Stephen Smith Jr. on Patreon.
-rw-r--r--debian/changelog3
-rw-r--r--src/Propellor/Property/DiskImage.hs8
2 files changed, 10 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 29eb985e..8fdfdf00 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,9 @@ propellor (4.0.7) UNRELEASED; urgency=medium
Thanks, Sean Whitton.
* Bootstrap.clonedFrom: Fix bug that broke copying .git/config into
chroot.
+ * Diskimage.imageExists: Align disk image size to multiple of 4096
+ sector size, since some programs (such as VBoxManage convertdd)
+ refuse to operate on disk images not aligned to a sector size.
-- Joey Hess <id@joeyh.name> Tue, 20 Jun 2017 10:55:37 -0400
diff --git a/src/Propellor/Property/DiskImage.hs b/src/Propellor/Property/DiskImage.hs
index 90b7010b..d5898d7c 100644
--- a/src/Propellor/Property/DiskImage.hs
+++ b/src/Propellor/Property/DiskImage.hs
@@ -247,7 +247,7 @@ getMountSz szm l (Just mntpt) =
--
-- If the file is too large, truncates it down to the specified size.
imageExists :: FilePath -> ByteSize -> Property Linux
-imageExists img sz = property ("disk image exists" ++ img) $ liftIO $ do
+imageExists img isz = property ("disk image exists" ++ img) $ liftIO $ do
ms <- catchMaybeIO $ getFileStatus img
case ms of
Just s
@@ -258,6 +258,12 @@ imageExists img sz = property ("disk image exists" ++ img) $ liftIO $ do
_ -> do
L.writeFile img (L.replicate (fromIntegral sz) 0)
return MadeChange
+ where
+ sz = ceiling (fromInteger isz / sectorsize) * ceiling sectorsize
+ -- Disks have a sector size, and making a disk image not
+ -- aligned to a sector size will confuse some programs.
+ -- Common sector sizes are 512 and 4096; use 4096 as it's larger.
+ sectorsize = 4096 :: Double
-- | A pair of properties. The first property is satisfied within the
-- chroot, and is typically used to download the boot loader.