[lxc-devel] [distrobuilder/master] sources: Use fdisk instead of kpartx

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Jul 8 11:03:39 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 386 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190708/4800bf54/attachment.bin>
-------------- next part --------------
From 0f218398f1196ffc248667bc31c6928e6b4901e1 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 8 Jul 2019 12:38:44 +0200
Subject: [PATCH] sources: Use fdisk instead of kpartx

This resolves #190

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 sources/ubuntu-http.go | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/sources/ubuntu-http.go b/sources/ubuntu-http.go
index 9caad58..40bd6cd 100644
--- a/sources/ubuntu-http.go
+++ b/sources/ubuntu-http.go
@@ -11,6 +11,7 @@ import (
 	"os"
 	"path/filepath"
 	"regexp"
+	"strconv"
 	"strings"
 
 	"github.com/gobuffalo/packr/v2"
@@ -93,20 +94,18 @@ func (s *UbuntuHTTP) runCoreVariant(definition shared.Definition, rootfsDir stri
 	s.fname = strings.TrimSuffix(s.fname, ".xz")
 	f = filepath.Join(s.fpath, s.fname)
 
-	output, err := lxd.RunCommand("kpartx", "-a", "-v", f)
+	output, err := lxd.RunCommand("fdisk", "-l", "-o", "Start", f)
 	if err != nil {
 		return err
 	}
-	defer lxd.RunCommand("kpartx", "-d", f)
 
 	lines := strings.Split(output, "\n")
 
-	if len(lines) < 3 {
-		return fmt.Errorf("Failed to mount core image")
+	offset, err := strconv.Atoi(lines[len(lines)-2])
+	if err != nil {
+		return err
 	}
 
-	rootPartition := filepath.Join("/dev", "mapper", strings.Split(lines[2], " ")[2])
-
 	imageDir := filepath.Join(os.TempDir(), "distrobuilder", "image")
 	snapsDir := filepath.Join(os.TempDir(), "distrobuilder", "snaps")
 	baseImageDir := fmt.Sprintf("%s.base", rootfsDir)
@@ -117,7 +116,7 @@ func (s *UbuntuHTTP) runCoreVariant(definition shared.Definition, rootfsDir stri
 	defer os.RemoveAll(filepath.Join(os.TempDir(), "distrobuilder"))
 	defer os.RemoveAll(filepath.Join(baseImageDir, "rootfs"))
 
-	err = shared.RunCommand("mount", rootPartition, imageDir)
+	err = shared.RunCommand("mount", "-o", fmt.Sprintf("loop,offset=%d", offset*512), f, imageDir)
 	if err != nil {
 		return err
 	}


More information about the lxc-devel mailing list