forked from radxa/rk-rootfs-build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmk-image.sh
executable file
·47 lines (34 loc) · 863 Bytes
/
mk-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 -e
TARGET_ROOTFS_DIR=./binary
MOUNTPOINT=./rootfs
ROOTFSIMAGE=linaro-rootfs.img
OUT=../out
echo Making rootfs!
if [ -e ${ROOTFSIMAGE} ]; then
rm ${ROOTFSIMAGE}
fi
if [ -e ${MOUNTPOINT} ]; then
rm -r ${MOUNTPOINT}
fi
# Create directories
mkdir ${MOUNTPOINT}
dd if=/dev/zero of=${ROOTFSIMAGE} bs=1M count=0 seek=4000
finish() {
sudo umount ${MOUNTPOINT} || true
echo -e "\e[31m MAKE ROOTFS FAILED.\e[0m"
exit -1
}
echo Format rootfs to ext4
mkfs.ext4 ${ROOTFSIMAGE}
echo Mount rootfs to ${MOUNTPOINT}
sudo mount ${ROOTFSIMAGE} ${MOUNTPOINT}
trap finish ERR
echo Copy rootfs to ${MOUNTPOINT}
sudo cp -rfp ${TARGET_ROOTFS_DIR}/* ${MOUNTPOINT}
echo Umount rootfs
sudo umount ${MOUNTPOINT}
echo Rootfs Image: ${ROOTFSIMAGE}
e2fsck -p -f ${ROOTFSIMAGE}
resize2fs -M ${ROOTFSIMAGE}
[ ! -d ${OUT} ] && mkdir ${OUT}
cp $ROOTFSIMAGE ${OUT}