1
0
mirror of https://github.com/rancher/os.git synced 2025-07-31 22:47:16 +00:00

Add noformat and RAID installer types

This commit is contained in:
Josh Curl 2016-09-29 21:55:19 -07:00
parent 5987d713a4
commit 2fc1d3fa5f
No known key found for this signature in database
GPG Key ID: 82B504B9BCCFA677
3 changed files with 84 additions and 23 deletions

View File

@ -115,8 +115,8 @@ func runInstall(image, installType, cloudConfig, device, append string, force, r
return err
}
}
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes", image,
"-d", device, "-t", installType, "-c", cloudConfig, "-a", append)
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", append)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
return err

View File

@ -1,7 +1,7 @@
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y udev grub2 parted kexec-tools && \
apt-get install --no-install-recommends -y udev grub2 parted kexec-tools extlinux syslinux-common && \
rm -rf /var/lib/apt/*
COPY ./build/vmlinuz ./build/initrd /dist/

View File

@ -27,6 +27,7 @@ DIST=${DIST:-/dist}
CLOUD_CONFIG=${CLOUD_CONFIG:-"${SCRIPTS_DIR}/conf/empty.yml"}
CONSOLE=tty0
BASE_DIR="/mnt/new_img"
BOOT=boot/
# TODO: Change this to a number so that users can specify.
# Will need to make it so that our builds and packer APIs remain consistent.
PARTITION=${PARTITION:=${DEVICE}1}
@ -46,18 +47,28 @@ format_device()
mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION}
}
get_dev()
{
if [ -z "$(which ros)" ]; then
lsblk -n -o label $1
else
ros dev LABEL=${1}
fi
}
mount_device()
{
local label=RANCHER_STATE
LABEL=RANCHER_STATE
local raw="${1:-false}"
mkdir -p ${BASE_DIR}
if [ "$(lsblk -o label|grep RANCHER_BOOT | wc -l)" -gt "0" ]; then
label=RANCHER_BOOT
if [ -n "$(get_dev RANCHER_BOOT)" ]; then
LABEL=RANCHER_BOOT
BOOT=
fi
local mount_opts="-L ${label}"
local mount_opts="-L ${LABEL}"
if [ "${raw}" == "true" ]; then
device_defined ${DEVICE}
mount_opts=${PARTITION}
@ -69,7 +80,21 @@ mount_device()
create_boot_dirs()
{
mkdir -p ${BASE_DIR}/boot/grub
mkdir -p ${BASE_DIR}/${BOOT}grub
mkdir -p ${BASE_DIR}/${BOOT}syslinux
}
install_syslinux() {
dd bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin of=${DEVICE}
cp /usr/lib/syslinux/modules/bios/* ${BASE_DIR}/${BOOT}syslinux
extlinux --install ${BASE_DIR}/${BOOT}syslinux
}
install_syslinux_raid() {
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/* ${BASE_DIR}/${BOOT}syslinux
extlinux --install --raid ${BASE_DIR}/${BOOT}syslinux
}
install_grub() {
@ -77,7 +102,7 @@ install_grub() {
}
grub2_config(){
local grub_cfg=${BASE_DIR}/boot/grub/grub.cfg
local grub_cfg=${BASE_DIR}/${BOOT}grub/grub.cfg
local append_line="${1}"
cat >${grub_cfg} <<EOF
set default="0"
@ -86,8 +111,8 @@ set timeout="1"
menuentry "RancherOS-current" {
set root=(hd0,msdos1)
linux /boot/vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /boot/initrd-${VERSION}-rancheros
linux /${BOOT}vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /${BOOT}initrd-${VERSION}-rancheros
}
EOF
@ -97,23 +122,48 @@ if [ ! -z ${ROLLBACK_VERSION} ]; then
cat >>${grub_cfg} <<EOF
menuentry "RancherOS-rollback" {
set root=(hd0,msdos1)
linux /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
linux /${BOOT}vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /${BOOT}initrd-${ROLLBACK_VERSION}-rancheros
}
EOF
fi
}
syslinux_config(){
local syslinux_cfg=${BASE_DIR}/${BOOT}syslinux/syslinux.cfg
local append_line="${1}"
cat >${syslinux_cfg} <<EOF
DEFAULT RancherOS-current
LABEL RancherOS-current
LINUX ../vmlinuz-${VERSION}-rancheros
APPEND ${KERNEL_ARGS} ${append_line}
INITRD ../initrd-${VERSION}-rancheros
EOF
if [ ! -z ${ROLLBACK_VERSION} ]; then
cat >>${syslinux_cfg} <<EOF
LABEL RancherOS-rollback
LINUX ../vmlinuz-${ROLLBACK_VERSION}-rancheros
APPEND ${KERNEL_ARGS} ${append_line}
INITRD ../initrd-${ROLLBACK_VERSION}-rancheros
EOF
fi
}
install_rancher()
{
cp ${DIST}/initrd ${BASE_DIR}/boot/initrd-${VERSION}-rancheros
cp ${DIST}/vmlinuz ${BASE_DIR}/boot/vmlinuz-${VERSION}-rancheros
cp ${DIST}/initrd ${BASE_DIR}/${BOOT}initrd-${VERSION}-rancheros
cp ${DIST}/vmlinuz ${BASE_DIR}/${BOOT}vmlinuz-${VERSION}-rancheros
}
pvgrub_config()
{
local grub_file=${BASE_DIR}/boot/grub/menu.lst
local grub_file=${BASE_DIR}/${BOOT}grub/menu.lst
local append_line="${1}"
cat > ${grub_file}<<EOF
default 0
@ -124,8 +174,8 @@ hiddenmenu
title RancherOS ${VERSION}-(current)
root (hd0)
kernel /boot/vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /boot/initrd-${VERSION}-rancheros
kernel /${BOOT}vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /${BOOT}initrd-${VERSION}-rancheros
EOF
@ -134,8 +184,8 @@ if [ ! -z ${ROLLBACK_VERSION} ]; then
cat >> ${grub_file}<<EOF
title RancherOS ${ROLLBACK_VERSION}-(rollback)
root (hd0)
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
kernel /${BOOT}/vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
initrd /${BOOT}initrd-${ROLLBACK_VERSION}-rancheros
EOF
fi
}
@ -173,6 +223,16 @@ if [ -n ${ENV} ]; then
install_grub
"${SCRIPTS_DIR}/seed-data" ${BASE_DIR} ${CLOUD_CONFIG} ${FILES}
;;
"noformat")
mount_device
create_boot_dirs
install_syslinux
;;
"raid")
mount_device
create_boot_dirs
install_syslinux_raid
;;
"bootstrap")
CONSOLE=ttyS0
mount_device true
@ -190,15 +250,16 @@ if [ -n ${ENV} ]; then
esac
fi
if [ -e ${BASE_DIR}/boot/append ]; then
PRESERVED_APPEND=$(cat ${BASE_DIR}/boot/append)
if [ -e ${BASE_DIR}/${BOOT}append ]; then
PRESERVED_APPEND=$(cat ${BASE_DIR}/${BOOT}append)
fi
if [ "${APPEND}" = "" ]; then
APPEND="${PRESERVED_APPEND}"
fi
echo "${APPEND}" > ${BASE_DIR}/boot/append
echo "${APPEND}" > ${BASE_DIR}/${BOOT}append
grub2_config "${APPEND}"
syslinux_config "${APPEND}"
pvgrub_config "${APPEND}"
install_rancher