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

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 fixes some issues with the CentOS raw images.
From a15de2177851980861ce32594e2dcbec9f764212 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Mon, 23 Sep 2019 21:25:47 +0200
Subject: [PATCH 1/2] sources: Figure out partion offset from fdisk

This removes the hard-coded offset and instead gets it from fdisk.

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 sources/centos-http.go | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/sources/centos-http.go b/sources/centos-http.go
index dc3afd6..7812420 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -1,6 +1,7 @@
 package sources
 
 import (
+       "bytes"
        "crypto/sha256"
        "errors"
        "fmt"
@@ -118,8 +119,24 @@ func (s CentOSHTTP) unpackRaw(filePath, rootfsDir string) 
error {
 
        rawFilePath := strings.TrimSuffix(filePath, ".xz")
 
+       // Figure out the offset
+       var buf bytes.Buffer
+
+       err := lxd.RunCommandWithFds(nil, &buf, "fdisk", "-l", "-o", "Start", 
rawFilePath)
+       if err != nil {
+               return err
+       }
+
+       output := strings.Split(buf.String(), "\n")
+       offsetStr := strings.TrimSpace(output[len(output)-2])
+
+       offset, err := strconv.Atoi(offsetStr)
+       if err != nil {
+               return err
+       }
+
        // Mount the partition read-only since we don't want to accidently 
modify it.
-       err := shared.RunCommand("mount", "-o", "ro,loop,offset=1048576",
+       err = shared.RunCommand("mount", "-o", fmt.Sprintf("ro,loop,offset=%d", 
offset*512),
                rawFilePath, roRootDir)
        if err != nil {
                return err

From f4b0e54e09929db5d51944a0365dc3a19a811cde Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Mon, 23 Sep 2019 21:30:11 +0200
Subject: [PATCH 2/2] shared,sources: Fix CentOS raw image handling

This fixes the path of the downloaded raw image. It will an existing
image if present instead of downloading it again.

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 shared/net.go          | 4 +---
 shared/util.go         | 8 ++++++++
 sources/centos-http.go | 9 ++++++---
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/shared/net.go b/shared/net.go
index f167d8d..aa16210 100644
--- a/shared/net.go
+++ b/shared/net.go
@@ -24,9 +24,7 @@ func DownloadHash(def DefinitionImage, file, checksum string, 
hashFunc hash.Hash
                hash   string
                err    error
        )
-       targetDir := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s-%s", 
def.Distribution, def.Release, def.ArchitectureMapped))
-       targetDir = strings.Replace(targetDir, " ", "", -1)
-       targetDir = strings.ToLower(targetDir)
+       targetDir := GetTargetDir(def)
 
        err = os.MkdirAll(targetDir, 0755)
        if err != nil {
diff --git a/shared/util.go b/shared/util.go
index 6a49d6f..32f5ab7 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -356,3 +356,11 @@ func SetEnvVariables(env Environment) Environment {
 
        return oldEnv
 }
+
+func GetTargetDir(def DefinitionImage) string {
+       targetDir := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s-%s", 
def.Distribution, def.Release, def.ArchitectureMapped))
+       targetDir = strings.Replace(targetDir, " ", "", -1)
+       targetDir = strings.ToLower(targetDir)
+
+       return targetDir
+}
diff --git a/sources/centos-http.go b/sources/centos-http.go
index 7812420..0bde872 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -12,6 +12,7 @@ import (
        "path"
        "path/filepath"
        "regexp"
+       "strconv"
        "strings"
        "syscall"
 
@@ -44,13 +45,15 @@ func (s *CentOSHTTP) Run(definition shared.Definition, 
rootfsDir string) error {
                return fmt.Errorf("Couldn't get name of iso")
        }
 
+       fpath := shared.GetTargetDir(definition.Image)
+
        // Skip download if raw image exists and has already been decompressed.
        if strings.HasSuffix(s.fname, ".raw.xz") {
-               imagePath := filepath.Join(os.TempDir(), 
filepath.Base(strings.TrimSuffix(s.fname, ".xz")))
+               imagePath := filepath.Join(fpath, 
filepath.Base(strings.TrimSuffix(s.fname, ".xz")))
 
                stat, err := os.Stat(imagePath)
                if err == nil && stat.Size() > 0 {
-                       return s.unpackRaw(filepath.Join(os.TempDir(), 
strings.TrimSuffix(s.fname, ".xz")),
+                       return s.unpackRaw(filepath.Join(fpath, 
strings.TrimSuffix(s.fname, ".xz")),
                                rootfsDir)
                }
        }
@@ -90,7 +93,7 @@ func (s *CentOSHTTP) Run(definition shared.Definition, 
rootfsDir string) error {
                }
        }
 
-       fpath, err := shared.DownloadHash(definition.Image, baseURL+s.fname, 
checksumFile, sha256.New())
+       _, err = shared.DownloadHash(definition.Image, baseURL+s.fname, 
checksumFile, sha256.New())
        if err != nil {
                return fmt.Errorf("Error downloading CentOS image: %s", err)
        }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to