clic-rpi-image/export-image/prerun.sh

61 lines
1.5 KiB
Bash
Raw Normal View History

2016-05-05 18:43:33 +00:00
#!/bin/bash -e
IMG_FILE="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}.img"
unmount_image ${IMG_FILE}
rm -f ${IMG_FILE}
rm -rf ${ROOTFS_DIR}
mkdir -p ${ROOTFS_DIR}
BOOT_SIZE=$(du -sh ${EXPORT_ROOTFS_DIR}/boot -B M | cut -f 1 | tr -d M)
TOTAL_SIZE=$(du -sh ${EXPORT_ROOTFS_DIR} -B M | cut -f 1 | tr -d M)
IMG_SIZE=$(expr $BOOT_SIZE \* 2 \+ $TOTAL_SIZE \+ 512)M
fallocate -l ${IMG_SIZE} ${IMG_FILE}
fdisk ${IMG_FILE} > /dev/null 2>&1 <<EOF
o
n
8192
+`expr $BOOT_SIZE \* 3`M
p
t
c
n
8192
p
w
EOF
PARTED_OUT=$(parted -s ${IMG_FILE} unit b print)
BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^ 1'| xargs echo -n \
| cut -d" " -f 2 | tr -d B)
BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^ 1'| xargs echo -n \
| cut -d" " -f 4 | tr -d B)
ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^ 2'| xargs echo -n \
| cut -d" " -f 2 | tr -d B)
ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^ 2'| xargs echo -n \
| cut -d" " -f 4 | tr -d B)
BOOT_DEV=$(losetup --show -f -o ${BOOT_OFFSET} --sizelimit ${BOOT_LENGTH} ${IMG_FILE})
ROOT_DEV=$(losetup --show -f -o ${ROOT_OFFSET} --sizelimit ${ROOT_LENGTH} ${IMG_FILE})
echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
2016-05-05 18:43:33 +00:00
2017-02-16 14:36:23 +00:00
mkdosfs -n boot -F 32 -v $BOOT_DEV > /dev/null
2016-05-05 18:43:33 +00:00
mkfs.ext4 -O ^huge_file $ROOT_DEV > /dev/null
mount -v $ROOT_DEV ${ROOTFS_DIR} -t ext4
mkdir -p ${ROOTFS_DIR}/boot
mount -v $BOOT_DEV ${ROOTFS_DIR}/boot -t vfat
rsync -aHAXx ${EXPORT_ROOTFS_DIR}/ ${ROOTFS_DIR}/