1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 06:11:12 +00:00

Merge pull request #1558 from SvenDowideit/paths-are-relative-to-the-syslinux-dir

Fixes found working on packet.net upgrade
This commit is contained in:
Sven Dowideit
2017-01-28 01:00:20 +10:00
committed by GitHub
8 changed files with 86 additions and 79 deletions

View File

@@ -470,7 +470,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string, kexec bo
if err != nil {
return err
}
installSyslinuxRaid(baseName, bootDir, diskType)
installSyslinux(device, baseName, bootDir, diskType)
case "bootstrap":
CONSOLE = "ttyS0"
var err error
@@ -487,6 +487,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string, kexec bo
if err != nil {
return err
}
log.Infof("upgrading - %s, %s, %s, %s", device, baseName, bootDir, diskType)
// TODO: detect pv-grub, and don't kill it with syslinux
upgradeBootloader(device, baseName, bootDir, diskType)
default:
@@ -716,8 +717,7 @@ func formatdevice(device, partition string) error {
}
func mountdevice(baseName, bootDir, partition string, raw bool) (string, string, error) {
log.Debugf("mountdevice %s, raw %v", partition, raw)
device := ""
log.Infof("mountdevice %s, raw %v", partition, raw)
if raw {
log.Debugf("util.Mount (raw) %s, %s", partition, baseName)
@@ -725,6 +725,7 @@ func mountdevice(baseName, bootDir, partition string, raw bool) (string, string,
cmd := exec.Command("lsblk", "-no", "pkname", partition)
log.Debugf("Run(%v)", cmd)
cmd.Stderr = os.Stderr
device := ""
if out, err := cmd.Output(); err == nil {
device = "/dev/" + strings.TrimSpace(string(out))
}
@@ -740,6 +741,7 @@ func mountdevice(baseName, bootDir, partition string, raw bool) (string, string,
cmd.Stderr = os.Stderr
if out, err := cmd.Output(); err == nil {
partition = strings.TrimSpace(string(out))
baseName = filepath.Join(baseName, "boot")
} else {
cmd := exec.Command("blkid", "-L", "RANCHER_STATE")
log.Debugf("Run(%v)", cmd)
@@ -748,6 +750,7 @@ func mountdevice(baseName, bootDir, partition string, raw bool) (string, string,
partition = strings.TrimSpace(string(out))
}
}
device := ""
cmd = exec.Command("lsblk", "-no", "pkname", partition)
log.Debugf("Run(%v)", cmd)
cmd.Stderr = os.Stderr
@@ -824,25 +827,21 @@ func upgradeBootloader(device, baseName, bootDir, diskType string) error {
// TODO: in v0.9.0, need to detect what version syslinux we have
return nil
}
if err := setBootable(device, diskType); err != nil {
log.Debugf("setBootable(%s, %s): %s", device, diskType, err)
//return err
}
if err := os.Rename(grubDir, filepath.Join(baseName, bootDir+"grub_backup")); err != nil {
log.Debugf("Rename(%s): %s", grubDir, err)
log.Errorf("Rename(%s): %s", grubDir, err)
return err
}
syslinuxDir := filepath.Join(baseName, bootDir+"syslinux")
backupSyslinuxDir := filepath.Join(baseName, bootDir+"syslinux_backup")
if err := os.Rename(syslinuxDir, backupSyslinuxDir); err != nil {
log.Debugf("Rename(%s, %s): %s", syslinuxDir, backupSyslinuxDir, err)
log.Errorf("Rename(%s, %s): %s", syslinuxDir, backupSyslinuxDir, err)
return err
}
//mv the old syslinux into linux-previous.cfg
oldSyslinux, err := ioutil.ReadFile(filepath.Join(backupSyslinuxDir, "syslinux.cfg"))
if err != nil {
log.Debugf("read(%s / syslinux.cfg): %s", backupSyslinuxDir, err)
log.Errorf("read(%s / syslinux.cfg): %s", backupSyslinuxDir, err)
return err
}
@@ -853,16 +852,25 @@ func upgradeBootloader(device, baseName, bootDir, diskType string) error {
// LINUX ../vmlinuz-v0.7.1-rancheros
// APPEND rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=tty0 rancher.password=rancher
// INITRD ../initrd-v0.7.1-rancheros
cfg = strings.Replace(cfg, "current", "previous", -1)
cfg = strings.Replace(cfg, "../", "/boot/", -1)
// TODO consider removing the APPEND line - as the global.cfg should have the same result
ioutil.WriteFile(filepath.Join(baseName, bootDir, "linux-current.cfg"), []byte(cfg), 0644)
lines := strings.Split(cfg, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "APPEND") {
// TODO: need to append any extra's the user specified
ioutil.WriteFile(filepath.Join(baseName, bootDir, "global.cfg"), []byte(cfg), 0644)
break
}
}
return installSyslinux(device, baseName, bootDir, diskType)
}
func installSyslinux(device, baseName, bootDir, diskType string) error {
log.Debugf("installSyslinux")
mbrFile := "mbr.bin"
if diskType == "gpt" {
@@ -872,12 +880,43 @@ func installSyslinux(device, baseName, bootDir, diskType string) error {
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${device}
// ubuntu: /usr/lib/syslinux/mbr/mbr.bin
// alpine: /usr/share/syslinux/mbr.bin
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of="+device)
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
log.Debugf("Run(%v)", cmd)
if err := cmd.Run(); err != nil {
log.Errorf("dd: %s", err)
return err
if device == "/dev/" {
log.Infof("installSyslinuxRaid(%s)", device)
//RAID - assume sda&sdb
//TODO: fix this - not sure how to detect what disks should have mbr - perhaps we need a param
// perhaps just assume and use the devices that make up the raid - mdadm
device = "/dev/sda"
if err := setBootable(device, diskType); err != nil {
log.Errorf("setBootable(%s, %s): %s", device, diskType, err)
//return err
}
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of="+device)
if err := cmd.Run(); err != nil {
log.Errorf("%s", err)
return err
}
device = "/dev/sdb"
if err := setBootable(device, diskType); err != nil {
log.Errorf("setBootable(%s, %s): %s", device, diskType, err)
//return err
}
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of="+device)
if err := cmd.Run(); err != nil {
log.Errorf("%s", err)
return err
}
} else {
if err := setBootable(device, diskType); err != nil {
log.Errorf("setBootable(%s, %s): %s", device, diskType, err)
//return err
}
log.Infof("installSyslinux(%s)", device)
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of="+device)
log.Debugf("Run(%v)", cmd)
if err := cmd.Run(); err != nil {
log.Errorf("dd: %s", err)
return err
}
}
if err := os.MkdirAll(filepath.Join(baseName, bootDir+"syslinux"), 0755); err != nil {
return err
@@ -896,55 +935,15 @@ func installSyslinux(device, baseName, bootDir, diskType string) error {
}
//extlinux --install ${baseName}/${bootDir}syslinux
cmd = exec.Command("extlinux", "--install", filepath.Join(baseName, bootDir+"syslinux"))
cmd := exec.Command("extlinux", "--install", filepath.Join(baseName, bootDir+"syslinux"))
if device == "/dev/" {
//extlinux --install --raid ${baseName}/${bootDir}syslinux
cmd = exec.Command("extlinux", "--install", "--raid", filepath.Join(baseName, bootDir+"syslinux"))
}
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
log.Debugf("Run(%v)", cmd)
if err := cmd.Run(); err != nil {
log.Errorf("extlinuux: %s", err)
return err
}
return nil
}
func installSyslinuxRaid(baseName, bootDir, diskType string) error {
log.Debugf("installSyslinuxRaid")
mbrFile := "mbr.bin"
if diskType == "gpt" {
mbrFile = "gptmbr.bin"
}
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdb
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
//extlinux --install --raid ${baseName}/${bootDir}syslinux
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of=/dev/sda")
if err := cmd.Run(); err != nil {
log.Errorf("%s", err)
return err
}
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of=/dev/sdb")
if err := cmd.Run(); err != nil {
log.Errorf("%s", err)
return err
}
if err := os.MkdirAll(filepath.Join(baseName, bootDir+"syslinux"), 0755); err != nil {
return err
}
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
files, _ := ioutil.ReadDir("/usr/share/syslinux/")
for _, file := range files {
if file.IsDir() {
continue
}
if err := dfs.CopyFile(filepath.Join("/usr/share/syslinux/", file.Name()), filepath.Join(baseName, bootDir, "syslinux"), file.Name()); err != nil {
log.Errorf("copy syslinux: %s", err)
return err
}
}
cmd = exec.Command("extlinux", "--install", "--raid", filepath.Join(baseName, bootDir+"syslinux"))
if err := cmd.Run(); err != nil {
log.Errorf("%s", err)
log.Errorf("extlinux: %s", err)
return err
}
return nil
@@ -975,6 +974,7 @@ func installRancher(baseName, bootDir, VERSION, DIST, kappend string) error {
log.Errorf("copy %s: %s", file.Name(), err)
return err
}
log.Debugf("copied %s to %s as %s", filepath.Join(DIST, file.Name()), filepath.Join(baseName, bootDir), file.Name())
}
// the general INCLUDE syslinuxcfg
if err := dfs.CopyFile(filepath.Join(DIST, "isolinux", "isolinux.cfg"), filepath.Join(baseName, bootDir, "syslinux"), "syslinux.cfg"); err != nil {

View File

@@ -10,7 +10,7 @@ source $(dirname $0)/version
cd $(dirname $0)/../tests
if [ ! -e ../dist/artifacts/initrd ]; then
if [ ! -e "$INITRD" ]; then
../scripts/dev
fi

View File

@@ -1,5 +1,5 @@
TIMEOUT 20 #2s
#PROMPT 1
PROMPT 1
# doesn't appear to work here?
INCLUDE ../global.cfg

View File

@@ -3,9 +3,7 @@
DEFAULT rancheros-${LABEL}
LABEL rancheros-${LABEL}
SAY rancheros-${LABEL}: RancherOS ${VERSION} ${KERNEL_VERSION}
KERNEL /boot/vmlinuz-${KERNEL_VERSION}
INITRD /boot/initrd
#TODO - once we work out how to append it for qemu-dev,/boot/linuxmods-${KERNEL_VERSION}
#APPEND quiet rancher.autologin=tty1 rancher.autologin=ttyS0 ${APPEND}
#INCLUDE global.cfg
KERNEL ../vmlinuz-${KERNEL_VERSION}
INITRD ../initrd-${VERSION}
# see global.cfg for kernel boot parameters

View File

@@ -3,10 +3,11 @@ set -e
cd $(dirname $0)/..
source scripts/version
BUILD=$(pwd)/build
INITRD_DIR=${BUILD}/initrd
ARTIFACTS=$(pwd)/dist/artifacts
INITRD=${ARTIFACTS}/initrd
mkdir -p ${ARTIFACTS}

View File

@@ -8,11 +8,14 @@ source ./scripts/version
BASEDOCKERFILE=./scripts/installer/BaseDockerfile.${ARCH}
DOCKERFILE=./scripts/installer/Dockerfile.${ARCH}
if [ ! -f $DOCKERFILE ] || [ ! -f dist/artifacts/vmlinuz-${KERNEL_VERSION} ] || [ ! -f dist/artifacts/initrd ]; then
exit 0
if [ ! -f $DOCKERFILE ] || [ ! -f dist/artifacts/vmlinuz-${KERNEL_VERSION} ] || [ ! -f ${INITRD} ]; then
echo "ERROR: ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} or ${INITRD} not found"
exit 1
fi
# TODO maybe extract the creation of the syslinux cfg files
DIST=$(pwd)/dist
echo "mkdir -p ${DIST}/boot/isolinux/"
mkdir -p ${DIST}/boot/isolinux/
cat scripts/isolinux.cfg | envsubst > ${DIST}/boot/isolinux/isolinux.cfg
cat scripts/isolinux_label.cfg | LABEL=${VERSION} envsubst > ${DIST}/boot/linux-current.cfg
@@ -35,7 +38,7 @@ docker build \
docker save -o dist/artifacts/installer.tar ${OS_REPO}/os-installer
cp $DOCKERFILE dist/artifacts/
cp ./dist/artifacts/initrd ./scripts/installer/build/boot
cp ${INITRD} ./scripts/installer/build/boot
cp ./dist/artifacts/vmlinuz-${KERNEL_VERSION} ./scripts/installer/build/boot
cp -r ${DIST}/boot/* ./scripts/installer/build/boot
cp $DOCKERFILE ./scripts/installer/build/Dockerfile

View File

@@ -13,11 +13,12 @@ CHECKSUM=iso-checksums.txt
mkdir -p ${CD}/boot/isolinux
mkdir -p ${CD}/rancheros
if [ ! -f ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ] || [ ! -f ${ARTIFACTS}/initrd ]; then
exit 0
if [ ! -f ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ] || [ ! -f ${INITRD} ]; then
echo "ERROR: ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} or ${INITRD} not found"
exit 1
fi
cp ${ARTIFACTS}/initrd ${CD}/boot
cp ${INITRD} ${CD}/boot
# TODO: these move to os-kernel
pwd
@@ -26,6 +27,7 @@ cp ${ARTIFACTS}/vmlinuz-${KERNEL_VERSION} ${CD}/boot/
#TODO cp ${ARTIFACTS}/linuxmods-${KERNEL_VERSION} ${CD}/boot/
# cfg files creation moved to package-installer
DIST=$(pwd)/dist
cp -r ${DIST}/boot/* ${CD}/boot/
cp /usr/lib/ISOLINUX/isolinux.bin ${CD}/boot/isolinux/

View File

@@ -1,3 +1,5 @@
#!/bin/bash
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
DIRTY="-dirty"
fi
@@ -13,7 +15,8 @@ if [ -z "$VERSION" ]; then
fi
fi
export VERSION COMMIT
INITRD=${ARTIFACTS}/initrd-${VERSION}
export VERSION COMMIT INITRD
# Suffix
export SUFFIX=""