The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/280

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This ensures that the VM directory and loop device are unmounted before
creating the image.

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From fd97da5615893036a0c0e0291b19d9b1e65a46b9 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 19 Feb 2020 08:37:28 +0100
Subject: [PATCH] vm: Ensure loop device is unmounted before creating image

This ensures that the VM directory and loop device are unmounted before
creating the image.

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 distrobuilder/main_lxd.go | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/distrobuilder/main_lxd.go b/distrobuilder/main_lxd.go
index 38efc123..59ca2e22 100644
--- a/distrobuilder/main_lxd.go
+++ b/distrobuilder/main_lxd.go
@@ -203,9 +203,11 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string, 
overlayDir string) error
 
        rootfsDir := overlayDir
        var mounts []shared.ChrootMount
+       var vmDir string
+       var vm *vm
 
        if c.flagVM {
-               vmDir := filepath.Join(c.global.flagCacheDir, "vm")
+               vmDir = filepath.Join(c.global.flagCacheDir, "vm")
 
                err := os.Mkdir(vmDir, 0755)
                if err != nil {
@@ -219,7 +221,7 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string, 
overlayDir string) error
 
                imgFile := filepath.Join(c.global.flagCacheDir, imgFilename)
 
-               vm, err := newVM(imgFile, vmDir, 
c.global.definition.Targets.LXD.VM.Filesystem, 
c.global.definition.Targets.LXD.VM.Size)
+               vm, err = newVM(imgFile, vmDir, 
c.global.definition.Targets.LXD.VM.Filesystem, 
c.global.definition.Targets.LXD.VM.Size)
                if err != nil {
                        return errors.Wrap(err, "Failed to instanciate VM")
                }
@@ -249,12 +251,12 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string, 
overlayDir string) error
                if err != nil {
                        return errors.Wrap(err, "failed to mount root partion")
                }
+               defer lxd.RunCommand("umount", "-R", vmDir)
 
                err = vm.createUEFIFS()
                if err != nil {
                        return errors.Wrap(err, "Failed to create UEFI 
filesystem")
                }
-               defer lxd.RunCommand("umount", "-R", vmDir)
 
                err = vm.mountUEFIPartition()
                if err != nil {
@@ -299,6 +301,19 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string, 
overlayDir string) error
 
        exitChroot()
 
+       // Unmount VM directory and loop device before creating the image.
+       if c.flagVM {
+               _, err := lxd.RunCommand("umount", "-R", vmDir)
+               if err != nil {
+                       return err
+               }
+
+               err = vm.umountImage()
+               if err != nil {
+                       return err
+               }
+       }
+
        err = img.Build(c.flagType == "unified", c.flagCompression, c.flagVM)
        if err != nil {
                return fmt.Errorf("Failed to create LXD image: %s", err)
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to