Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: remove anaconda #311

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bottlecap
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fi

script_dir=$(dirname "$(readlink -f "$0")")

volumes="-v $build_dir:/srv "
volumes="-v $build_dir:/srv --device /dev/kvm"

entrypoint=""

Expand All @@ -101,4 +101,4 @@ fi

# we actually want work splitting here since $volumes is multiple args
# shellcheck disable=SC2086
$runtime run --rm -ti --privileged --userns=host $volumes --workdir /srv $entrypoint "$container" "$@"
$runtime run --rm -ti --net=host --userns=host $volumes --workdir /srv $entrypoint "$container" "$@"
59 changes: 15 additions & 44 deletions src/cmd-build
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ sha256sum_str() {

# Calculate kickstart checksum now and gather previous image build variables if any
image_config_path="${configdir:?}"/image.yaml
image_config=true
if [ -f "${image_config_path}" ]; then
image_input="${image_config_path}"
else
Expand All @@ -118,7 +117,6 @@ else
echo "Sleeping for 10 seconds."
sleep 10
image_input="${configdir:?}"/image.ks
image_config=false
else
fatal "Failed to find image.yaml in configdir"
fi
Expand Down Expand Up @@ -163,6 +161,7 @@ composejson=${PWD}/tmp/compose.json
# --cache-only is here since `fetch` is a separate verb.
runcompose --cache-only ${FORCE} --add-metadata-from-json "${commitmeta_input_json}" \
--write-composejson-to "${composejson}"

# Always update the summary, since we used to do so
ostree --repo="${workdir}/repo" summary -u
# Very special handling for --write-composejson-to as rpm-ostree doesn't
Expand Down Expand Up @@ -219,62 +218,35 @@ echo "New build ID: ${buildid}"

imageprefix="${name:?}"-"${buildid}"
# Make these two verbose
set -x
mkdir -p tmp/anaconda
#set -x
#mkdir -p tmp/anaconda
img_base=tmp/${imageprefix}-base.qcow2

# These options don't work for EL7 so don't pass for now
# virt-install --console=log.file doesn't work for qemu in EL7
# 9pfs isn't an option for EL7 so copying out anaconda logs doesn't work
extraargs=
if [ -n "${ISFEDORA}" ]; then
extraargs="${extraargs} --console-log-file ${PWD}/install.log --logs ${PWD}/tmp/anaconda"
fi
set -x

if ${image_config}; then
extraargs="${extraargs} --image-config ${image_input}"
else
extraargs="${extraargs} --kickstart ${image_input}"
fi
create_disk() {
dest="$1"
shift

# forgive me for this sin
iso_location="${workdir}/installer/$(basename "${INSTALLER}")"
checksum_location="${workdir}/installer/$(basename "${INSTALLER_CHECKSUM}")"
rm -f "$(pwd)/diskimage.raw"
truncate -s 8G "$(pwd)/diskimage.raw"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get the size from image.yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we parse image.yaml into anything readable by bash anywhere?


set +x
# This generates the "base image"; not specific to a platform.
run_virtinstall() {
dest=$1
shift
tmpdest="${dest}.tmp"
# We want extraargs var to be split on words
# shellcheck disable=SC2086
/usr/lib/coreos-assembler/virt-install --create-disk --dest=${tmpdest} \
--kickstart-out "${PWD}"/tmp/flattened.ks \
--ostree-remote="${name}" --ostree-stateroot="${name}" \
--ostree-ref="${ref:-${commit}}" \
--location "${iso_location}" \
--ostree-repo="${workdir}"/repo ${extraargs-} "$@"
mv "${tmpdest}" "${dest}"
}
runvm /usr/lib/coreos-assembler/create_disk.sh -d /dev/vda -o "$workdir/repo" -r "${ref:-${commit}}"

build_cloud_base() {
if [ -f "${PWD}/${img_base}" ]; then
return
fi
run_virtinstall "${PWD}"/"${img_base}" --variant=cloud
qemu-img convert diskimage.raw "$dest"
}

declare -A images
for itype in "${IMAGE_TYPES[@]}"; do
case $itype in
qemu) img_qemu=${imageprefix}-qemu.qcow2
images[$itype]="${img_qemu}"
build_cloud_base
create_disk "$(pwd)/${img_base}"
#build_cloud_base
/usr/lib/coreos-assembler/gf-oemid "$(pwd)"/"${img_base}" "$(pwd)"/"${img_qemu}" qemu
# Clear the MCS SELinux labels
# See https://github.com/coreos/coreos-assembler/issues/292
chcon -vl s0 "${img_qemu}"
#chcon -vl s0 "${img_qemu}"
# make a version-less symlink to have a stable path
# TODO: Remove this, things should be parsing the metadata
ln -s "${img_qemu}" "${name}"-qemu.qcow2
Expand All @@ -295,7 +267,6 @@ for itype in "${IMAGE_TYPES[@]}"; do
done

build_timestamp=$(date -u +$RFC3339)
vm_iso_checksum=$(awk '/SHA256.*iso/{print$NF}' "${checksum_location}")

src_location="container"
if [ ! -f /lib/coreos-assembler/.clean ]; then
Expand All @@ -321,7 +292,6 @@ cat > tmp/meta.json <<EOF
"coreos-assembler.image-genver": "${image_genver}",
"coreos-assembler.image-input-checksum": "${image_input_checksum}",
"coreos-assembler.code-source": "${src_location}",
"coreos-assembler.vm-iso-checksum": "${vm_iso_checksum}",
"coreos-assembler.container-config-git": $(jq -M '.git' ${PWD}/coreos-assembler-config-git.json)
}
EOF
Expand Down Expand Up @@ -358,6 +328,7 @@ cat "${composejson}" tmp/meta.json tmp/images.json tmp/cosa-image.json "${commit
"${dn}"/commitmeta_to_json "${workdir}/repo" "${commit}" > commitmeta.json

