diff options
Diffstat (limited to 'scripts/lib/mic')
-rw-r--r-- | scripts/lib/mic/imager/baseimager.py | 47 | ||||
-rw-r--r-- | scripts/lib/mic/imager/direct.py | 42 | ||||
-rw-r--r-- | scripts/lib/mic/plugins/imager/direct_plugin.py | 2 | ||||
-rw-r--r-- | scripts/lib/mic/utils/partitionedfs.py | 37 |
4 files changed, 22 insertions, 106 deletions
diff --git a/scripts/lib/mic/imager/baseimager.py b/scripts/lib/mic/imager/baseimager.py index 0d591eaf43..7f32dd559e 100644 --- a/scripts/lib/mic/imager/baseimager.py +++ b/scripts/lib/mic/imager/baseimager.py | |||
@@ -97,41 +97,15 @@ class BaseImageCreator(object): | |||
97 | 97 | ||
98 | 98 | ||
99 | # | 99 | # |
100 | # Properties | ||
101 | # | ||
102 | def __get_instroot(self): | ||
103 | if self.__builddir is None: | ||
104 | raise CreatorError("_instroot is not valid before calling mount()") | ||
105 | return self.__builddir + "/install_root" | ||
106 | _instroot = property(__get_instroot) | ||
107 | """The location of the install root directory. | ||
108 | |||
109 | This is the directory into which the system is installed. Subclasses may | ||
110 | mount a filesystem image here or copy files to/from here. | ||
111 | |||
112 | Note, this directory does not exist before ImageCreator.mount() is called. | ||
113 | |||
114 | Note also, this is a read-only attribute. | ||
115 | |||
116 | """ | ||
117 | |||
118 | |||
119 | # | ||
120 | # Hooks for subclasses | 100 | # Hooks for subclasses |
121 | # | 101 | # |
122 | def _mount_instroot(self, base_on = None): | 102 | def _create(self): |
123 | """Mount or prepare the install root directory. | 103 | """Create partitions for the disk image(s) |
124 | 104 | ||
125 | This is the hook where subclasses may prepare the install root by e.g. | 105 | This is the hook where subclasses may create the partitions |
126 | mounting creating and loopback mounting a filesystem image to | 106 | that will be assembled into disk image(s). |
127 | _instroot. | ||
128 | 107 | ||
129 | There is no default implementation. | 108 | There is no default implementation. |
130 | |||
131 | base_on -- this is the value passed to mount() and can be interpreted | ||
132 | as the subclass wishes; it might e.g. be the location of | ||
133 | a previously created ISO containing a system image. | ||
134 | |||
135 | """ | 109 | """ |
136 | pass | 110 | pass |
137 | 111 | ||
@@ -176,19 +150,16 @@ class BaseImageCreator(object): | |||
176 | 150 | ||
177 | runner.show('umount -l %s' % self.workdir) | 151 | runner.show('umount -l %s' % self.workdir) |
178 | 152 | ||
179 | def mount(self): | 153 | def create(self): |
180 | """Setup the target filesystem in preparation for an install. | 154 | """Create partitions for the disk image(s) |
181 | 155 | ||
182 | This function sets up the filesystem which the ImageCreator will | 156 | Create the partitions that will be assembled into disk |
183 | install into and configure. The ImageCreator class merely creates an | 157 | image(s). |
184 | install root directory, bind mounts some system directories (e.g. /dev) | ||
185 | and writes out /etc/fstab. Other subclasses may also e.g. create a | ||
186 | sparse file, format it and loopback mount it to the install root. | ||
187 | """ | 158 | """ |
188 | self.__setup_tmpdir() | 159 | self.__setup_tmpdir() |
189 | self.__ensure_builddir() | 160 | self.__ensure_builddir() |
190 | 161 | ||
191 | self._mount_instroot() | 162 | self._create() |
192 | 163 | ||
193 | def unmount(self): | 164 | def unmount(self): |
194 | """Unmounts the target filesystem. | 165 | """Unmounts the target filesystem. |
diff --git a/scripts/lib/mic/imager/direct.py b/scripts/lib/mic/imager/direct.py index 2e6914b86d..b96740d0f4 100644 --- a/scripts/lib/mic/imager/direct.py +++ b/scripts/lib/mic/imager/direct.py | |||
@@ -79,9 +79,10 @@ class DirectImageCreator(BaseImageCreator): | |||
79 | self.staging_data_dir = staging_data_dir | 79 | self.staging_data_dir = staging_data_dir |
80 | 80 | ||
81 | def __write_fstab(self, image_rootfs): | 81 | def __write_fstab(self, image_rootfs): |
82 | """overriden to generate fstab (temporarily) in rootfs. This | 82 | """overriden to generate fstab (temporarily) in rootfs. This is called |
83 | is called from mount_instroot, make sure it doesn't get called | 83 | from _create, make sure it doesn't get called from |
84 | from BaseImage.mount()""" | 84 | BaseImage.create() |
85 | """ | ||
85 | if image_rootfs is None: | 86 | if image_rootfs is None: |
86 | return None | 87 | return None |
87 | 88 | ||
@@ -217,29 +218,15 @@ class DirectImageCreator(BaseImageCreator): | |||
217 | # | 218 | # |
218 | # Actual implemention | 219 | # Actual implemention |
219 | # | 220 | # |
220 | def _mount_instroot(self): | 221 | def _create(self): |
221 | """ | 222 | """ |
222 | For 'wic', we already have our build artifacts and don't want | 223 | For 'wic', we already have our build artifacts - we just create |
223 | to loop mount anything to install into, we just create | ||
224 | filesystems from the artifacts directly and combine them into | 224 | filesystems from the artifacts directly and combine them into |
225 | a partitioned image. | 225 | a partitioned image. |
226 | |||
227 | We still want to reuse as much of the basic mic machinery | ||
228 | though; despite the fact that we don't actually do loop or any | ||
229 | other kind of mounting we still want to do many of the same | ||
230 | things to prepare images, so we basically just adapt to the | ||
231 | basic framework and reinterpret what 'mounting' means in our | ||
232 | context. | ||
233 | |||
234 | _instroot would normally be something like | ||
235 | /var/tmp/wic/build/imgcreate-s_9AKQ/install_root, for | ||
236 | installing packages, etc. We don't currently need to do that, | ||
237 | so we simplify life by just using /var/tmp/wic/build as our | ||
238 | workdir. | ||
239 | """ | 226 | """ |
240 | parts = self._get_parts() | 227 | parts = self._get_parts() |
241 | 228 | ||
242 | self.__instimage = PartitionedMount(self._instroot) | 229 | self.__instimage = PartitionedMount() |
243 | 230 | ||
244 | for p in parts: | 231 | for p in parts: |
245 | # as a convenience, set source to the boot partition source | 232 | # as a convenience, set source to the boot partition source |
@@ -250,20 +237,11 @@ class DirectImageCreator(BaseImageCreator): | |||
250 | for p in parts: | 237 | for p in parts: |
251 | # need to create the filesystems in order to get their | 238 | # need to create the filesystems in order to get their |
252 | # sizes before we can add them and do the layout. | 239 | # sizes before we can add them and do the layout. |
253 | # PartitionedMount.mount() actually calls __format_disks() | 240 | # PartitionedMount.create() actually calls __format_disks() |
254 | # to create the disk images and carve out the partitions, | 241 | # to create the disk images and carve out the partitions, |
255 | # then self.install() calls PartitionedMount.install() | 242 | # then self.install() calls PartitionedMount.install() |
256 | # which calls __install_partitition() for each partition | 243 | # which calls __install_partitition() for each partition |
257 | # to dd the fs into the partitions. It would be nice to | 244 | # to dd the fs into the partitions. |
258 | # be able to use e.g. ExtDiskMount etc to create the | ||
259 | # filesystems, since that's where existing e.g. mkfs code | ||
260 | # is, but those are only created after __format_disks() | ||
261 | # which needs the partition sizes so needs them created | ||
262 | # before its called. Well, the existing setup is geared | ||
263 | # to installing packages into mounted filesystems - maybe | ||
264 | # when/if we need to actually do package selection we | ||
265 | # should modify things to use those objects, but for now | ||
266 | # we can avoid that. | ||
267 | 245 | ||
268 | fstab = self.__write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) | 246 | fstab = self.__write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) |
269 | 247 | ||
@@ -294,7 +272,7 @@ class DirectImageCreator(BaseImageCreator): | |||
294 | self.__disks[disk_name] = disk_obj | 272 | self.__disks[disk_name] = disk_obj |
295 | self.__instimage.add_disk(disk_name, disk_obj) | 273 | self.__instimage.add_disk(disk_name, disk_obj) |
296 | 274 | ||
297 | self.__instimage.mount() | 275 | self.__instimage.create() |
298 | 276 | ||
299 | def install(self): | 277 | def install(self): |
300 | """ | 278 | """ |
diff --git a/scripts/lib/mic/plugins/imager/direct_plugin.py b/scripts/lib/mic/plugins/imager/direct_plugin.py index 793a736e95..da18b65f54 100644 --- a/scripts/lib/mic/plugins/imager/direct_plugin.py +++ b/scripts/lib/mic/plugins/imager/direct_plugin.py | |||
@@ -91,7 +91,7 @@ class DirectPlugin(ImagerPlugin): | |||
91 | creatoropts) | 91 | creatoropts) |
92 | 92 | ||
93 | try: | 93 | try: |
94 | creator.mount() | 94 | creator.create() |
95 | creator.install() | 95 | creator.install() |
96 | creator.configure() | 96 | creator.configure() |
97 | creator.print_outimage_info() | 97 | creator.print_outimage_info() |
diff --git a/scripts/lib/mic/utils/partitionedfs.py b/scripts/lib/mic/utils/partitionedfs.py index 50536b4fce..43a38a9b14 100644 --- a/scripts/lib/mic/utils/partitionedfs.py +++ b/scripts/lib/mic/utils/partitionedfs.py | |||
@@ -33,11 +33,9 @@ MBR_OVERHEAD = 1 | |||
33 | SECTOR_SIZE = 512 | 33 | SECTOR_SIZE = 512 |
34 | 34 | ||
35 | class PartitionedMount: | 35 | class PartitionedMount: |
36 | def __init__(self, mountdir): | 36 | def __init__(self): |
37 | self.disks = {} | 37 | self.disks = {} |
38 | self.partitions = [] | 38 | self.partitions = [] |
39 | self.mountOrder = [] | ||
40 | self.unmountOrder = [] | ||
41 | self.parted = find_binary_path("parted") | 39 | self.parted = find_binary_path("parted") |
42 | # Size of a sector used in calculations | 40 | # Size of a sector used in calculations |
43 | self.sector_size = SECTOR_SIZE | 41 | self.sector_size = SECTOR_SIZE |
@@ -102,7 +100,6 @@ class PartitionedMount: | |||
102 | 'label': label, # Partition label | 100 | 'label': label, # Partition label |
103 | 'disk_name': disk_name, # physical disk name holding partition | 101 | 'disk_name': disk_name, # physical disk name holding partition |
104 | 'device': None, # kpartx device node for partition | 102 | 'device': None, # kpartx device node for partition |
105 | 'mount': None, # Mount object | ||
106 | 'num': None, # Partition number | 103 | 'num': None, # Partition number |
107 | 'boot': boot, # Bootable flag | 104 | 'boot': boot, # Bootable flag |
108 | 'align': align, # Partition alignment | 105 | 'align': align, # Partition alignment |
@@ -303,17 +300,6 @@ class PartitionedMount: | |||
303 | self.__run_parted(["-s", d['disk'].device, "set", | 300 | self.__run_parted(["-s", d['disk'].device, "set", |
304 | "%d" % p['num'], "lba", "off"]) | 301 | "%d" % p['num'], "lba", "off"]) |
305 | 302 | ||
306 | def __calculate_mountorder(self): | ||
307 | msger.debug("Calculating mount order") | ||
308 | for p in self.partitions: | ||
309 | if p['mountpoint']: | ||
310 | self.mountOrder.append(p['mountpoint']) | ||
311 | self.unmountOrder.append(p['mountpoint']) | ||
312 | |||
313 | self.mountOrder.sort() | ||
314 | self.unmountOrder.sort() | ||
315 | self.unmountOrder.reverse() | ||
316 | |||
317 | def cleanup(self): | 303 | def cleanup(self): |
318 | if self.disks: | 304 | if self.disks: |
319 | for dev in self.disks.keys(): | 305 | for dev in self.disks.keys(): |
@@ -323,23 +309,6 @@ class PartitionedMount: | |||
323 | except: | 309 | except: |
324 | pass | 310 | pass |
325 | 311 | ||
326 | def unmount(self): | ||
327 | for mp in self.unmountOrder: | ||
328 | if mp == 'swap': | ||
329 | continue | ||
330 | p = None | ||
331 | for p1 in self.partitions: | ||
332 | if p1['mountpoint'] == mp: | ||
333 | p = p1 | ||
334 | break | ||
335 | |||
336 | if p['mount'] != None: | ||
337 | try: | ||
338 | p['mount'].cleanup() | ||
339 | except: | ||
340 | pass | ||
341 | p['mount'] = None | ||
342 | |||
343 | def __install_partition(self, num, source_file, start, size): | 312 | def __install_partition(self, num, source_file, start, size): |
344 | """ | 313 | """ |
345 | Install source_file contents into a partition. | 314 | Install source_file contents into a partition. |
@@ -375,13 +344,11 @@ class PartitionedMount: | |||
375 | self.__install_partition(p['num'], p['source_file'], | 344 | self.__install_partition(p['num'], p['source_file'], |
376 | p['start'], p['size']) | 345 | p['start'], p['size']) |
377 | 346 | ||
378 | def mount(self): | 347 | def create(self): |
379 | for dev in self.disks.keys(): | 348 | for dev in self.disks.keys(): |
380 | d = self.disks[dev] | 349 | d = self.disks[dev] |
381 | d['disk'].create() | 350 | d['disk'].create() |
382 | 351 | ||
383 | self.__format_disks() | 352 | self.__format_disks() |
384 | 353 | ||
385 | self.__calculate_mountorder() | ||
386 | |||
387 | return | 354 | return |