diff options
author | Andrea Righi <andrea.righi@canonical.com> | 2019-08-13 17:23:19 +0200 |
---|---|---|
committer | Andrea Righi <andrea.righi@canonical.com> | 2019-08-14 12:02:52 +0200 |
commit | 23fb9a86fc5aab0c48ccd76bc06b56fd08f912c5 (patch) | |
tree | 79b96b0888f917cd4b95e95599e7e092d81d4c1e | |
parent | 538f1e756139a6b57a4780e7ceb3ac6bcaa4fe6f (diff) | |
download | virtme-23fb9a86fc5aab0c48ccd76bc06b56fd08f912c5.tar.gz |
virtme-run: provide a way to support modules with --kdir
When --kdir is provided there's not an easy and automated way to use
kernel modules from the guest.
A possible solution could be to install all the modules inside the
kernel build directory (argument of --kdir) inside a temporary directory
.tmp_moddir/ as following:
$ make modules_install INSTALL_MOD_DIR=.tmp_moddir
In this way if .tmp_moddir is found the guest can use the kernel modules
from this directory, otherwise fallback to the old behavior and do not
provide an automated way to access the kernel modules.
TODO: document this .tmp_moddir/ directory somewhere.
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
-rw-r--r-- | virtme/commands/run.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/virtme/commands/run.py b/virtme/commands/run.py index c40e225..407f445 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -118,6 +118,11 @@ def arg_fail(message): _ARGPARSER.print_usage() sys.exit(1) +def get_kver_from_kdir(kdir): + kver_path = os.path.join(kdir, 'include/config/kernel.release') + with open(kver_path) as fd: + return fd.read().strip() + def find_kernel_and_mods(arch, args): if args.installed_kernel is not None: kver = args.installed_kernel @@ -130,13 +135,16 @@ def find_kernel_and_mods(arch, args): dtb = None # For now elif args.kdir is not None: kimg = os.path.join(args.kdir, arch.kimg_path()) - modfiles = [] - moddir = None - - # Once kmod gets fixed (if ever), we can do something like: - # modfiles = modfinder.find_modules_from_install( - # virtmods.MODALIASES, - # moddir=os.path.join(args.kernel_build_dir, '.tmp_moddir')) + tmp_moddir = os.path.join(args.kdir, '.tmp_moddir') + if os.path.exists(tmp_moddir): + kver = get_kver_from_kdir(args.kdir) + moddir = os.path.join(tmp_moddir, 'lib/modules', kver) + modfiles = modfinder.find_modules_from_install( + virtmods.MODALIASES, kver=kver) + else: + kver = None + moddir = None + modfiles = [] dtb_path = arch.dtb_path() if dtb_path is None: |