# Clean up our temporary data
chattr -R -i tmp
rm tmp -rf
# Back to the toplevel build directory, so we can rename this one
cd "${workdir}"/builds
Expand Down
27 changes: 0 additions & 27 deletions src/cmd-init
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,6 @@ mkdir -p src
fi
fi)


installer_bn=$(basename "${INSTALLER}")
checksums_bn=$(basename "${INSTALLER_CHECKSUM}")
mkdir -p installer

if [ -n "${INSTALLER_DIR}" ]; then
if (cd "${INSTALLER_DIR}" && sha256sum -c "${checksums_bn}"); then
(cd installer
cp --reflink=auto "${INSTALLER_DIR}"/"${installer_bn}" .
cp --reflink=auto "${INSTALLER_DIR}"/"${checksums_bn}" .
)
fi
fi

(cd installer
if ! [ -f "${installer_bn}" ]; then
mkdir -p tmp
(
cd tmp
curl -L --remote-name-all "${INSTALLER}" "${INSTALLER_CHECKSUM}"
sha256sum -c "${checksums_bn}"
mv "${installer_bn}" "${checksums_bn}" ..
)
rm tmp -rf
fi
)

mkdir -p cache
mkdir -p builds
mkdir -p tmp
Expand Down
43 changes: 13 additions & 30 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,6 @@ release="29"
export arch
export release

# Download url is different for primary and secondary fedora
# Primary Fedora - https://download.fedoraproject.org/pub/fedora/linux/releases/
# Secondary Fedora - https://download.fedoraproject.org/pub/fedora-secondary/releases/
declare -A repository_dirs
repository_dirs[aarch64]=fedora/linux
repository_dirs[armhfp]=fedora/linux
repository_dirs[x86_64]=fedora/linux
repository_dirs[i386]=fedora-secondary
repository_dirs[ppc64le]=fedora-secondary
repository_dirs[s390x]=fedora-secondary

