[lxc-devel] [distrobuilder/master] sources/oracle: Fix Oracle Linux 8
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Thu Oct 24 06:14:29 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 385 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191023/700899d0/attachment.bin>
-------------- next part --------------
From 0fe7d9f189090844836eb6965aca2804a5c9b4cb Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 24 Oct 2019 08:13:01 +0200
Subject: [PATCH] sources/oracle: Fix Oracle Linux 8
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
sources/oraclelinux-http.go | 47 +++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 10 deletions(-)
diff --git a/sources/oraclelinux-http.go b/sources/oraclelinux-http.go
index e02564a..4906455 100644
--- a/sources/oraclelinux-http.go
+++ b/sources/oraclelinux-http.go
@@ -2,12 +2,12 @@ package sources
import (
"fmt"
+ "io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
- "syscall"
lxd "github.com/lxc/lxd/shared"
"golang.org/x/sys/unix"
@@ -84,12 +84,6 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er
}
- err = shared.RunCommand("mount", "-o", "ro", rootfsImage, roRootDir)
- if err != nil {
- return err
- }
- defer syscall.Unmount(roRootDir, 0)
-
// Remove rootfsDir otherwise rsync will copy the content into the directory
// itself
err = os.RemoveAll(rootfsDir)
@@ -97,9 +91,7 @@ func (s *OracleLinuxHTTP) unpackISO(latestUpdate, filePath, rootfsDir string) er
return err
}
- // Since roRootDir is read-only, we need to copy it to a temporary rootfs
- // directory in order to create the minimal rootfs.
- err = shared.RunCommand("rsync", "-qa", roRootDir+"/", tempRootDir)
+ err = s.unpackRootfsImage(rootfsImage, tempRootDir)
if err != nil {
return err
}
@@ -277,3 +269,38 @@ func (s *OracleLinuxHTTP) getLatestUpdate(URL string) (string, error) {
return strings.TrimSuffix(latestUpdate, "/"), nil
}
+
+func (s OracleLinuxHTTP) unpackRootfsImage(imageFile string, target string) error {
+ installDir, err := ioutil.TempDir(filepath.Join(os.TempDir(), "distrobuilder"), "temp_")
+ if err != nil {
+ return err
+ }
+ defer os.RemoveAll(installDir)
+
+ err = shared.RunCommand("mount", "-o", "ro", imageFile, installDir)
+ if err != nil {
+ return err
+ }
+ defer unix.Unmount(installDir, 0)
+
+ rootfsDir := installDir
+ rootfsFile := filepath.Join(installDir, "LiveOS", "rootfs.img")
+
+ if lxd.PathExists(rootfsFile) {
+ rootfsDir, err = ioutil.TempDir(filepath.Join(os.TempDir(), "distrobuilder"), "temp_")
+ if err != nil {
+ return err
+ }
+ defer os.RemoveAll(rootfsDir)
+
+ err = shared.RunCommand("mount", "-o", "ro", rootfsFile, rootfsDir)
+ if err != nil {
+ return err
+ }
+ defer unix.Unmount(rootfsFile, 0)
+ }
+
+ // Since rootfs is read-only, we need to copy it to a temporary rootfs
+ // directory in order to create the minimal rootfs.
+ return shared.RunCommand("rsync", "-qa", rootfsDir+"/", target)
+}
More information about the lxc-devel
mailing list