54
68
for (key, info) in cfg.get('write_files').items():
55
69
if not info.get('path'):
56
70
LOG.warn("Warning, write_files[%s] had no 'path' entry", key)
58
73
futil.write_finfo(path=target + os.path.sep + info['path'],
59
74
content=info.get('content', ''),
60
75
owner=info.get('owner', "-1:-1"),
61
perms=info.get('perms', "0644"))
76
perms=info.get('permissions',
77
info.get('perms', "0644")))
64
80
def apt_config(cfg, target):
120
136
os.unlink(dpkg_cfg)
139
def install_kernel(cfg, target):
140
kernel_cfg = cfg.get('kernel', {'package': None,
141
'fallback-package': None,
144
with util.RunInChroot(target) as in_chroot:
145
if kernel_cfg is not None:
146
kernel_package = kernel_cfg.get('package')
147
kernel_fallback = kernel_cfg.get('fallback-package')
149
kernel_package = None
150
kernel_fallback = None
153
util.install_packages([kernel_package], target=target)
156
_, _, kernel, _, _ = os.uname()
157
out, _ = in_chroot(['lsb_release', '--codename', '--short'],
159
version, _, flavor = kernel.split('-', 2)
160
config.merge_config(kernel_cfg['mapping'], KERNEL_MAPPING)
163
map_suffix = kernel_cfg['mapping'][out.strip()][version]
165
LOG.warn("Couldn't detect kernel package to install for %s."
167
if kernel_fallback is not None:
168
util.install_packages([kernel_fallback])
171
package = "linux-{flavor}{map_suffix}".format(
172
flavor=flavor, map_suffix=map_suffix)
173
out, _ = in_chroot(['apt-cache', 'search', package], capture=True)
174
if (len(out.strip()) > 0 and
175
not util.has_pkg_installed(package, target)):
176
util.install_packages([package], target=target)
178
LOG.warn("Tried to install kernel %s but package not found."
180
if kernel_fallback is not None:
181
util.install_packages([kernel_fallback], target=target)
123
184
def apply_debconf_selections(cfg, target):
124
185
# debconf_selections:
202
263
def setup_grub(cfg, target):
203
if 'grub_install_devices' in cfg:
204
instdevs = cfg.get('grub_install_devices')
264
grubcfg = cfg.get('grub', {})
266
# copy legacy top level name
267
if 'grub_install_devices' in cfg and 'install_devices' not in grubcfg:
268
grubcfg['install_devices'] = cfg['grub_install_devices']
270
if 'install_devices' in grubcfg:
271
instdevs = grubcfg.get('install_devices')
205
272
if isinstance(instdevs, str):
206
273
instdevs = [instdevs]
207
274
if instdevs is None:
216
283
instdevs = list(blockdevs)
285
env = os.environ.copy()
287
replace_default = grubcfg.get('replace_linux_default', True)
288
if str(replace_default).lower() in ("0", "false"):
289
env['REPLACE_GRUB_LINUX_DEFAULT'] = "0"
291
env['REPLACE_GRUB_LINUX_DEFAULT'] = "1"
218
293
instdevs = [block.get_dev_name_entry(i)[1] for i in instdevs]
219
LOG.debug("installing grub to %s", instdevs)
294
LOG.debug("installing grub to %s [replace_default=%s]",
295
instdevs, replace_default)
220
296
with util.ChrootableTarget(target):
221
util.subp(['install-grub', target] + instdevs)
297
util.subp(['install-grub', target] + instdevs, env=env)
300
def update_initramfs(target):
301
with util.RunInChroot(target) as in_chroot:
302
in_chroot(['update-initramfs', '-u'])
224
305
def copy_fstab(fstab, target):
261
342
target = state['target']
263
if args.config is not None:
264
cfg_file = args.config
266
cfg_file = state['config']
268
344
if target is None:
269
345
sys.stderr.write("Unable to find target. "
270
346
"Use --target or set TARGET_MOUNT_POINT\n")
274
LOG.debug("config file was none!")
277
cfg = config.load_config(cfg_file)
349
cfg = util.load_command_config(args, state)
279
351
write_files(cfg, target)
280
352
apt_config(cfg, target)
281
353
disable_overlayroot(cfg, target)
354
install_kernel(cfg, target)
282
355
apply_debconf_selections(cfg, target)
284
357
restore_dist_interfaces(cfg, target)
286
359
copy_interfaces(state.get('interfaces'), target)
287
360
copy_fstab(state.get('fstab'), target)
288
setup_grub(cfg, target)
362
# As a rule, ARMv7 systems don't use grub. This may change some
363
# day, but for now, assume no. They do require the initramfs
364
# to be updated, and this also triggers boot loader setup via
366
machine = platform.machine()
367
if machine.startswith('armv7'):
368
update_initramfs(target)
370
setup_grub(cfg, target)