forked from pguyot/arm-runner-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmount_image.sh
More file actions
71 lines (62 loc) · 2.1 KB
/
mount_image.sh
File metadata and controls
71 lines (62 loc) · 2.1 KB
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
#!/bin/bash
set -uo pipefail
image=$1
additional_mb=$2
use_systemd_nspawn=$3
if [ ${additional_mb} -gt 0 ]; then
dd if=/dev/zero bs=1M count=${additional_mb} >> ${image}
fi
loopdev=$(losetup --find --show --partscan ${image})
echo "Created loopback device ${loopdev}"
echo "::set-output name=loopdev::${loopdev}"
if [ ${additional_mb} -gt 0 ]; then
if ( (parted --script $loopdev print || false) | grep "Partition Table: gpt" > /dev/null); then
sgdisk -e "${loopdev}"
fi
parted --script "${loopdev}" resizepart 2 100%
e2fsck -p -f "${loopdev}p2"
resize2fs "${loopdev}p2"
echo "Finished resizing disk image."
fi
waitForFile() {
maxRetries=60
retries=0
until [ -n "$(compgen -G "$1")" ] ; do
retries=$((retries + 1))
if [ $retries -ge $maxRetries ] ; then
echo "Could not find $1 within $maxRetries seconds" >&2
return 1
fi
sleep 1
done
compgen -G "$1"
}
sync
partprobe -s "${loopdev}"
bootdev=$(waitForFile "${loopdev}*1")
rootdev=$(waitForFile "${loopdev}*2")
# Mount the image
mount=${RUNNER_TEMP:-/home/actions/temp}/arm-runner/mnt
mkdir -p ${mount}
echo "::set-output name=mount::${mount}"
[ ! -d "${mount}" ] && mkdir "${mount}"
mount "${rootdev}" "${mount}"
[ ! -d "${mount}/boot" ] && mkdir "${mount}/boot"
mount "${bootdev}" "${mount}/boot"
# Prep the chroot
if [ "${use_systemd_nspawn}x" = "x" -o "${use_systemd_nspawn}x" = "nox" ]; then
mount --bind /proc "${mount}/proc"
mount --bind /sys "${mount}/sys"
mount --bind /dev "${mount}/dev"
mount --bind /dev/pts "${mount}/dev/pts"
fi
cp "${mount}/etc/resolv.conf" "${mount}/etc/_resolv.conf"
cp /etc/resolv.conf "${mount}/etc/resolv.conf"
cp /usr/bin/qemu-arm-static0 ${mount}/usr/bin/qemu-arm-static0
cp /usr/bin/qemu-arm-static ${mount}/usr/bin/qemu-arm-static
cp /usr/bin/qemu-aarch64-static0 ${mount}/usr/bin/qemu-aarch64-static0
cp /usr/bin/qemu-aarch64-static ${mount}/usr/bin/qemu-aarch64-static
if [ -e "${mount}/etc/ld.so.preload" ]; then
cp "${mount}/etc/ld.so.preload" "${mount}/etc/_ld.so.preload"
echo > "${mount}/etc/ld.so.preload"
fi