From: Michael Tremer Date: Sat, 8 May 2021 12:43:02 +0000 (+0000) Subject: Mount image as loop device in test mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c96be18e29cfed4662f1e7f1eb8af903935ed7b6;p=people%2Fms%2Fbricklayer.git Mount image as loop device in test mode Signed-off-by: Michael Tremer --- diff --git a/src/python/disk.py b/src/python/disk.py index 714ff09..a239b40 100644 --- a/src/python/disk.py +++ b/src/python/disk.py @@ -75,13 +75,28 @@ class Disks(object): """ path = util.create_sparse_file("disk", TEST_DISK_SIZE) + # Connect to a loop device + loop_device = self._losetup(path) + # Open the file with parted - device = parted.Device(path) + device = parted.Device(loop_device) # Create a Disk object disk = Disk(self.bricklayer, device) self.disks.append(disk) + def _losetup(self, path): + # Find a free loop device + device = self.bricklayer.command(["losetup", "-f"]) + + device = device.rstrip() + + # Connect the image to the loop device + self.bricklayer.command(["losetup", device, path]) + + # Return the name of the loop device + return device + @property def supported(self): """