burrow-pi-img/export-image/prerun.sh

69 lines
1.8 KiB
Bash
Raw Normal View History

2016-05-05 18:43:33 +00:00
#!/bin/bash -e
2016-05-05 18:43:33 +00:00
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 --apparent-size -s ${EXPORT_ROOTFS_DIR}/boot --block-size=1 | cut -f 1)
TOTAL_SIZE=$(du --apparent-size -s ${EXPORT_ROOTFS_DIR} --exclude var/cache/apt/archives --block-size=1 | cut -f 1)
2016-05-05 18:43:33 +00:00
IMG_SIZE=$((BOOT_SIZE + TOTAL_SIZE + (800 * 1024 * 1024)))
2016-05-05 18:43:33 +00:00
truncate -s ${IMG_SIZE} ${IMG_FILE}
2017-03-30 16:51:23 +00:00
fdisk -H 255 -S 63 ${IMG_FILE} <<EOF
2016-05-05 18:43:33 +00:00
o
n
8192
2017-03-30 16:51:23 +00:00
+$((BOOT_SIZE * 2 /512))
2016-05-05 18:43:33 +00:00
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
ROOT_FEATURES="^huge_file"
2017-08-10 14:53:18 +00:00
for FEATURE in metadata_csum 64bit; do
if grep -q "$FEATURE" /etc/mke2fs.conf; then
ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES"
fi
done
2017-02-16 14:36:23 +00:00
mkdosfs -n boot -F 32 -v $BOOT_DEV > /dev/null
mkfs.ext4 -O $ROOT_FEATURES $ROOT_DEV > /dev/null
2016-05-05 18:43:33 +00:00
mount -v $ROOT_DEV ${ROOTFS_DIR} -t ext4
mkdir -p ${ROOTFS_DIR}/boot
mount -v $BOOT_DEV ${ROOTFS_DIR}/boot -t vfat
Avoid rsync options -o & -g on vfat My custom build stage was dropping a 2 text files on /boot and that was causing rsync to fail on my stage when it didn't fail on stage2. Before making this change I was getting this error: + mkdosfs -n boot -F 32 -v /dev/loop0 mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows + mkfs.ext4 -O '^huge_file' /dev/loop1 mke2fs 1.42.13 (17-May-2015) + mount -v /dev/loop1 /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs -t ext4 mount: /dev/loop1 mounted on /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs. + mkdir -p /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs/boot + mount -v /dev/loop0 /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs/boot -t vfat mount: /dev/loop0 mounted on /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs/boot. + rsync -aHAXx --exclude var/cache/apt/archives /home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/stage4/rootfs/ /home/ubuntu/ies_rpi/pi-gen/work/201 7-10-04-Raspbian/export-image/rootfs/ rsync: chown "/home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs/boot/.meta-data.57XaxF" failed: Operation not permitted (1) rsync: chown "/home/ubuntu/ies_rpi/pi-gen/work/2017-10-04-Raspbian/export-image/rootfs/boot/.user-data.9Icrdz" failed: Operation not permitted (1) rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
2017-10-04 19:34:46 +00:00
rsync -aHAXx --exclude boot --exclude var/cache/apt/archives ${EXPORT_ROOTFS_DIR}/ ${ROOTFS_DIR}/
rsync -aHAXx --no-o --no-g --exclude var/cache/apt/archives ${EXPORT_ROOTFS_DIR}/boot/ ${ROOTFS_DIR}/boot/