-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-image
More file actions
executable file
·75 lines (61 loc) · 2.01 KB
/
create-image
File metadata and controls
executable file
·75 lines (61 loc) · 2.01 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
#!/bin/bash
# Define variables
IMAGE_NAME="roomplayer.img"
ROOTFS_TAR="rootfs.tar"
IMAGE="uImage"
cd output
# Create a 4GB image file with a block size of 256KB
dd if=/dev/zero of=${IMAGE_NAME} bs=256K count=14800
# Create partitions in the image
# This will use 'sfdisk' for non-interactive partitioning
sfdisk ${IMAGE_NAME} << EOF
,50M,c
,1G,83
,1G,83
,,83
EOF
# Map image to loop device
loop_device=$(losetup -f --show -P ${IMAGE_NAME})
# Format partitions
mkfs.vfat -n "BOOT" ${loop_device}p1 # Partition 1 (50MB VFAT for kernel/bootloader)
mkfs.ext4 -L "rootfs1" ${loop_device}p2 # Partition 2 (1GB ext4 root filesystem)
mkfs.ext4 -L "rootfs2" ${loop_device}p3 # Partition 3 (1GB ext4 second root filesystem)
mkfs.ext4 -L "DATA" ${loop_device}p4 # Partition 4 (Remaining space as ext4 for data)
# Mount partition 2
mkdir -p /mnt/rootfs2
mount ${loop_device}p2 /mnt/rootfs2
#mkdir -p /mnt/rootfs3
#mount ${loop_device}p3 /mnt/rootfs3
mkdir -p /mnt/kernel
mount ${loop_device}p1 /mnt/kernel
# Check if the rootfs.tar file exists
if [[ -f ${ROOTFS_TAR} ]]; then
# Copy and extract the rootfs.tar into partition 2
tar -xf ${ROOTFS_TAR} -C /mnt/rootfs2
#dd if=${ROOTFS_EXT4} of=${loop_device}p2 bs=256K status=progress
#tar -xf ${ROOTFS_TAR} -C /mnt/rootfs3
else
echo "Error: ${ROOTFS_TAR} not found!"
exit 1
fi
if [[ -f ${IMAGE} ]]; then
# Copy and extract the rootfs.tar into partition 2
cp ${IMAGE} /mnt/kernel
touch /mnt/kernel/rfspart
echo "rfspart=2" > /mnt/kernel/rfspart
touch /mnt/kernel/bootargs
echo "mainbootargs=console=ttyS0,115200n8 drm.debug=7 root=/dev/mmcblk0p\${rfspart} ro rootfstype=ext4 rootwait" > /mnt/kernel/bootargs
else
echo "Error: ${IMAGE} not found!"
exit 1
fi
# Unmount the partition
umount /mnt/rootfs2
#umount /mnt/rootfs3
umount /mnt/kernel
rm -r /mnt/rootfs*
rm -r /mnt/kernel
# Unmount the loop device
losetup -d ${loop_device}
gzip -9 -k -f $IMAGE_NAME
echo "Disk image created, partitions formatted, and root filesystem extracted successfully!"