mirror of
https://github.com/rancher/os.git
synced 2025-07-02 01:31:48 +00:00
Merge pull request #1716 from rancher/alpine-install
fix for alpine's simpler blkid cmd
This commit is contained in:
commit
2a8d8fa891
@ -336,7 +336,11 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
func mountBootIso() error {
|
func mountBootIso() error {
|
||||||
deviceName := "/dev/sr0"
|
deviceName := "/dev/sr0"
|
||||||
deviceType := "iso9660"
|
deviceType := "iso9660"
|
||||||
{ // force the defer
|
if d, t := util.Blkid("RancherOS"); d != "" {
|
||||||
|
deviceName = d
|
||||||
|
deviceType = t
|
||||||
|
}
|
||||||
|
|
||||||
mountsFile, err := os.Open("/proc/mounts")
|
mountsFile, err := os.Open("/proc/mounts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to read /proc/mounts %s", err)
|
log.Errorf("failed to read /proc/mounts %s", err)
|
||||||
@ -347,37 +351,10 @@ func mountBootIso() error {
|
|||||||
if partitionMounted(deviceName, mountsFile) {
|
if partitionMounted(deviceName, mountsFile) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
os.MkdirAll("/bootiso", 0755)
|
os.MkdirAll("/bootiso", 0755)
|
||||||
|
cmd := exec.Command("mount", "-t", deviceType, deviceName, "/bootiso")
|
||||||
// find the installation device
|
log.Infof("mount (%#v)", cmd)
|
||||||
cmd := exec.Command("blkid", "-L", "RancherOS")
|
|
||||||
log.Debugf("Run(%v)", cmd)
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
out, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to get RancherOS boot device: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
deviceName = strings.TrimSpace(string(out))
|
|
||||||
log.Debugf("blkid found -L RancherOS: %s", deviceName)
|
|
||||||
|
|
||||||
cmd = exec.Command("blkid", deviceName)
|
|
||||||
log.Debugf("Run(%v)", cmd)
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if out, err = cmd.Output(); err != nil {
|
|
||||||
log.Errorf("Failed to get RancherOS boot device type: %s", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
deviceType = strings.TrimSpace(string(out))
|
|
||||||
s1 := strings.Split(deviceType, "TYPE=\"")
|
|
||||||
s2 := strings.Split(s1[1], "\"")
|
|
||||||
deviceType = s2[0]
|
|
||||||
log.Debugf("blkid type of %s: %s", deviceName, deviceType)
|
|
||||||
|
|
||||||
cmd = exec.Command("mount", "-t", deviceType, deviceName, "/bootiso")
|
|
||||||
log.Debugf("Run(%v)", cmd)
|
|
||||||
|
|
||||||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
@ -750,27 +727,21 @@ func mountdevice(baseName, bootDir, partition string, raw bool) (string, string,
|
|||||||
// Don't use ResolveDevice - it can fail, whereas `blkid -L LABEL` works more often
|
// Don't use ResolveDevice - it can fail, whereas `blkid -L LABEL` works more often
|
||||||
|
|
||||||
cfg := config.LoadConfig()
|
cfg := config.LoadConfig()
|
||||||
cmd := exec.Command("blkid", "-L", "RANCHER_BOOT")
|
if d, _ := util.Blkid("RANCHER_BOOT"); d != "" {
|
||||||
log.Debugf("Run(%v)", cmd)
|
partition = d
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if out, err := cmd.Output(); err == nil {
|
|
||||||
partition = strings.TrimSpace(string(out))
|
|
||||||
baseName = filepath.Join(baseName, "boot")
|
baseName = filepath.Join(baseName, "boot")
|
||||||
} else {
|
} else {
|
||||||
if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" {
|
if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" {
|
||||||
// try the rancher.state.dev setting
|
// try the rancher.state.dev setting
|
||||||
partition = dev
|
partition = dev
|
||||||
} else {
|
} else {
|
||||||
cmd := exec.Command("blkid", "-L", "RANCHER_STATE")
|
if d, _ := util.Blkid("RANCHER_STATE"); d != "" {
|
||||||
log.Debugf("Run(%v)", cmd)
|
partition = d
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if out, err := cmd.Output(); err == nil {
|
|
||||||
partition = strings.TrimSpace(string(out))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
device := ""
|
device := ""
|
||||||
cmd = exec.Command("lsblk", "-no", "pkname", partition)
|
cmd := exec.Command("lsblk", "-no", "pkname", partition)
|
||||||
log.Debugf("Run(%v)", cmd)
|
log.Debugf("Run(%v)", cmd)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if out, err := cmd.Output(); err == nil {
|
if out, err := cmd.Output(); err == nil {
|
||||||
|
@ -80,3 +80,40 @@ sync
|
|||||||
// TEST parted output? (gpt non-uefi == legacy_boot)
|
// TEST parted output? (gpt non-uefi == legacy_boot)
|
||||||
s.Stop(c)
|
s.Stop(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *QemuSuite) TestInstallAlpine(c *C) {
|
||||||
|
// ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
|
||||||
|
runArgs := []string{
|
||||||
|
"--iso",
|
||||||
|
"--fresh",
|
||||||
|
}
|
||||||
|
version := ""
|
||||||
|
{
|
||||||
|
s.RunQemuWith(c, runArgs...)
|
||||||
|
|
||||||
|
s.MakeCall("sudo ros console switch -f alpine")
|
||||||
|
c.Assert(s.WaitForSSH(), IsNil)
|
||||||
|
|
||||||
|
version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
|
||||||
|
fmt.Printf("installing %s", version)
|
||||||
|
|
||||||
|
s.CheckCall(c, `
|
||||||
|
set -ex
|
||||||
|
echo "ssh_authorized_keys:" > config.yml
|
||||||
|
echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
|
||||||
|
sudo ros install --force --no-reboot --device /dev/vda -c config.yml
|
||||||
|
sync
|
||||||
|
`)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
s.Stop(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ./scripts/run --no-format --append "rancher.debug=true"
|
||||||
|
runArgs = []string{
|
||||||
|
"--boothd",
|
||||||
|
}
|
||||||
|
s.RunQemuWith(c, runArgs...)
|
||||||
|
|
||||||
|
s.CheckOutput(c, version, Equals, "sudo ros -v")
|
||||||
|
s.Stop(c)
|
||||||
|
}
|
||||||
|
@ -3,10 +3,15 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/mount"
|
"github.com/docker/docker/pkg/mount"
|
||||||
|
"github.com/rancher/os/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mountProc() error {
|
func mountProc() error {
|
||||||
@ -43,3 +48,32 @@ func Mount(device, directory, fsType, options string) error {
|
|||||||
func Unmount(target string) error {
|
func Unmount(target string) error {
|
||||||
return mount.Unmount(target)
|
return mount.Unmount(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Blkid(label string) (deviceName, deviceType string) {
|
||||||
|
// Not all blkid's have `blkid -L label (see busybox/alpine)
|
||||||
|
cmd := exec.Command("blkid")
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to run blkid: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r := bytes.NewReader(out)
|
||||||
|
s := bufio.NewScanner(r)
|
||||||
|
for s.Scan() {
|
||||||
|
line := s.Text()
|
||||||
|
log.Debugf("blkid: %s", cmd, line)
|
||||||
|
if !strings.Contains(line, `LABEL="`+label+`"`) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
d := strings.Split(line, ":")
|
||||||
|
deviceName = d[0]
|
||||||
|
|
||||||
|
s1 := strings.Split(line, `TYPE="`)
|
||||||
|
s2 := strings.Split(s1[1], `"`)
|
||||||
|
deviceType = s2[0]
|
||||||
|
log.Debugf("blkid type of %s: %s", deviceName, deviceType)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user