Skip to content

Commit 765abce

Browse files
committed
implemented ADDPART command
ADDPART appends a partition in the SIZE with a partition type and file system
1 parent b608d15 commit 765abce

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ FROM debian:bookworm-slim
22

33
LABEL description="Reconfigure Raspberry Pi images with an easy, Docker-like configuration file"
44
LABEL maintainer="[email protected]"
5-
LABEL version="0.6.1"
5+
LABEL version="0.7.0"
66

77
RUN bash
88

99
RUN apt-get update && \
1010
apt-get install -y \
1111
binfmt-support \
12+
exfatprogs \
1213
fdisk \
1314
file \
1415
git \

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ This is an alternative to `FROM` and `TO`.
198198
##### `PUMP SIZE`
199199
`PUMP` increases the image's size about the given amount (suffixes K, M, G are allowed).
200200

201+
##### `ADDPART SIZE PTYPE FS`
202+
`PUMP` appends a partition of the size (suffixes K, M, G are allowed) using a partion type and file system (ext4, exfat, ...).
203+
201204
#### 3. Chroot Stage
202205
##### `INSTALL <MODE> SOURCE DEST`
203206
`INSTALL` installs a given file or directory into the destination in the image.

stages/00-commands.sh

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ PUMP() {
4444
:
4545
}
4646

47+
ADDPART() {
48+
:
49+
}
50+
4751
# Stage 3x
4852
INSTALL() {
4953
:

stages/20-prepare.sh

+60
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,63 @@ PUMP() {
4242

4343
umount_image "${loop}"
4444
}
45+
46+
# ADDPART adds a partition of a given size, partition type and file system
47+
#
48+
# Usage: ADDPART SIZE PTYPE FS
49+
ADDPART() {
50+
if [ $# -ne 3 ]; then
51+
echo -e "\033[0;31m### Error: usage ADDPART SIZE PTYPE FS\033[0m"
52+
return 1
53+
fi
54+
55+
echo -e "\033[0;32m### ADDPART ${1} ${2} ${3}\033[0m"
56+
57+
if [[ -b "${DEST_IMG}" ]]; then
58+
echo -e "\033[0;31m### Error: Block device ${DEST_IMG} cannot be altered.\033[0m"
59+
return 1
60+
fi
61+
62+
BS="1M"
63+
64+
# units does not print to stderr, thus test call before using output
65+
echo -n "addpart conversion to ${BS} * "
66+
units -t "${1}B" "${BS}B"
67+
68+
COUNT=$(units -t ${1}B ${BS}B)
69+
70+
# Ceil the number if a decimal is given.
71+
if [[ "${COUNT}" == *.* ]]; then
72+
COUNT=$(( $(echo "${COUNT}" | cut -d. -f1) + 1 ))
73+
fi
74+
75+
echo "addpart ceil: ${BS} * ${COUNT}"
76+
77+
# Error on unset PTYPE
78+
if [[ -z ${2+x} ]]; then
79+
echo -e "\033[0;31m### Error: Partition type unspecified, possible options:\033[0m"
80+
sfdisk -T
81+
return 1
82+
fi
83+
84+
echo "checking mkfs.${3}"
85+
86+
if ! command -v mkfs.${3}; then
87+
echo -e "\033[0;31m### Error: file system ${3} is not available.\033[0m"
88+
return 1
89+
fi
90+
91+
dd if=/dev/zero bs="${BS}" count="${COUNT}" >> "${DEST_IMG}"
92+
93+
local data_part_start
94+
data_part_start=$(( $(sfdisk -l "${DEST_IMG}" -o END -n | tail -n1) + 1 ))
95+
96+
echo "$data_part_start,+,${2}" | sfdisk -a "${DEST_IMG}"
97+
98+
local loop
99+
loop=$(mount_image "${DEST_IMG}")
100+
101+
mkfs.${3} "/dev/mapper/${loop}p$((IMG_ROOT + 1))"
102+
103+
umount_image "${loop}"
104+
}

0 commit comments

Comments
 (0)