[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Add a partition into the binary image



I will try to use the functions and helpers from live-helper. I did a
quick test and it seems that this works:

# dd if=/dev/zero of=final.img bs=256M count=1
# dd if=binary.img of=final.img conv=notrunc
# losetup /dev/loop0 final.img
# fdisk /dev/loop0  <-- create the new partition
# losetup -d /dev/loop0
# losetup.sh /dev/loop0 final.img 1
# mkfs.ext3 -L live-rw -F /dev/loop0
# losetup -d /dev/loop0

I will probably look at your script for the "create the new partition"
step. Maybe live-helper has some functions for this too.


It was a bit easier to achieve than expected :) The attached script (lh_final) creates a ext3 partition into the file persistent.img. It then copies binary.img (the Debian live image) into final.img and appends persistent.img to final.img. It finally uses parted to "register" (create) the second partition.

I only tested with qemu so far but it seems to work good :) The ext3 partition is mounted on /live/cow and I now have a persistent system that I can easily copy on a CF card using dd.

Regards,

Cyril
#!/bin/bash

FIN_IMG="final.img"
BIN_IMG="binary.img"

PERS_IMG="persistent.img"
PERS_SIZE="128M"

set -e

if [ ! -f ${BIN_IMG} ]; then
	echo "Live image '${BIN_IMG}' does not exist."
	exit 1
fi

if [ -f ${FIN_IMG} ]; then
	echo "Final image '${FIN_IMG}' already exist. Please remove first."
	exit 1
fi

if [ ! -f ${PERS_IMG} ]; then
	echo -n "Creating persistent partiton (ext3)"
	dd if=/dev/zero of=${PERS_IMG} bs=${PERS_SIZE} count=1 > /dev/null 2>&1 || echo " [failed]"
	mkfs.ext3 -L live-rw -F ${PERS_IMG} > /dev/null 2>&1 || echo " [failed]"
	echo " [done]"
fi

if [ ! -f ${PERS_IMG} ]; then
	echo "Persistent partition '${PERS_IMG}' not found."
	exit 1
fi

echo -n "Copying first partition"
LAST=`dd if=${BIN_IMG} of=${FIN_IMG} 2>&1 | head -n 1 | awk '{ print $1 }'`
echo " [done]"
LAST=${LAST%+0}
echo "Second partition offset is ${LAST}"
echo -n "Copying second (persistent) partition"
dd if=${PERS_IMG} of=${FIN_IMG} seek=${LAST} > /dev/null 2>&1 || echo " [failed]"
echo " [done]"
echo -n "Creating second partition"
parted ${FIN_IMG} mkpart primary ${LAST}s 100% > /dev/null 2>&1 || echo " [failed]"
echo " [done]"
echo "Final image '${FIN_IMG}' created"


Reply to: