-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathbuild-livecd-root
executable file
·125 lines (107 loc) · 3.62 KB
/
build-livecd-root
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#
# Builds in /var/tmp by default, you can override this with FDI_BUILD_DIR.
# The temp dir in which things happen is by default deleted when this
# script ends, unless an error happens or the KEEP_TMPDIR variable is set
. $0.conf.sh
function cleanup() {
if [ -n "$KEEP_TMPDIR" ]; then
echo "Not removing tmpdir $tmpdir"
else
echo "* Cleaning up tmp dir"
[ -d $tmpdir ] && rm -rf $tmpdir
fi
}
trap cleanup EXIT
if [ $(id -u) != 0 ]; then
echo "Please run this script as root"
exit 1
fi
which livemedia-creator ksflatten wget >/dev/null || ( echo "Command(s) missing, install required tools" && exit 2 )
echo "* Doing cleanup"
rm -rf fdi-image/tftpboot result/*
srcdir=$(readlink -f $(dirname $0))
destdir=${2:-$srcdir}
kernelcmd=${3:-nomodeset nokaslr}
buildytype=${4:-virt}
tmpdir=$(mktemp -d ${FDI_BUILD_DIR:-/var/tmp}/fdi-XXXXXXXXX)
pushd $srcdir
last_tag=${1:-$(git describe --abbrev=0 --tags)}
last_sha=$(git log --pretty=format:'%h' -n 1)
popd
if [[ "$buildytype" = virt ]]; then
echo "* Using virt mode, make sure virtualization is enabled"
BUILD_OPTS="--iso install.iso"
if [ ! -e install.iso ]; then
echo "* Downloading netboot installation ISO"
wget -O install.iso https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/images/boot.iso
fi
else
echo "* Using non-virt mode, make sure the host system is CentOS 9 Stream"
echo " (This mode can destroy the host system, only use dedicated VMs!)"
BUILD_OPTS="--no-virt"
fi
echo "* Building ISO (kernel cmdline: $kernelcmd)"
# https://bugzilla.redhat.com/show_bug.cgi?id=1955836 - dmsquash-live-ntfs
# https://bugzilla.redhat.com/show_bug.cgi?id=2034601 - product CentOS Linux workaround
livemedia-creator $BUILD_OPTS --ks fdi-image.ks \
--make-iso \
--nomacboot \
--extra-boot-args "$kernelcmd" \
--project "FDI" \
--releasever "$last_tag/$last_sha" \
--anaconda-arg="--product CentOS Linux" \
--dracut-arg="--xz" \
--dracut-arg="--no-hostonly" \
--dracut-arg="--debug" \
--dracut-arg="--no-early-microcode" \
--dracut-arg="--omit plymouth" \
--dracut-arg="--add livenet dmsquash-live convertfs pollcdrom qemu qemu-net" \
--dracut-arg="--add-drivers mptbase mptscsih mptspi hv_storvsc hid_hyperv hv_netvsc hv_vmbus" \
--tmp "$tmpdir"
if [ $? -ne 0 ]; then
echo "Error creating livecd, use KEEP_TMPDIR to investigate"
tail -n 2000 *log
exit 1
fi
# Move manually, --resultdir lorax option does not work correctly on CentOS8
mkdir -p "$destdir"
echo "* Moving the ISO to the destination directory"
DEST_ISO="$destdir/fdi-$last_tag-$last_sha.iso"
mv -f $tmpdir/lmc-*/images/boot.iso "$DEST_ISO"
chown --reference $srcdir/build-kickstart "$DEST_ISO"
echo "* Converting to initrd"
echo $DEST_ISO
aux/livecd-iso-to-pxeboot "$DEST_ISO"
rm -rf tftpboot/pxelinux.{cfg,0}
mv tftpboot/initrd.img tftpboot/initrd0.img
mv tftpboot/vmlinuz tftpboot/vmlinuz0
chmod 644 tftpboot/*
chown -R --reference $srcdir/build-kickstart "tftpboot"
mv tftpboot fdi-image
if [ $? -ne 0 ]; then
echo "Error building PXE files, use KEEP_TMPDIR to investigate"
exit 1
fi
echo "* Calculating SHA sums"
pushd fdi-image
cat > README <<EOF
Foreman Discovery Image $last_tag ($last_sha)
To verify the kernel and initrd, run
sha512sum -c SHA512SUM
EOF
sha512sum tftpboot/initrd0.img tftpboot/vmlinuz0 > SHA512SUM
popd
echo "* Moving to the destination folder"
DEST_TAR="$destdir/fdi-image-$last_tag-$last_sha.tar"
tar cf $DEST_TAR fdi-image/
chown --reference $srcdir/build-kickstart $DEST_TAR
echo ""
echo "##########################"
echo "##########################"
echo "Done"
echo "ISO: $DEST_ISO"
echo "##########################"
echo "##########################"
echo "##########################"
exit 0