forked from pguyot/arm-runner-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmount_image.sh
46 lines (38 loc) · 1.31 KB
/
mount_image.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
#!/bin/bash
set -uo pipefail
image=$1
additional_mb=$2
if [ ${additional_mb} -gt 0 ]; then
dd if=/dev/zero bs=1M count=${additional_mb} >> ${image}
fi
loopdev=$(losetup --find --show ${image})
echo "Created loopback device ${loopdev}"
echo "::set-output name=loopdev::${loopdev}"
if [ ${additional_mb} -gt 0 ]; then
parted --script "${loopdev}" resizepart 2 100%
e2fsck -p -f "${loopdev}p2"
resize2fs "${loopdev}p2"
echo "Finished resizing disk image."
fi
partprobe "${loopdev}"
bootdev=$(ls "${loopdev}"*1)
rootdev=$(ls "${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
mount --bind /proc "${mount}/proc"
mount --bind /sys "${mount}/sys"
mount --bind /dev "${mount}/dev"
mount --bind /dev/pts "${mount}/dev/pts"
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 "${mount}/etc/ld.so.preload" "${mount}/etc/_ld.so.preload"
echo "" > "${mount}/etc/ld.so.preload"