Revision 333ff548 image_creator/disk.py
b/image_creator/disk.py | ||
---|---|---|
51 | 51 |
size = blockdev('--getsize', sourcedev) |
52 | 52 |
cowfd, cow = tempfile.mkstemp() |
53 | 53 |
self._add_cleanup(os.unlink, cow) |
54 |
dd('if=/dev/zero', 'of=%s' % cow, 'count=%d' % (1024*1024))#(int(size)/4)) |
|
54 |
# Create 1G cow file |
|
55 |
dd('if=/dev/null', 'of=%s' % cow, 'bs=1k' ,'seek=%d' % (1024*1024)) |
|
55 | 56 |
cowdev = self._losetup(cow) |
56 | 57 |
|
57 | 58 |
snapshot = uuid.uuid4().hex |
... | ... | |
70 | 71 |
|
71 | 72 |
class DiskDevice(object): |
72 | 73 |
|
73 |
def __init__(self, disk, device): |
|
74 |
def __init__(self, disk, device, bootable = True):
|
|
74 | 75 |
self.disk = disk |
75 |
self.dev = device |
|
76 |
self.device = device |
|
77 |
self.is_bootable = bootable |
|
76 | 78 |
self.partitions_mapped = False |
77 | 79 |
self.magic_number = uuid.uuid4().hex |
78 | 80 |
|
79 | 81 |
def list_partitions(self): |
82 |
if not self.partitions_mapped: |
|
83 |
kpartx("-a", "-p", self.magic_number, self.dev) |
|
84 |
self.disk._cleanup_jobs.append(kpartx, "-d", "-p", |
|
85 |
self.magic_number, self.dev) |
|
86 |
self.partitions_mapped = True |
|
87 |
|
|
80 | 88 |
output = kpartx("-l", "-p", self.magic_number, self.dev) |
81 | 89 |
return [ "/dev/mapper/%s" % x for x in |
82 | 90 |
re.findall('^\S+', str(output), flags=re.MULTILINE)] |
83 | 91 |
|
84 | 92 |
def mount(self, partition): |
85 | 93 |
if not self.partitions_mapped: |
94 |
self.list_partitions() |
|
86 | 95 |
kpartx("-a", "-p", self.magic_number, self.dev) |
87 | 96 |
self.disk._cleanup_jobs.append(kpartx, "-d", "-p", |
88 | 97 |
self.magic_number, self.dev) |
Also available in: Unified diff