-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkimage_rv64_uefi.sh
executable file
·84 lines (67 loc) · 1.73 KB
/
mkimage_rv64_uefi.sh
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
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Rivos Inc.
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
d=$(dirname "${BASH_SOURCE[0]}")
rootfs=$1
imagename=$2
tmp=$(mktemp -d)
cleanup() {
rm -rf "$tmp"
}
trap cleanup EXIT
kernel=
modpath=
while getopts k:m: name ; do
case $name in
k)
kernel="$OPTARG"
;;
m)
modpath="$OPTARG"
;;
?)
exit 1
;;
esac
done
shift $(($OPTIND -1))
if [[ ! $kernel ]]; then
tar --extract --file=$rootfs -C $tmp --wildcards './boot/vmlinu?-*' --strip-components=2
kernel=$(echo $tmp/vmlinu?*)
fi
rm -rf $imagename
imsz=1
if [[ -n $modpath ]]; then
imsz=$(du -B 1G -s "$modpath" | awk '{print $1}')
fi
imsz=$(( ${imsz} + 4 ))
eval "$(guestfish --listen)"
guestfish --remote -- \
disk-create "$imagename" raw ${imsz}G : \
add-drive "$imagename" format:raw : \
launch : \
part-init /dev/sda gpt : \
part-add /dev/sda primary 2048 526336 : \
part-add /dev/sda primary 526337 -34 : \
part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B : \
mkfs ext4 /dev/sda2 : \
mount /dev/sda2 / : \
mkdir /boot : \
mkdir /boot/efi : \
mkfs vfat /dev/sda1 : \
mount /dev/sda1 /boot/efi : \
tar-in $rootfs / : \
copy-in $kernel /boot/efi/
if [[ $(basename $kernel) != Image ]]; then
guestfish --remote -- mv /boot/efi/$(basename $kernel) /boot/efi/Image
fi
if [[ $modpath ]]; then
guestfish --remote -- copy-in $modpath /lib/modules/
fi
guestfish --remote -- \
sync : \
umount /boot/efi : \
umount / : \
exit