repository_dir=${repository_dirs[$arch]}
INSTALLER=https://download.fedoraproject.org/pub/$repository_dir/releases/$release/Everything/$arch/iso/Fedora-Everything-netinst-$arch-$release-1.2.iso
INSTALLER_CHECKSUM=https://download.fedoraproject.org/pub/$repository_dir/releases/$release/Everything/$arch/iso/Fedora-Everything-$release-1.2-$arch-CHECKSUM

# Overriding install URL
if [ -n "${INSTALLER_URL_OVERRIDE-}" ]; then
INSTALLER="${INSTALLER_URL_OVERRIDE}"
info "Overriding the install URL with contents of INSTALLER_URL_OVERRIDE"
fi
# Overriding install checksum URL
if [ -n "${INSTALLER_CHECKSUM_URL_OVERRIDE-}" ]; then
INSTALLER_CHECKSUM="${INSTALLER_CHECKSUM_URL_OVERRIDE}"
info "Overriding the install checksum URL with contents of INSTALLER_CHECKSUM_URL_OVERRIDE"
fi

export INSTALLER
export INSTALLER_CHECKSUM

_privileged=
has_privileges() {
if [ -z "${_privileged:-}" ]; then
Expand Down Expand Up @@ -280,6 +251,9 @@ echo \$rc > ${workdir}/tmp/rc
/sbin/reboot -f
EOF
chmod a+x "${vmpreparedir}"/init
echo "/usr/lib/coreos-assembler/create_disk.sh" > "${vmpreparedir}/hostfiles"
echo "/usr/lib/coreos-assembler/grub.cfg" >> "${vmpreparedir}/hostfiles"

(cd "${vmpreparedir}" && tar -czf init.tar.gz --remove-files init)
supermin --build "${vmpreparedir}" --size 5G -f ext2 -o "${vmbuilddir}"

Expand All @@ -292,9 +266,17 @@ EOF
srcvirtfs=("-virtfs" "local,id=source,path=${workdir}/src/config,security_model=none,mount_tag=source")
fi

# add the diskimage if it exists
diskimage=()
if [ -f "$(pwd)/diskimage.raw" ]; then
diskimage=("-drive" "if=virtio,id=target,format=raw,file=$(pwd)/diskimage.raw")
fi

${QEMU_KVM} -nodefaults -nographic -m 2048 -no-reboot \
-kernel "${vmbuilddir}/kernel" \
-initrd "${vmbuilddir}/initrd" \
-append "root=/dev/sda init=/usr/lib/systemd/systemd console=ttyS0 selinux=1 enforcing=0 autorelabel=1" \
-serial stdio \
-netdev user,id=eth0,hostname=supermin \
-device virtio-net-pci,netdev=eth0 \
-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 \
Expand All @@ -303,7 +285,8 @@ EOF
-drive if=none,id=drive-scsi0-0-0-1,discard=unmap,file="${workdir}/cache/cache.qcow2" \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi0-0-0-1,id=scsi0-0-0-1 \
-virtfs local,id=workdir,path="${workdir}",security_model=none,mount_tag=workdir \
"${srcvirtfs[@]}" -serial stdio -append "root=/dev/sda console=ttyS0 selinux=1 enforcing=0 autorelabel=1"
"${diskimage[@]}" \
"${srcvirtfs[@]}"

if [ ! -f "${workdir}"/tmp/rc ]; then
fatal "Couldn't find rc file, something went terribly wrong!"
Expand Down
121 changes: 121 additions & 0 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/sh

usage() {
echo "create_disk -d disk -o ostree"
}

export PATH=$PATH:/sbin:/usr/sbin

getpart() {
# getpart /dev/loop0 1 -> /dev/loop0p1
# getpart /dev/sda 1 -> /dev/sda1
last="${1: -1}"
if [ $last -q $last 2>/dev/null ]; then
echo "${1}p${2}"
else
echo "${1}${2}"
fi
}

rc=0
TEMP=$(getopt -o "d:o:r:" --long "disk:,ostree:,ref:" -- "$@") || rc=$?
if [ "$rc" -ne 0 ]; then
usage
exit 1
fi

eval set -- "$TEMP"

while :
do
case "$1" in
"-d"|"--disk")
shift
disk="$1"
shift
;;
"-o"|"--ostree")
shift
ostree="$1"
shift
;;
"-r"|"--ref")
shift
ref="$1"
shift
;;
--)
shift
break
;;
*)
echo "Error parsing args"
usage
exit 1
;;
esac
done

