Skip to content

Commit

Permalink
src: add disk create script, grub config
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Jeddeloh committed Jun 19, 2019
1 parent 128671b commit 7640c90
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh
set -euo pipefail

if [ "$#" -ne 6 ]; then
echo 'create_disk <device> <ostree-repo> <ostree-ref> <grub-script> <os-name> <space separated kargs>'
exit 1
fi

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

disk="$1" && shift
ostree="$1" && shift
ref="$1" && shift
grub_script="$1" && shift
os_name="$1" && shift
extrakargs="$1" && shift

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

# HACK ALERT - wait for partition rescans
sleep 2

mkfs.ext4 "${disk}1" -L boot
mkfs.fat "${disk}2" -n EFI-SYSTEM
# partition 3 has no FS, its for bios grub
mkfs.xfs "${disk}4" -L root

# mount the partitions
rm -rf rootfs
mkdir rootfs
mount "${disk}4" rootfs
mkdir rootfs/boot
mount "${disk}1" rootfs/boot
mkdir rootfs/boot/efi
mount "${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 "$os_name" --sysroot rootfs
allkargs='root=/dev/disk/by-label/root rootflags=defaults,prjquota rw $ignition_firstboot'
allkargs="$allkargs $extrakargs"
kargsargs=""
for karg in $allkargs
do
kargsargs+="--karg-append=$karg "
done
ostree admin deploy "$ref" --sysroot rootfs --os fedora-coreos $kargsargs

# install bios grub
grub2-install \
--target i386-pc \
--boot-directory rootfs/boot \
$disk

# copy the grub config and any other files we might need
cp $grub_script rootfs/boot/grub2/grub.cfg
touch rootfs/boot/ignition.firstboot

umount -R rootfs
49 changes: 49 additions & 0 deletions src/grub.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
set pager=1

if [ -f ${config_directory}/grubenv ]; then
load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
load_env
fi

if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi

function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}

serial --speed=115200
terminal_input serial console
terminal_output serial console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=1
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=1
fi

set ignition_firstboot=""
# Determine if this is a first boot.
if [ -f "/ignition.firstboot" ]; then
set ignition_firstboot="ignition.firstboot"
fi

set root='hd0,gpt1'
set boot='hd0,gpt1'
blscfg

0 comments on commit 7640c90

Please sign in to comment.