Skip to content

Commit 7640c90

Browse files
author
Andrew Jeddeloh
committed
src: add disk create script, grub config
1 parent 128671b commit 7640c90

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

src/create_disk.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
if [ "$#" -ne 6 ]; then
5+
echo 'create_disk <device> <ostree-repo> <ostree-ref> <grub-script> <os-name> <space separated kargs>'
6+
exit 1
7+
fi
8+
9+
export PATH=$PATH:/sbin:/usr/sbin
10+
11+
disk="$1" && shift
12+
ostree="$1" && shift
13+
ref="$1" && shift
14+
grub_script="$1" && shift
15+
os_name="$1" && shift
16+
extrakargs="$1" && shift
17+
18+
# partition and create fs
19+
sgdisk -Z $disk \
20+
-n 1:0:+128M -c 1:boot \
21+
-n 2:0:+128M -c 2:EFI-SYSTEM -t 2:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \
22+
-n 3:0:+128M -c 3:BIOS-BOOT -t 3:21686148-6449-6E6F-744E-656564454649 \
23+
-n 4:0:0 -c 4:root -t 4:4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
24+
sgdisk -p "$disk"
25+
26+
# HACK ALERT - wait for partition rescans
27+
sleep 2
28+
29+
mkfs.ext4 "${disk}1" -L boot
30+
mkfs.fat "${disk}2" -n EFI-SYSTEM
31+
# partition 3 has no FS, its for bios grub
32+
mkfs.xfs "${disk}4" -L root
33+
34+
# mount the partitions
35+
rm -rf rootfs
36+
mkdir rootfs
37+
mount "${disk}4" rootfs
38+
mkdir rootfs/boot
39+
mount "${disk}1" rootfs/boot
40+
mkdir rootfs/boot/efi
41+
mount "${disk}2" rootfs/boot/efi
42+
43+
# init the ostree
44+
ostree admin init-fs rootfs
45+
ostree pull-local "$ostree" --repo rootfs/ostree/repo
46+
ostree admin os-init "$os_name" --sysroot rootfs
47+
allkargs='root=/dev/disk/by-label/root rootflags=defaults,prjquota rw $ignition_firstboot'
48+
allkargs="$allkargs $extrakargs"
49+
kargsargs=""
50+
for karg in $allkargs
51+
do
52+
kargsargs+="--karg-append=$karg "
53+
done
54+
ostree admin deploy "$ref" --sysroot rootfs --os fedora-coreos $kargsargs
55+
56+
# install bios grub
57+
grub2-install \
58+
--target i386-pc \
59+
--boot-directory rootfs/boot \
60+
$disk
61+
62+
# copy the grub config and any other files we might need
63+
cp $grub_script rootfs/boot/grub2/grub.cfg
64+
touch rootfs/boot/ignition.firstboot
65+
66+
umount -R rootfs

src/grub.cfg

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
set pager=1
2+
3+
if [ -f ${config_directory}/grubenv ]; then
4+
load_env -f ${config_directory}/grubenv
5+
elif [ -s $prefix/grubenv ]; then
6+
load_env
7+
fi
8+
9+
if [ x"${feature_menuentry_id}" = xy ]; then
10+
menuentry_id_option="--id"
11+
else
12+
menuentry_id_option=""
13+
fi
14+
15+
function load_video {
16+
if [ x$feature_all_video_module = xy ]; then
17+
insmod all_video
18+
else
19+
insmod efi_gop
20+
insmod efi_uga
21+
insmod ieee1275_fb
22+
insmod vbe
23+
insmod vga
24+
insmod video_bochs
25+
insmod video_cirrus
26+
fi
27+
}
28+
29+
serial --speed=115200
30+
terminal_input serial console
31+
terminal_output serial console
32+
if [ x$feature_timeout_style = xy ] ; then
33+
set timeout_style=menu
34+
set timeout=1
35+
# Fallback normal timeout code in case the timeout_style feature is
36+
# unavailable.
37+
else
38+
set timeout=1
39+
fi
40+
41+
set ignition_firstboot=""
42+
# Determine if this is a first boot.
43+
if [ -f "/ignition.firstboot" ]; then
44+
set ignition_firstboot="ignition.firstboot"
45+
fi
46+
47+
set root='hd0,gpt1'
48+
set boot='hd0,gpt1'
49+
blscfg

0 commit comments

Comments
 (0)