assemble_image.sh 3.22 KB
Newer Older
1
2
#!/bin/bash

OSAK Buildhauer's avatar
OSAK Buildhauer committed
3
set -e
4
5
set -x

6
image_size="6600M"
7
8
9
img1="kubuntu-20.04.3-desktop-amd64.iso"
img2="kubuntu-21.10-desktop-amd64.iso"
bootimg="$img1"
10
: ${workspace:="/workspace"}
11
12
13
14
15
16
17
: ${USE_OFFLINE_REPO:=0}
if [[ "$USE_OFFLINE_REPO" -eq 1 ]]
then
    offlinerepo1='archives-focal'
    offlinerepo2='archives-impish'
    image_size='13G'
fi
18
19

# mtools, ddrescure, fdisk, grub, 7z
20
21
rm -rf "$workspace/part_files"
mkdir -p "$workspace/part_files"
22
23
# copy only relevant files
git -C "$workspace/part_files" clone --depth 1 --single-branch --branch tardis https://git.fsmpi.rwth-aachen.de/osak/lipstick.git .
24
25
26
27
28
rsync -av /usr/lib/grub/i386-efi "$workspace/part_files"/grub
rsync -av /usr/lib/grub/i386-pc "$workspace/part_files"/grub
rsync -av /usr/share/grub/themes "$workspace/part_files"/grub
mkdir -p "$workspace/part_files"/grub/fonts/
rsync -av /usr/share/grub/unicode.pf2 "$workspace/part_files"/grub/fonts/
29

30
31
7z x "$bootimg" -o"$workspace/part_files" EFI/
7z x "$bootimg" -o"$workspace/part_files" boot/grub/x86_64-efi
32

33
34
mv "$workspace/part_files"/grub/* "$workspace/part_files"/boot/grub/
rm -rf "$workspace/part_files"/grub
35

36
37
rsync --copy-links --size-only --checksum "$img1" "$workspace/part_files/"
rsync --copy-links --size-only --checksum "$img2" "$workspace/part_files/"
OSAK Buildhauer's avatar
OSAK Buildhauer committed
38
39
40

source ./grub_config.sh # functions to fill grub_template.cfg
cp grub_template.cfg "$workspace/part_files/boot/grub/grub.cfg"
41
42
43
fill_grub_config_template "$img1" "$workspace/part_files/boot/grub/grub.cfg"
fill_grub_config_template "$img2" "$workspace/part_files/boot/grub/grub.cfg"

44
45
46
47
48
49
50
51
if [[ "$USE_OFFLINE_REPO" -eq 1 ]]
then
    # Note: in practice you might still want to create the offline repo separately and just copy or move the directories here.
    # Creating the offline repo requires root privileges and can be quite slow.
    ./create_offlinerepo.sh "$workspace/part_files/$offlinerepo1" "$img1" $(grep '^[^#]' packages | cut -d'|' -f 2)
    ./create_offlinerepo.sh "$workspace/part_files/$offlinerepo2" "$img2" $(grep '^[^#]' packages | cut -d'|' -f 2)
fi

52
cp packages "$workspace/part_files/packages"
53
54
# The following command is dangerous: If offline repo is missing and "download updates while installing" is selected (default), this will install ALL listed packages during the installation.
#echo "ubiquity ubiquity/keep-installed string $(grep '^[^#]' packages | cut -d'|' -f 2 | tr '\n' ' ')" >> "$workspace/part_files/preseed/lip.seed"
55

56
rm -f "$workspace/part.img"
57
58
truncate -s "$image_size" "$workspace/part.img"
mkfs.vfat -n "LIPSTICK" "$workspace/part.img"
59
# Note: in *ubuntu 21.10 mcopy has a bug and option "-b" should be removed.
60
MTOOLS_SKIP_CHECK=1 mcopy -i "$workspace/part.img" -b -s -v "$workspace/part_files"/* "$workspace/part_files"/.git ::
61
rm -rf "$workspace/part_files"
62
63
64
65
66
grub-mkimage --prefix "(hd0,msdos1)/boot/grub" --output "$workspace/grub.i386-pc.img" --format "i386-pc" part_msdos fat ext2 biosdisk
dd if=/usr/lib/grub/i386-pc/boot.img of="$workspace/output.img" bs=446 count=1
dd if="$workspace/grub.i386-pc.img" of="$workspace/output.img" bs=512 seek=1
ddrescue --output-position=2048s --sparse "$workspace/part.img" "$workspace/output.img"
printf "label: dos\nunit: sectors\n2048,+,b,*\n" | sfdisk "$workspace/output.img"
67
echo "Used $(du -s -h "$workspace/output.img" | cut -f1) of ${image_size}"