[ -z "$disk" ] || [ -z "$ostree" ] && {
usage
exit 1
}

set -e

script_dir=$(dirname $(readlink -f "$0"))
# partition and create fs
sgdisk -Z $disk \
-n 1:0:+128M -c 1:boot \
-n 2:0:+128M -c 2:EFI-SYSTEM -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \
-n 3:0:+128M -c 3:BIOS-BOOT -t 2:21686148-6449-6E6F-744E-656564454649 \
-n 4:0:0 -c 4:root -t 3:4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
sgdisk -p $disk

# HACK ALERT - wait for partition rescans
sleep 2
# FIXME ostree needs symlinks
mkfs.ext2 "$(getpart ${disk} 1)" -L boot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ext 2 ?

mkfs.fat "$(getpart ${disk} 2)" -n EFI-SYSTEM
mkfs.xfs "$(getpart ${disk} 4)" -L root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we also force on -m reflink=1 but eh...I guess we can just take that default from mkfs in the near future.


# mount the partitions
rm -rf rootfs
mkdir rootfs
mount $(getpart ${disk} 4) rootfs
mkdir rootfs/boot
mount $(getpart ${disk} 1) rootfs/boot
mkdir rootfs/boot/efi
mount $(getpart ${disk} 2) rootfs/boot/efi

# init the ostree
ostree admin init-fs rootfs
ostree pull-local "$ostree" --repo rootfs/ostree/repo
ostree admin os-init fedora-coreos --sysroot rootfs
ostree admin deploy "$ref" --sysroot rootfs --os fedora-coreos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fedora-coreos values are ${name} in cmd-build.sh.


checksum=$(cat rootfs/boot/ostree/*/{vm*,init*} | sha256sum | cut -d ' ' -f 1)
vmlinuz=$(basename rootfs/boot/ostree/*/vm*)
initrd=$(basename rootfs/boot/ostree/*/init*)
echo "Checksum is: $checksum initrd is $initrd vmlinuz is $vmlinuz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data is more canonically stored in the BLS fragment.


# install bios grub (mostly lifted from the container linux scripts)
grub2-install \
--target i386-pc \
--boot-directory rootfs/boot \
$disk

#mkdir -p rootfs/boot/efi/EFI/boot
#grub2-mkimage \
# --format x86_64-efi \
# --output rootfs/boot/efi/EFI/grub.efi \
# --prefix='(root)/boot/grub'
# serial linuxefi efi_gop getenv smbios efinet verify http tftp

cat "$script_dir/grub.cfg" \
| sed "s/HASHHASH/$checksum/" \
| sed "s/VMLINUZ/$vmlinuz/" \
| sed "s/INITRD/$initrd/" \
| tee rootfs/boot/grub2/grub.cfg

touch rootfs/boot/ignition.firstboot
2 changes: 1 addition & 1 deletion src/gf-oemid
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ coreos_gf_run_mount "${tmp_dest}"
# * grub config
# * BLS config (for subsequent config regeneration)
# First, the grub config.
grubcfg_path=/boot/loader/grub.cfg
grubcfg_path=/boot/grub2/grub.cfg
coreos_gf download "${grubcfg_path}" "${tmpd}"/grub.cfg
# Remove any oemid currently there
sed -i -e 's, coreos.oem.id=[a-zA-Z0-9]*,,g' "${tmpd}"/grub.cfg
Expand Down
Loading