blob: 2a71d7b1d6a0433b24b7cd11a4c110681a5fd4d9 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001#
2# Copyright (c) 2013-2016 Intel Corporation.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05005#
6# DESCRIPTION
7# This module provides the OpenEmbedded partition object definitions.
8#
9# AUTHORS
10# Tom Zanussi <tom.zanussi (at] linux.intel.com>
11# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
12
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014import os
Brad Bishop316dfdd2018-06-25 12:45:53 -040015import uuid
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017from wic import WicError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019from wic.pluginbase import PluginMgr
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021logger = logging.getLogger('wic')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022
Patrick Williamsc0f7c042017-02-23 20:41:17 -060023class Partition():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024
25 def __init__(self, args, lineno):
26 self.args = args
27 self.active = args.active
28 self.align = args.align
29 self.disk = args.disk
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 self.device = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031 self.extra_space = args.extra_space
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 self.exclude_path = args.exclude_path
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050033 self.fsopts = args.fsopts
34 self.fstype = args.fstype
35 self.label = args.label
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036 self.use_label = args.use_label
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037 self.mkfs_extraopts = args.mkfs_extraopts
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038 self.mountpoint = args.mountpoint
39 self.no_table = args.no_table
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 self.num = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 self.overhead_factor = args.overhead_factor
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 self.part_name = args.part_name
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 self.part_type = args.part_type
44 self.rootfs_dir = args.rootfs_dir
45 self.size = args.size
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 self.fixed_size = args.fixed_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 self.source = args.source
48 self.sourceparams = args.sourceparams
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 self.system_id = args.system_id
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 self.use_uuid = args.use_uuid
51 self.uuid = args.uuid
Brad Bishop316dfdd2018-06-25 12:45:53 -040052 self.fsuuid = args.fsuuid
Brad Bishop08902b02019-08-20 09:16:51 -040053 self.type = args.type
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054
55 self.lineno = lineno
56 self.source_file = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057
58 def get_extra_block_count(self, current_blocks):
59 """
60 The --size param is reflected in self.size (in kB), and we already
61 have current_blocks (1k) blocks, calculate and return the
62 number of (1k) blocks we need to add to get to --size, 0 if
63 we're already there or beyond.
64 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 logger.debug("Requested partition size for %s: %d",
66 self.mountpoint, self.size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067
68 if not self.size:
69 return 0
70
71 requested_blocks = self.size
72
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073 logger.debug("Requested blocks %d, current_blocks %d",
74 requested_blocks, current_blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075
76 if requested_blocks > current_blocks:
77 return requested_blocks - current_blocks
78 else:
79 return 0
80
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081 def get_rootfs_size(self, actual_rootfs_size=0):
82 """
83 Calculate the required size of rootfs taking into consideration
84 --size/--fixed-size flags as well as overhead and extra space, as
85 specified in kickstart file. Raises an error if the
86 `actual_rootfs_size` is larger than fixed-size rootfs.
87
88 """
89 if self.fixed_size:
90 rootfs_size = self.fixed_size
91 if actual_rootfs_size > rootfs_size:
92 raise WicError("Actual rootfs size (%d kB) is larger than "
93 "allowed size %d kB" %
94 (actual_rootfs_size, rootfs_size))
95 else:
96 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
97 if extra_blocks < self.extra_space:
98 extra_blocks = self.extra_space
99
100 rootfs_size = actual_rootfs_size + extra_blocks
101 rootfs_size *= self.overhead_factor
102
103 logger.debug("Added %d extra blocks to %s to get to %d total blocks",
104 extra_blocks, self.mountpoint, rootfs_size)
105
106 return rootfs_size
107
108 @property
109 def disk_size(self):
110 """
111 Obtain on-disk size of partition taking into consideration
112 --size/--fixed-size options.
113
114 """
115 return self.fixed_size if self.fixed_size else self.size
116
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500117 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
118 bootimg_dir, kernel_dir, native_sysroot):
119 """
120 Prepare content for individual partitions, depending on
121 partition command parameters.
122 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500123 if not self.source:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 if not self.size and not self.fixed_size:
125 raise WicError("The %s partition has a size of zero. Please "
126 "specify a non-zero --size/--fixed-size for that "
127 "partition." % self.mountpoint)
128
129 if self.fstype == "swap":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500130 self.prepare_swap_partition(cr_workdir, oe_builddir,
131 native_sysroot)
132 self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 else:
134 if self.fstype == 'squashfs':
135 raise WicError("It's not possible to create empty squashfs "
136 "partition '%s'" % (self.mountpoint))
137
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500138 rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label,
139 self.lineno, self.fstype)
140 if os.path.isfile(rootfs):
141 os.remove(rootfs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142
143 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
144 method = getattr(self, "prepare_empty_partition_" + prefix)
145 method(rootfs, oe_builddir, native_sysroot)
146 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500147 return
148
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 plugins = PluginMgr.get_plugins('source')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500150
151 if self.source not in plugins:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
153 "See 'wic list source-plugins' for a list of available"
154 " --sources.\n\tSee 'wic help source-plugins' for "
155 "details on adding a new source plugin." %
156 (self.source, self.mountpoint))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500157
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 srcparams_dict = {}
159 if self.sourceparams:
160 # Split sourceparams string of the form key1=val1[,key2=val2,...]
161 # into a dict. Also accepts valueless keys i.e. without =
162 splitted = self.sourceparams.split(',')
Brad Bishop19323692019-04-05 15:28:33 -0400163 srcparams_dict = dict(par.split('=', 1) for par in splitted if par)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500164
165 plugin = PluginMgr.get_plugins('source')[self.source]
166 plugin.do_configure_partition(self, srcparams_dict, creator,
167 cr_workdir, oe_builddir, bootimg_dir,
168 kernel_dir, native_sysroot)
169 plugin.do_stage_partition(self, srcparams_dict, creator,
170 cr_workdir, oe_builddir, bootimg_dir,
171 kernel_dir, native_sysroot)
172 plugin.do_prepare_partition(self, srcparams_dict, creator,
173 cr_workdir, oe_builddir, bootimg_dir,
174 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400175 plugin.do_post_partition(self, srcparams_dict, creator,
176 cr_workdir, oe_builddir, bootimg_dir,
177 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500178
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500179 # further processing required Partition.size to be an integer, make
180 # sure that it is one
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 if not isinstance(self.size, int):
182 raise WicError("Partition %s internal size is not an integer. "
183 "This a bug in source plugin %s and needs to be fixed." %
184 (self.mountpoint, self.source))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500185
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 if self.fixed_size and self.size > self.fixed_size:
187 raise WicError("File system image of partition %s is "
188 "larger (%d kB) than its allowed size %d kB" %
189 (self.mountpoint, self.size, self.fixed_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500190
191 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400192 native_sysroot, real_rootfs = True):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500193 """
194 Prepare content for a rootfs partition i.e. create a partition
195 and fill it from a /rootfs dir.
196
Brad Bishop316dfdd2018-06-25 12:45:53 -0400197 Currently handles ext2/3/4, btrfs, vfat and squashfs.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198 """
199 p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
200 p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800201 "%s/../pseudo" % rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500202 p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
203 p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
204 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
205 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
206 pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
207 pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500208 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500209
210 rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label,
211 self.lineno, self.fstype)
212 if os.path.isfile(rootfs):
213 os.remove(rootfs)
214
Brad Bishop08902b02019-08-20 09:16:51 -0400215 # If size is not specified compute it from the rootfs_dir size
Brad Bishop316dfdd2018-06-25 12:45:53 -0400216 if not self.size and real_rootfs:
Brad Bishop08902b02019-08-20 09:16:51 -0400217 # Use the same logic found in get_rootfs_size()
218 # from meta/classes/image.bbclass
219 du_cmd = "du -ks %s" % rootfs_dir
220 out = exec_cmd(du_cmd)
221 self.size = int(out.split()[0])
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500222
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
224 method = getattr(self, "prepare_rootfs_" + prefix)
225 method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
226 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 # get the rootfs size in the right units for kickstart (kB)
229 du_cmd = "du -Lbks %s" % rootfs
230 out = exec_cmd(du_cmd)
231 self.size = int(out.split()[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500232
233 def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
234 native_sysroot, pseudo):
235 """
236 Prepare content for an ext2/3/4 rootfs partition.
237 """
238 du_cmd = "du -ks %s" % rootfs_dir
239 out = exec_cmd(du_cmd)
240 actual_rootfs_size = int(out.split()[0])
241
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500242 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500244 with open(rootfs, 'w') as sparse:
245 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500246
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500247 extraopts = self.mkfs_extraopts or "-F -i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500248
249 label_str = ""
250 if self.label:
251 label_str = "-L %s" % self.label
252
Brad Bishop316dfdd2018-06-25 12:45:53 -0400253 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
254 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500255 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
256
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500257 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500258 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
259
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500260 def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
261 native_sysroot, pseudo):
262 """
263 Prepare content for a btrfs rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264 """
265 du_cmd = "du -ks %s" % rootfs_dir
266 out = exec_cmd(du_cmd)
267 actual_rootfs_size = int(out.split()[0])
268
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500269 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500270
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500271 with open(rootfs, 'w') as sparse:
272 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273
274 label_str = ""
275 if self.label:
276 label_str = "-L %s" % self.label
277
Brad Bishop316dfdd2018-06-25 12:45:53 -0400278 mkfs_cmd = "mkfs.%s -b %d -r %s %s %s -U %s %s" % \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500279 (self.fstype, rootfs_size * 1024, rootfs_dir, label_str,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400280 self.mkfs_extraopts, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500281 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
282
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500283 def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
284 native_sysroot, pseudo):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500285 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500286 Prepare content for a msdos/vfat rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500287 """
288 du_cmd = "du -bks %s" % rootfs_dir
289 out = exec_cmd(du_cmd)
290 blocks = int(out.split()[0])
291
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500292 rootfs_size = self.get_rootfs_size(blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500294 label_str = "-n boot"
295 if self.label:
296 label_str = "-n %s" % self.label
297
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298 size_str = ""
299 if self.fstype == 'msdos':
300 size_str = "-F 16" # FAT 16
301
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500302 extraopts = self.mkfs_extraopts or '-S 512'
303
Brad Bishop316dfdd2018-06-25 12:45:53 -0400304 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
305 (label_str, self.fsuuid, size_str, extraopts, rootfs,
Brad Bishopc342db32019-05-15 21:57:59 -0400306 rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500307 exec_native_cmd(dosfs_cmd, native_sysroot)
308
309 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
310 exec_native_cmd(mcopy_cmd, native_sysroot)
311
312 chmod_cmd = "chmod 644 %s" % rootfs
313 exec_cmd(chmod_cmd)
314
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500315 prepare_rootfs_vfat = prepare_rootfs_msdos
316
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500317 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
318 native_sysroot, pseudo):
319 """
320 Prepare content for a squashfs rootfs partition.
321 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500322 extraopts = self.mkfs_extraopts or '-noappend'
323 squashfs_cmd = "mksquashfs %s %s %s" % \
324 (rootfs_dir, rootfs, extraopts)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500325 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
326
327 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
328 native_sysroot):
329 """
330 Prepare an empty ext2/3/4 partition.
331 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332 size = self.disk_size
333 with open(rootfs, 'w') as sparse:
334 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500335
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500336 extraopts = self.mkfs_extraopts or "-i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500337
338 label_str = ""
339 if self.label:
340 label_str = "-L %s" % self.label
341
Brad Bishop316dfdd2018-06-25 12:45:53 -0400342 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
343 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500344 exec_native_cmd(mkfs_cmd, native_sysroot)
345
346 def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
347 native_sysroot):
348 """
349 Prepare an empty btrfs partition.
350 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 size = self.disk_size
352 with open(rootfs, 'w') as sparse:
353 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500354
355 label_str = ""
356 if self.label:
357 label_str = "-L %s" % self.label
358
Brad Bishop316dfdd2018-06-25 12:45:53 -0400359 mkfs_cmd = "mkfs.%s -b %d %s -U %s %s %s" % \
360 (self.fstype, self.size * 1024, label_str, self.fsuuid,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500361 self.mkfs_extraopts, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500362 exec_native_cmd(mkfs_cmd, native_sysroot)
363
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 def prepare_empty_partition_msdos(self, rootfs, oe_builddir,
365 native_sysroot):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500366 """
367 Prepare an empty vfat partition.
368 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500369 blocks = self.disk_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500370
371 label_str = "-n boot"
372 if self.label:
373 label_str = "-n %s" % self.label
374
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500375 size_str = ""
376 if self.fstype == 'msdos':
377 size_str = "-F 16" # FAT 16
378
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500379 extraopts = self.mkfs_extraopts or '-S 512'
380
Brad Bishop316dfdd2018-06-25 12:45:53 -0400381 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
382 (label_str, self.fsuuid, extraopts, size_str, rootfs,
383 blocks)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500384
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500385 exec_native_cmd(dosfs_cmd, native_sysroot)
386
387 chmod_cmd = "chmod 644 %s" % rootfs
388 exec_cmd(chmod_cmd)
389
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500390 prepare_empty_partition_vfat = prepare_empty_partition_msdos
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500391
392 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
393 """
394 Prepare a swap partition.
395 """
396 path = "%s/fs.%s" % (cr_workdir, self.fstype)
397
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500398 with open(path, 'w') as sparse:
399 os.ftruncate(sparse.fileno(), self.size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500400
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500401 label_str = ""
402 if self.label:
403 label_str = "-L %s" % self.label
Brad Bishop316dfdd2018-06-25 12:45:53 -0400404
405 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500406 exec_native_cmd(mkswap_cmd, native_sysroot)