forked from jwrdegoede/sunxi-fedora-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-image.sh
More file actions
executable file
·88 lines (76 loc) · 2.46 KB
/
build-image.sh
File metadata and controls
executable file
·88 lines (76 loc) · 2.46 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# This script builds a Fedora ARM Allwinner sunxi image, as input it takes
# uboot.tar.gz and rootfs.tar.gz tarbals as build by build-boot-root.sh
# and an *unzipped* Fedora ARM panda sdcard image
#
# This script expects to be run from a directory which contains the
# uboot.tar.gz and rootfs.tar.gz files
#
# This script expects /dev/$LOOP to be free for its use
set -e
if [ "$1" = "--nocopy" ]; then
NOCOPY=1
shift
fi
if [ $# != 2 ]; then
echo "Usage $0 <Fedora-arm-panda-img-in> <Fedora-arm-a10-img-out>"
exit 1
fi
if [ "$(id -u)" != 0 ]; then
echo "$0 must be run as root to be able to setup loop devices"
exit 1
fi
LOOP=loop5
IMG_IN="$1"
IMG_OUT="$2"
UBOOT="$(pwd)/uboot"
ROOTFS="$(pwd)/rootfs"
if [ -z "$NOCOPY" ]; then
echo "Copying $IMG_IN to $IMG_OUT"
cp "$IMG_IN" "$IMG_OUT"
fi
echo "Setting up loopback mount of $IMG_OUT and its partitions"
losetup "/dev/$LOOP" "$IMG_OUT"
kpartx -a "/dev/$LOOP"
udevadm settle
mkdir -p "$UBOOT"
mount "/dev/mapper/${LOOP}p1" "$UBOOT"
mkdir -p "$ROOTFS"
mount "/dev/mapper/${LOOP}p3" "$ROOTFS"
echo "Clearing uboot area"
dd if=/dev/zero of="/dev/$LOOP" bs=1024 seek=8 count=1016
echo "Cleaning panda uboot files and copying sunxi uboot files"
pushd "$UBOOT" > /dev/null
rm -rf *
tar xfz "$UBOOT.tar.gz" --no-same-owner --no-same-permissions
popd > /dev/null
echo "Cleaning panda specific rootfs files and copying sunxi rootfs files"
pushd "$ROOTFS" > /dev/null
rm -rf usr/lib/modules/*
tar xfz "$ROOTFS.tar.gz" --no-overwrite-dir
echo "Customizing sunxi rootfs"
sed -i 's/panda/sunxi/' etc/hostname etc/sysconfig/network
if ! grep -q exclude=kernel-omap etc/yum.conf; then
sed -i 's/installonly_limit=3/installonly_limit=3\nexclude=kernel-omap*/' etc/yum.conf
fi
for i in 'abrt*' atd irqbalance mdmonitor rngd rpcbind sendmail sm-client smartd; do
rm -f etc/systemd/system/multi-user.target.wants/$i.service
done
rm -f etc/systemd/system/spice-vdagentd.target.wants/spice-vdagentd.service
rm -f etc/systemd/system/sysinit.target.wants/mdmonitor-takeover.service
# We don't use plymouth (no initrd) so mask it
pushd usr/lib > /dev/null
for i in systemd/system/*plymouth*.service; do
ln -f -s /dev/null ../../etc/$i
done
popd > /dev/null
popd > /dev/null
echo "Cleaning up loopback mounts"
# wait for udev rules / udisksd to stop poking things, causing -EBUSY errors
sleep 1
umount "$ROOTFS"
umount "$UBOOT"
kpartx -d "/dev/$LOOP"
losetup -d "/dev/$LOOP"
echo "$IMG_OUT is ready for dd-ing to an sdcard"