Skip to content

Commit

Permalink
fixed issue that occur when mkfs calculate rootfs size (batch updates)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencetg committed May 10, 2021
1 parent 70a2b91 commit b058aeb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build-boot-img.sh
Expand Up @@ -29,7 +29,7 @@ IMG_SIZE=67108864
TOP=$PWD
true ${MKFS:="${TOP}/tools/make_ext4fs"}

${MKFS} -s -l ${IMG_SIZE} -a root -L boot ${IMG_FILE} ${BOOT_DIR}
${MKFS} -0 -s -l ${IMG_SIZE} -a root -L boot ${IMG_FILE} ${BOOT_DIR}
RET=$?

if [ $RET -eq 0 ]; then
Expand Down
12 changes: 9 additions & 3 deletions build-rootfs-img.sh
Expand Up @@ -33,10 +33,16 @@ if [ $(id -u) -ne 0 ]; then
exit
fi

MKFS_OPTS="-s -a root -L rootfs"
if echo ${TARGET_OS} | grep friendlywrt -i >/dev/null; then
# set default uid/gid to 0
MKFS_OPTS="-0 ${MKFS_OPTS}"
fi
if [ ${IMG_SIZE} -eq 0 ]; then
# calc image size
ROOTFS_SIZE=`du -s -B 1 ${ROOTFS_DIR} | cut -f1`
MAX_IMG_SIZE=7100000000
# +1024m + 10% rootfs size
MAX_IMG_SIZE=$((${ROOTFS_SIZE} + 1024*1024*1024 + ${ROOTFS_SIZE}/10))
TMPFILE=`tempfile`
${MKFS} -s -l ${MAX_IMG_SIZE} -a root -L rootfs /dev/null ${ROOTFS_DIR} > ${TMPFILE}
IMG_SIZE=`cat ${TMPFILE} | grep "Suggest size:" | cut -f2 -d ':' | awk '{gsub(/^\s+|\s+$/, "");print}'`
Expand All @@ -48,13 +54,13 @@ if [ ${IMG_SIZE} -eq 0 ]; then
fi

# make fs
${MKFS} -s -l ${IMG_SIZE} -a root -L rootfs ${IMG_FILE} ${ROOTFS_DIR}
${MKFS} ${MKFS_OPTS} -l ${IMG_SIZE} ${IMG_FILE} ${ROOTFS_DIR}
if [ $? -ne 0 ]; then
echo "error: failed to make rootfs.img."
exit 1
fi
else
${MKFS} -s -l ${IMG_SIZE} -a root -L rootfs ${IMG_FILE} ${ROOTFS_DIR}
${MKFS} ${MKFS_OPTS} -l ${IMG_SIZE} ${IMG_FILE} ${ROOTFS_DIR}
if [ $? -ne 0 ]; then
echo "error: failed to make rootfs.img."
exit 1
Expand Down
Binary file modified tools/make_ext4fs
Binary file not shown.
10 changes: 8 additions & 2 deletions tools/update_kernel_bin_to_img.sh
Expand Up @@ -64,12 +64,18 @@ if [ -f ${TARGET_OS}/rootfs.img ]; then
rm -rf ${OUT}/rootfs_new/lib/modules/*
cp -af ${KMODULES_OUTDIR}/lib/modules/* ${OUT}/rootfs_new/lib/modules/

MKFS_OPTS="-s -a root -L rootfs"
if echo ${TARGET_OS} | grep friendlywrt -i >/dev/null; then
# set default uid/gid to 0
MKFS_OPTS="-0 ${MKFS_OPTS}"
fi

# Make rootfs.img
ROOTFS_DIR=${OUT}/rootfs_new
# calc image size
ROOTFS_SIZE=`du -s -B 1 ${ROOTFS_DIR} | cut -f1`
MAX_IMG_SIZE=7100000000
# +1024m + 10% rootfs size
MAX_IMG_SIZE=$((${ROOTFS_SIZE} + 1024*1024*1024 + ${ROOTFS_SIZE}/10))
TMPFILE=`tempfile`
${MKFS} -s -l ${MAX_IMG_SIZE} -a root -L rootfs /dev/null ${ROOTFS_DIR} > ${TMPFILE}
IMG_SIZE=`cat ${TMPFILE} | grep "Suggest size:" | cut -f2 -d ':' | awk '{gsub(/^\s+|\s+$/, "");print}'`
Expand All @@ -81,7 +87,7 @@ if [ -f ${TARGET_OS}/rootfs.img ]; then
fi

# make fs
${MKFS} -s -l ${IMG_SIZE} -a root -L rootfs ${TARGET_OS}/rootfs.img ${ROOTFS_DIR}
${MKFS} ${MKFS_OPTS} -l ${IMG_SIZE} ${TARGET_OS}/rootfs.img ${ROOTFS_DIR}
if [ $? -ne 0 ]; then
echo "error: failed to make rootfs.img."
exit 1
Expand Down

0 comments on commit b058aeb

Please sign in to comment.