mirror of
https://github.com/rancher/os.git
synced 2025-09-16 15:09:27 +00:00
port the use of parted to go
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -46,9 +46,8 @@ var installCommand = cli.Command{
|
|||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "install-type, t",
|
Name: "install-type, t",
|
||||||
Usage: `generic: (Default) Creates 1 ext4 partition and installs RancherOS
|
Usage: `generic: (Default) Creates 1 ext4 partition and installs RancherOS (syslinux)
|
||||||
amazon-ebs: Installs RancherOS and sets up PV-GRUB
|
amazon-ebs: Installs RancherOS and sets up PV-GRUB
|
||||||
syslinux: partition and format disk (mbr), then install RancherOS and setup Syslinux
|
|
||||||
gptsyslinux: partition and format disk (gpt), then install RancherOS and setup Syslinux
|
gptsyslinux: partition and format disk (gpt), then install RancherOS and setup Syslinux
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@@ -137,19 +136,18 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
diskType = "gpt"
|
diskType = "gpt"
|
||||||
}
|
}
|
||||||
|
|
||||||
if installType == "generic" ||
|
|
||||||
installType == "syslinux" ||
|
|
||||||
installType == "gptsyslinux" {
|
|
||||||
|
|
||||||
// Versions before 0.8.0-rc2 use the old calling convention (from the lay-down-os shell script)
|
// Versions before 0.8.0-rc2 use the old calling convention (from the lay-down-os shell script)
|
||||||
imageVersion := strings.TrimPrefix(image, "rancher/os:v")
|
imageVersion := strings.TrimPrefix(image, "rancher/os:v")
|
||||||
if image != imageVersion {
|
if image != imageVersion {
|
||||||
|
log.Infof("user spcified different install image: %s != %s", image, imageVersion)
|
||||||
imageVersion = strings.Replace(imageVersion, "-", ".", -1)
|
imageVersion = strings.Replace(imageVersion, "-", ".", -1)
|
||||||
vArray := strings.Split(imageVersion, ".")
|
vArray := strings.Split(imageVersion, ".")
|
||||||
v, _ := strconv.ParseFloat(vArray[0]+"."+vArray[1], 32)
|
v, _ := strconv.ParseFloat(vArray[0]+"."+vArray[1], 32)
|
||||||
if v < 0.8 || imageVersion == "0.8.0-rc1" {
|
if v < 0.8 || imageVersion == "0.8.0-rc1" {
|
||||||
log.Infof("starting installer container for %s", image)
|
log.Infof("starting installer container for %s", image)
|
||||||
if installType == "generic" {
|
if installType == "generic" ||
|
||||||
|
installType == "syslinux" ||
|
||||||
|
installType == "gptsyslinux" {
|
||||||
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=all-volumes",
|
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=all-volumes",
|
||||||
"--entrypoint=/scripts/set-disk-partitions", image, device, diskType)
|
"--entrypoint=/scripts/set-disk-partitions", image, device, diskType)
|
||||||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
@@ -158,7 +156,8 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes",
|
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes",
|
||||||
"--volumes-from=command-volumes", image, "-d", device, "-t", installType, "-c", cloudConfig, "-a", kappend)
|
"--volumes-from=command-volumes", image, "-d", device, "-t", installType, "-c", cloudConfig,
|
||||||
|
"-a", kappend)
|
||||||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -195,7 +194,7 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
"run", "--rm", "--net=host", "--privileged",
|
"run", "--rm", "--net=host", "--privileged",
|
||||||
// bind mount host fs to access its ros, vmlinuz, initrd and /dev (udev isn't running in container)
|
// bind mount host fs to access its ros, vmlinuz, initrd and /dev (udev isn't running in container)
|
||||||
"-v", "/:/host",
|
"-v", "/:/host",
|
||||||
"--volumes-from=user-volumes", "--volumes-from=command-volumes",
|
"--volumes-from=all-volumes",
|
||||||
image,
|
image,
|
||||||
"install",
|
"install",
|
||||||
"-t", installType,
|
"-t", installType,
|
||||||
@@ -239,8 +238,14 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
|
|
||||||
log.Infof("running installation")
|
log.Infof("running installation")
|
||||||
|
|
||||||
if installType == "generic" {
|
if installType == "generic" ||
|
||||||
err := setDiskpartitions(device)
|
installType == "syslinux" ||
|
||||||
|
installType == "gptsyslinux" {
|
||||||
|
diskType := "msdos"
|
||||||
|
if installType == "gptsyslinux" {
|
||||||
|
diskType = "gpt"
|
||||||
|
}
|
||||||
|
err := setDiskpartitions(device, diskType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error setDiskpartitions %s", err)
|
log.Errorf("error setDiskpartitions %s", err)
|
||||||
return err
|
return err
|
||||||
@@ -271,12 +276,23 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mountBootIso() error {
|
func mountBootIso() error {
|
||||||
// TODO: need to add a label to the iso and mount using that.
|
|
||||||
// ARGH! need to mount this in the host - or share it as a volume..
|
|
||||||
os.MkdirAll("/bootiso", 0755)
|
|
||||||
|
|
||||||
deviceName := "/dev/sr0"
|
deviceName := "/dev/sr0"
|
||||||
deviceType := "iso9660"
|
deviceType := "iso9660"
|
||||||
|
{ // force the defer
|
||||||
|
mountsFile, err := os.Open("/proc/mounts")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to read /proc/mounts %s", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer mountsFile.Close()
|
||||||
|
|
||||||
|
if partitionMounted(deviceName, mountsFile) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.MkdirAll("/bootiso", 0755)
|
||||||
|
|
||||||
// find the installation device
|
// find the installation device
|
||||||
cmd := exec.Command("blkid", "-L", "RancherOS")
|
cmd := exec.Command("blkid", "-L", "RancherOS")
|
||||||
log.Debugf("Run(%v)", cmd)
|
log.Debugf("Run(%v)", cmd)
|
||||||
@@ -337,7 +353,16 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
|
|||||||
// unmount on trap
|
// unmount on trap
|
||||||
defer util.Unmount(baseName)
|
defer util.Unmount(baseName)
|
||||||
|
|
||||||
|
diskType := "msdos"
|
||||||
|
if installType == "gptsyslinux" {
|
||||||
|
diskType = "gpt"
|
||||||
|
}
|
||||||
|
|
||||||
switch installType {
|
switch installType {
|
||||||
|
case "syslinux":
|
||||||
|
fallthrough
|
||||||
|
case "gptsyslinux":
|
||||||
|
fallthrough
|
||||||
case "generic":
|
case "generic":
|
||||||
log.Debugf("formatAndMount")
|
log.Debugf("formatAndMount")
|
||||||
var err error
|
var err error
|
||||||
@@ -349,7 +374,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
|
|||||||
//log.Infof("installGrub")
|
//log.Infof("installGrub")
|
||||||
//err = installGrub(baseName, device)
|
//err = installGrub(baseName, device)
|
||||||
log.Debugf("installSyslinux")
|
log.Debugf("installSyslinux")
|
||||||
err = installSyslinux(device, baseName, bootDir)
|
err = installSyslinux(device, baseName, bootDir, diskType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s", err)
|
log.Errorf("%s", err)
|
||||||
@@ -399,7 +424,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
createbootDirs(baseName, bootDir)
|
createbootDirs(baseName, bootDir)
|
||||||
installSyslinux(device, baseName, bootDir)
|
installSyslinux(device, baseName, bootDir, diskType)
|
||||||
case "raid":
|
case "raid":
|
||||||
var err error
|
var err error
|
||||||
bootDir, err = mountdevice(baseName, bootDir, partition, false)
|
bootDir, err = mountdevice(baseName, bootDir, partition, false)
|
||||||
@@ -407,7 +432,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
createbootDirs(baseName, bootDir)
|
createbootDirs(baseName, bootDir)
|
||||||
installSyslinuxRaid(baseName, bootDir)
|
installSyslinuxRaid(baseName, bootDir, diskType)
|
||||||
case "bootstrap":
|
case "bootstrap":
|
||||||
CONSOLE = "ttyS0"
|
CONSOLE = "ttyS0"
|
||||||
var err error
|
var err error
|
||||||
@@ -496,7 +521,7 @@ func seedData(baseName, cloudData string, files []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set-disk-partitions is called with device == **/dev/sda**
|
// set-disk-partitions is called with device == **/dev/sda**
|
||||||
func setDiskpartitions(device string) error {
|
func setDiskpartitions(device, diskType string) error {
|
||||||
log.Debugf("setDiskpartitions")
|
log.Debugf("setDiskpartitions")
|
||||||
|
|
||||||
d := strings.Split(device, "/")
|
d := strings.Split(device, "/")
|
||||||
@@ -590,23 +615,16 @@ func setDiskpartitions(device string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, w := io.Pipe()
|
bootflag := "boot"
|
||||||
go func() {
|
if diskType == "gpt" {
|
||||||
w.Write([]byte(`n
|
bootflag = "legacy_boot"
|
||||||
p
|
}
|
||||||
1
|
log.Debugf("running parted")
|
||||||
|
cmd = exec.Command("parted", "-s", "-a", "optimal", device,
|
||||||
|
"mklabel "+diskType, "--",
|
||||||
a
|
"mkpart primary ext4 1 -1",
|
||||||
1
|
"set 1 "+bootflag+" on")
|
||||||
w
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
`))
|
|
||||||
w.Close()
|
|
||||||
}()
|
|
||||||
log.Debugf("running fdisk")
|
|
||||||
cmd = exec.Command("fdisk", device)
|
|
||||||
cmd.Stdin = r
|
|
||||||
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Errorf("%s", err)
|
log.Errorf("%s", err)
|
||||||
return err
|
return err
|
||||||
@@ -714,13 +732,18 @@ func createbootDirs(baseName, bootDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func installSyslinux(device, baseName, bootDir string) error {
|
func installSyslinux(device, baseName, bootDir, diskType string) error {
|
||||||
log.Debugf("installSyslinux")
|
log.Debugf("installSyslinux")
|
||||||
|
|
||||||
|
mbrFile := "mbr.bin"
|
||||||
|
if diskType == "gpt" {
|
||||||
|
mbrFile = "gptmbr.bin"
|
||||||
|
}
|
||||||
|
|
||||||
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${device}
|
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${device}
|
||||||
// ubuntu: /usr/lib/syslinux/mbr/mbr.bin
|
// ubuntu: /usr/lib/syslinux/mbr/mbr.bin
|
||||||
// alpine: /usr/share/syslinux/mbr.bin
|
// alpine: /usr/share/syslinux/mbr.bin
|
||||||
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of="+device)
|
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of="+device)
|
||||||
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
log.Debugf("Run(%v)", cmd)
|
log.Debugf("Run(%v)", cmd)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@@ -750,19 +773,24 @@ func installSyslinux(device, baseName, bootDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func installSyslinuxRaid(baseName, bootDir string) error {
|
func installSyslinuxRaid(baseName, bootDir, diskType string) error {
|
||||||
log.Debugf("installSyslinuxRaid")
|
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/sda
|
||||||
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdb
|
//dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdb
|
||||||
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
|
//cp /usr/lib/syslinux/modules/bios/* ${baseName}/${bootDir}syslinux
|
||||||
//extlinux --install --raid ${baseName}/${bootDir}syslinux
|
//extlinux --install --raid ${baseName}/${bootDir}syslinux
|
||||||
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of=/dev/sda")
|
cmd := exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of=/dev/sda")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Errorf("%s", err)
|
log.Errorf("%s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/mbr.bin", "of=/dev/sdb")
|
cmd = exec.Command("dd", "bs=440", "count=1", "if=/usr/share/syslinux/"+mbrFile, "of=/dev/sdb")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Errorf("%s", err)
|
log.Errorf("%s", err)
|
||||||
return err
|
return err
|
||||||
|
31
scripts/run
31
scripts/run
@@ -14,6 +14,12 @@ while [ "$#" -gt 0 ]; do
|
|||||||
QIND=0
|
QIND=0
|
||||||
REBUILD=0
|
REBUILD=0
|
||||||
;;
|
;;
|
||||||
|
--boothd)
|
||||||
|
BOOT_HD=1
|
||||||
|
QEMU=0
|
||||||
|
QIND=0
|
||||||
|
REBUILD=0
|
||||||
|
;;
|
||||||
--append)
|
--append)
|
||||||
shift 1
|
shift 1
|
||||||
QEMU_APPEND="${QEMU_APPEND} $1"
|
QEMU_APPEND="${QEMU_APPEND} $1"
|
||||||
@@ -100,7 +106,7 @@ if [ "$KVM" == "" ] && [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; th
|
|||||||
KVM=1
|
KVM=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ]; then
|
if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ] || [ "$BOOT_HD" == "1" ]; then
|
||||||
HD=${BASE}/state/hd.img
|
HD=${BASE}/state/hd.img
|
||||||
HD2=${BASE}/state/hd2.img
|
HD2=${BASE}/state/hd2.img
|
||||||
[ "$FRESH" == "1" ] && rm -f ${HD} ${HD2} >/dev/null 2>&1 || :
|
[ "$FRESH" == "1" ] && rm -f ${HD} ${HD2} >/dev/null 2>&1 || :
|
||||||
@@ -118,14 +124,15 @@ if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ]; then
|
|||||||
qemu-img create -f qcow2 -o size=10G ${HD2}
|
qemu-img create -f qcow2 -o size=10G ${HD2}
|
||||||
SECOND_DRIVE_ENABLE=$(eval "${hd["$ARCH"]} ${HD2}")
|
SECOND_DRIVE_ENABLE=$(eval "${hd["$ARCH"]} ${HD2}")
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$QIND" != "1" ]; then
|
||||||
CPU=${cpu["$ARCH"]}
|
CPU=${cpu["$ARCH"]}
|
||||||
if [ "$KVM" == "1" ] && [ "$ARCH" == "$HOST_ARCH" ]; then
|
if [ "$KVM" == "1" ] && [ "$ARCH" == "$HOST_ARCH" ]; then
|
||||||
KVM_ENABLE="-enable-kvm"
|
KVM_ENABLE="-enable-kvm"
|
||||||
CPU="-cpu host"
|
CPU="-cpu host"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$QIND" != "1" ]; then
|
|
||||||
CCROOT=${BUILD}/cloud-config
|
CCROOT=${BUILD}/cloud-config
|
||||||
rm -rf ${CCROOT}
|
rm -rf ${CCROOT}
|
||||||
mkdir -p ${CCROOT}
|
mkdir -p ${CCROOT}
|
||||||
@@ -175,7 +182,16 @@ if [ "$QEMU" == "1" ]; then
|
|||||||
${QEMU_ARGS} \
|
${QEMU_ARGS} \
|
||||||
"${@}"
|
"${@}"
|
||||||
|
|
||||||
elif [ "$BOOT_ISO" == "1" ]; then
|
elif [ "$BOOT_ISO" == "1" ] ||
|
||||||
|
[ "$BOOT_HD" == "1" ]; then
|
||||||
|
if [ "$BOOT_ISO" == "1" ]; then
|
||||||
|
ISO_OPTS="-boot d -cdrom ./dist/artifacts/rancheros.iso \
|
||||||
|
-fsdev local,security_model=passthrough,readonly,id=fsdev0,path=${CCROOT} \
|
||||||
|
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2 \
|
||||||
|
-fsdev local,security_model=none,id=fsdev1,path=${HOME} \
|
||||||
|
-device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home "
|
||||||
|
echo "----- $ISO_OPTS"
|
||||||
|
fi
|
||||||
set -x
|
set -x
|
||||||
exec qemu-system-${QEMUARCH} \
|
exec qemu-system-${QEMUARCH} \
|
||||||
-curses \
|
-curses \
|
||||||
@@ -188,12 +204,7 @@ elif [ "$BOOT_ISO" == "1" ]; then
|
|||||||
$(eval "${hd["$ARCH"]} ${HD}") \
|
$(eval "${hd["$ARCH"]} ${HD}") \
|
||||||
${SECOND_DRIVE_ENABLE} \
|
${SECOND_DRIVE_ENABLE} \
|
||||||
-smp 1 \
|
-smp 1 \
|
||||||
-fsdev local,security_model=passthrough,readonly,id=fsdev0,path=${CCROOT} \
|
${ISO_OPTS}
|
||||||
-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2 \
|
|
||||||
-fsdev local,security_model=none,id=fsdev1,path=${HOME} \
|
|
||||||
-device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home \
|
|
||||||
-boot d \
|
|
||||||
-cdrom ./dist/artifacts/rancheros.iso
|
|
||||||
elif [ "$QIND" == "1" ]; then
|
elif [ "$QIND" == "1" ]; then
|
||||||
|
|
||||||
NAME=${NAME:-ros-qind}
|
NAME=${NAME:-ros-qind}
|
||||||
|
Reference in New Issue
Block a user