[lxc-devel] [distrobuilder/master] vm: Handle loop partitions inside containers
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Thu Feb 20 15:08:20 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200220/b6c94d1c/attachment.bin>
-------------- next part --------------
From 646e9f5eb0574a49d7b28004bc2d619d6ced0852 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at 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.hipp at 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
More information about the lxc-devel
mailing list