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

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) ===
Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From 646e9f5eb0574a49d7b28004bc2d619d6ced0852 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Thu, 20 Feb 2020 14:31:07 +0100
Subject: [PATCH] vm: Handle loop partitions inside containers

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 distrobuilder/vm.go | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/distrobuilder/vm.go b/distrobuilder/vm.go
index 056d705d..de46700b 100644
--- a/distrobuilder/vm.go
+++ b/distrobuilder/vm.go
@@ -103,6 +103,34 @@ func (v *vm) mountImage() error {
 
        v.loopDevice = strings.TrimSpace(stdout)
 
+       // Ensure the partitions are accessible. This part is usually only 
needed
+       // if building inside of a container.
+
+       out, err := lxd.RunCommand("lsblk", "--raw", "--output", "MAJ:MIN", 
"--noheadings", v.loopDevice)
+       if err != nil {
+               return err
+       }
+
+       deviceNumbers := strings.Split(out, "\n")
+
+       if !lxd.PathExists(v.getUEFIDevFile()) {
+               fields := strings.Split(deviceNumbers[1], ":")
+
+               err := shared.RunCommand("mknod", v.getUEFIDevFile(), "b", 
fields[0], fields[1])
+               if err != nil {
+                       return err
+               }
+       }
+
+       if !lxd.PathExists(v.getRootfsDevFile()) {
+               fields := strings.Split(deviceNumbers[2], ":")
+
+               err := shared.RunCommand("mknod", v.getRootfsDevFile(), "b", 
fields[0], fields[1])
+               if err != nil {
+                       return err
+               }
+       }
+
        return nil
 }
 
@@ -117,6 +145,21 @@ func (v *vm) umountImage() error {
                return err
        }
 
+       // Make sure that p1 and p2 are also removed.
+       if lxd.PathExists(v.getUEFIDevFile()) {
+               err := os.Remove(v.getUEFIDevFile())
+               if err != nil {
+                       return err
+               }
+       }
+
+       if lxd.PathExists(v.getRootfsDevFile()) {
+               err := os.Remove(v.getRootfsDevFile())
+               if err != nil {
+                       return err
+               }
+       }
+
        v.loopDevice = ""
 
        return nil
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to