From ec14875a8531be3a9b814066a7393513677d2182 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 18 Nov 2019 14:27:31 +1300 Subject: [PATCH] if /target exists, run curtin umount /target before first disk probe The installer now lets you restart after an install failure, but unless we do something like this, the target system still being mounted will make life confusing. It's more robust to be defensive and try to unmount at startup rather than trying to unmount before restarting. --- subiquity/controllers/filesystem.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index add0c7c2..33c31a47 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -18,6 +18,7 @@ import json import logging import os import select +import sys import time import pyudev @@ -144,12 +145,29 @@ class FilesystemController(BaseController): self._probes = {} def start(self): - self._start_probe(restricted=False) + self._start_probe(restricted=False, start=False) + target = self.app.base_model.target + if os.path.exists(target): + self.run_in_bg(self._bg_unmount, self._unmounted) + else: + self._cur_probe.start() + + def _bg_unmount(self): + cmd = [ + sys.executable, '-m', 'curtin', 'unmount', + '-t', self.app.base_model.target, + ] + if self.opts.dry_run: + cmd = ['sleep', 0.2] + run_command(cmd) + + def _unmounted(self, fut): context = pyudev.Context() self._monitor = pyudev.Monitor.from_netlink(context) self._monitor.filter_by(subsystem='block') self._monitor.enable_receiving() self.start_listening_udev() + self._cur_probe.start() def start_listening_udev(self): self._udev_listen_handle = self.loop.watch_file( @@ -178,10 +196,11 @@ class FilesystemController(BaseController): log.debug("_udev_event %s %s", action, dev) self._start_probe(restricted=False) - def _start_probe(self, *, restricted=False): + def _start_probe(self, *, restricted, start=True): p = Probe(self, restricted, 5.0, self._probe_done) self._cur_probe = self._probes[restricted] = p - p.start() + if start: + p.start() def _probe_done(self, probe): if probe is not self._cur_probe: