Skip to content

Commit

Permalink
WIP: Add metal-bios target
Browse files Browse the repository at this point in the history
Split out the "net.ifnames" stuff into a separate kickstart, and
generate a raw disk image `metal-bios` if specified.

Note to really be useful this requires Ignition to load `/boot/config.ign`
or so.
  • Loading branch information
cgwalters committed Jan 31, 2019
1 parent 83e63bd commit 3ac38a9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
66 changes: 44 additions & 22 deletions src/cmd-build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Usage: coreos-assembler build --help
Valid types:
- qemu
- metal-bios
EOF
}

Expand Down Expand Up @@ -212,33 +213,54 @@ else
extraargs="${extraargs} --kickstart ${image_input}"
fi

# This generates the "base image"; not specific to a platform.
# We want extraargs var to be split on words
# shellcheck disable=SC2086
/usr/lib/coreos-assembler/virt-install --dest="$(pwd)"/"${img_base}" \
--create-disk --kickstart-out "$(pwd)"/tmp/flattened.ks \
--ostree-remote="${name}" --ostree-stateroot="${name}" \
--ostree-ref="${ref:-${commit}}" \
--location "${workdir}"/installer/*.iso \
--ostree-repo="${workdir}"/repo ${extraargs-}
/usr/lib/coreos-assembler/gf-anaconda-cleanup "$(pwd)"/"${img_base}"
set +x
run_virtinstall() {
# This generates the "base image"; not specific to a platform.
# We want extraargs var to be split on words
# shellcheck disable=SC2086
dest=$1
shift
/usr/lib/coreos-assembler/virt-install --create-disk --dest=${dest} \
--kickstart-out "$(pwd)"/tmp/flattened.ks \
--ostree-remote="${name}" --ostree-stateroot="${name}" \
--ostree-ref="${ref:-${commit}}" \
--location "${workdir}"/installer/*.iso \
--ostree-repo="${workdir}"/repo ${extraargs-} "$@"
# And strip out all of the Anaconda stuff in /var
/usr/lib/coreos-assembler/gf-anaconda-cleanup "${dest}"
}

build_cloud_base() {
if [ -f "$(pwd)/${img_base}" ]; then
return
fi
run_virtinstall "$(pwd)"/"${img_base}" --variant=cloud
built_generic_base=y
}

declare -A images
for atype in ${ARTIFACT_TYPES}; do
case $atype in
qemu) img_qemu=${imageprefix}-qemu.qcow2
images[$atype]="${img_qemu}"
/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}"
# 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
;;
*) fatal "Unrecognized image type: $atype"
;;
qemu)
img_qemu=${imageprefix}-qemu.qcow2
images[$atype]="${img_qemu}"
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}"
# 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
;;
metal-bios)
img_metalbios=${imageprefix}-metal-bios.raw
images[$atype]="${img_metalbios}"
run_virtinstall "$(pwd)"/"${img_metalbios}" --variant=metal
;;
*)
fatal "Unrecognized image type: $atype"
;;
esac
done

Expand Down
20 changes: 0 additions & 20 deletions src/image-base.ks
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ network --bootproto=dhcp --onboot=on

zerombr
clearpart --initlabel --all
# Add the following to kernel boot args:
# - ip=dhcp # how to get network
# - rd.neednet=1 # tell dracut we need network
# - $ignition_firstboot # This is actually a GRUB variable
bootloader --timeout=1 --append="no_timer_check console=ttyS0,115200n8 console=tty0 net.ifnames=0 biosdevname=0 ip=dhcp rd.neednet=1 rw $ignition_firstboot"

# https://github.com/coreos/fedora-coreos-tracker/issues/18
# See also coreos-growpart.service defined in fedora-coreos-base.yaml
Expand All @@ -42,19 +37,4 @@ reboot
# Remove any persistent NIC rules generated by udev
rm -vf /etc/udev/rules.d/*persistent-net*.rules
# By default, we do DHCP. Also, due to the above disabling
# of biosdevname/net.ifnames, this uses eth0.
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
NM_CONTROLLED="yes"
EOF
# Anaconda is writing a /etc/resolv.conf from the generating environment.
# The system should start out with an empty file.
truncate -s 0 /etc/resolv.conf
%end
15 changes: 15 additions & 0 deletions src/image-cloud.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# console, Ignition, and net.ifnames=0
bootloader --timeout=1 --append="no_timer_check console=ttyS0,115200n8 console=tty0 net.ifnames=0 biosdevname=0 ip=dhcp rd.neednet=1 rw $ignition_firstboot"

%post --erroronfail
# By default, we do DHCP. Also, due to the above disabling
# of biosdevname/net.ifnames, this uses eth0.
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
NM_CONTROLLED="yes"
EOF
%end
2 changes: 2 additions & 0 deletions src/image-metal.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Base Ignition args
bootloader --append="rw $ignition_firstboot"
12 changes: 11 additions & 1 deletion src/virt-install
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ parser.add_argument("--create-disk", help="Automatically create disk as qcow2, p
action='store_true')
parser.add_argument("--image-config", help="coreos-assembler image.yaml",
action='store')
parser.add_argument("--variant", help="Use an internal (kickstart) config",
choices=('metal', 'cloud'), default=None)
parser.add_argument("--kickstart", help="Kickstart path",
action='store')
parser.add_argument("--kickstart-out", help="Save flattened kickstart",
Expand Down Expand Up @@ -86,6 +88,10 @@ else:

disk_size = None

if args.variant is not None:
with open(f'/usr/lib/coreos-assembler/image-{args.variant}.ks') as f:
shutil.copyfileobj(f, ks_tmp)

if args.image_config:
with open('/usr/lib/coreos-assembler/image-base.ks') as basef:
shutil.copyfileobj(basef, ks_tmp)
Expand Down Expand Up @@ -155,7 +161,11 @@ if args.create_disk and args.kickstart:
fatal("--create-disk specified, but failed to find '{}' in kickstart".format(magic_virt_install_size_str))

if args.create_disk:
run_sync_verbose(['qemu-img', 'create', '-f', 'qcow2', args.dest, '{}G'.format(disk_size)])
if args.variant == 'metal':
fmt = 'raw'
else:
fmt = 'qcow2'
run_sync_verbose(['qemu-img', 'create', '-f', fmt, args.dest, '{}G'.format(disk_size)])
print("Created initial disk: {} with size {}G".format(args.dest, disk_size))

# Now a hack to avoid libvirt race conditions; it's
Expand Down

0 comments on commit 3ac38a9

Please sign in to comment.