Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Building with custom or random DUID instead of static value.
Browse files Browse the repository at this point in the history
  • Loading branch information
jryberg committed Oct 3, 2011
1 parent 2882a54 commit daaf1c9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
17 changes: 17 additions & 0 deletions build-bindist.sh
@@ -1,5 +1,16 @@
#!/bin/sh

# Functions
function getrandomduid {
# Generates a 16 chars long hex string
tempduid=`cat /dev/urandom | tr -dc "a-f0-9" | fold -w 16 | head -1`
echo ${tempduid}
}

DUID=`getrandomduid`

export DUID

mkdir bindist

DISTNAME=WRAP12
Expand Down Expand Up @@ -66,6 +77,12 @@ cp obj/bsd.gz bindist/${DISTNAME}.bsd
gzip image
mv image.gz bindist/${DISTNAME}.image

DISTNAME=PENDRIVE
./build-usbkernel.sh GENERIC-RD ${DUID}
./build-usbimage.sh pendrive ${DUID}
gzip pendrive
mv pendrive.gz bindist/${DISTNAME}.image

DISTNAME=LIVECD
sh ./build-livecd.sh GENERIC-RD
mv obj/live_cd*.iso bindist/
Expand Down
16 changes: 11 additions & 5 deletions build-usbimage.sh
Expand Up @@ -8,6 +8,7 @@ SUDO=sudo
DEVICE=svnd0
MOUNTPOINT=/mnt
TEMPFILE=/tmp/build-diskimage.tmp.$$
DUID=${2}

# This is for boot.conf and should match the kernel ttyspeed.
# Which should be 9600 for GENERIC-RD, 38400 for WRAP12 and 19200 for the rest.
Expand Down Expand Up @@ -39,10 +40,9 @@ cylinders=980 # "cylinders:"
#trackscylinder=16 # "tracks/cylinder:"
#cylinders=994 # "cylinders:"


# Don't start without a imagefile as a parameter
if [ "$1" = "" ]; then
echo "usage: $0 imagefile"
if [ "$1" = "" ] || [ "$DUID" = "" ]; then
echo "usage: $0 imagefile duid"
exit 1
fi

Expand All @@ -54,6 +54,12 @@ if [ ! -r $KERNELFILE ]; then
exit 1
fi

# Check DUID format (hex and 16 char long string)
if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
echo "DUID: ${DUID} is not a 16-character hexadecimal string"
exit
fi;

echo "Cleanup if something failed the last time... (ignore any not currently mounted and Device not configured warnings)"
${SUDO} umount $MOUNTPOINT
${SUDO} vnconfig -u $DEVICE
Expand Down Expand Up @@ -107,10 +113,10 @@ ${SUDO} disklabel -R $DEVICE $TEMPFILE
rm $TEMPFILE

echo ""
echo "Setting duid with disklabel..."
echo "Setting duid to ${DUID} with disklabel..."
${SUDO} disklabel -E $DEVICE << __EOC >/dev/null
i
0123456789abcdef
${DUID}
write
quit
__EOC
Expand Down
13 changes: 12 additions & 1 deletion build-usbkernel-injail.sh
@@ -1,5 +1,11 @@
#!/bin/sh

# Check DUID format (hex and 16 char long string)
if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
echo "DUID: ${DUID} is not a 16-character hexadecimal string"
exit
fi;

# Create dir if not there
mkdir -p obj

Expand All @@ -18,13 +24,18 @@ COPY ${DESTDIR}/sbin/mount_cd9660 sbin/mount_cd9660\
rm list.temp
mv list.temp2 list.temp

# Modify fstab.initial.usb and replace predefined UID with the defined one
sed 's/0123456789abcdef/'"${1}"'/g' initial-conf/fstab.initial.usb > initial-conf/fstab.initial.usb.tmp
rm initial-conf/fstab.initial.usb
mv initial-conf/fstab.initial.usb.tmp initial-conf/fstab.initial.usb

# Cleanup just in case the previous build failed
umount /mnt
vnconfig -u svnd0
make KCONF=${KERNEL} clean

# Make kernel
make termdefs bsd KCONF=${KERNEL} LIST=/list.temp NBLKS=${NBLKS} DISKPROTO=/disktabs/${DISKTAB} $2 $3 $4
make termdefs bsd KCONF=${KERNEL} LIST=/list.temp NBLKS=${NBLKS} DISKPROTO=/disktabs/${DISKTAB}

exit

32 changes: 27 additions & 5 deletions build-usbkernel.sh
Expand Up @@ -2,18 +2,31 @@
#
# Builds a 48MB kernel to put on a USB-stick

# Functions
function getrandomduid {
# Generates a 16 chars long hex string
tempduid=`cat /dev/urandom | tr -dc "a-f0-9" | fold -w 16 | head -1`
echo ${tempduid}
}

CWD=`pwd`
WORKDIR=sandbox
DISKTAB=disktab.48mb
NBLKS=98304
SRCDIR=${BSDSRCDIR:-/usr/src}
DESTDIR=${DESTDIR:-${CWD}/${WORKDIR}}

export SRCDIR DESTDIR CWD WORKDIR DISKTAB NBLKS
DUID=${2:-`getrandomduid`}
export SRCDIR DESTDIR CWD WORKDIR DISKTAB NBLKS DUID

# Don't start without a kernel as a parameter
if [ "$1" = "" ]; then
echo "usage: $0 kernel"
echo "usage: $0 kernel [duid]"
echo
echo "The options are as follows:"
echo "[duid]: Optional 16-character hexadecimal string used as"
echo " disklabel UID for the storage device mounted as /flash"
echo " If unset a random number is generated and printed at"
echo " the end of the script"
exit 1
fi

Expand All @@ -29,6 +42,12 @@ if ! [ -d ${CWD}/${WORKDIR}/dev ]; then
exit
fi

# Check DUID format (hex and 16 char long string)
if [[ "$DUID" != +([[:xdigit:]]) ]] || [[ ${#DUID} != 16 ]]; then
echo "DUID: ${DUID} is not a 16-character hexadecimal string"
exit
fi;

# Which kernel to use?
export KERNEL=$1

Expand Down Expand Up @@ -65,7 +84,7 @@ mkdir -p ${CWD}/obj
umount /mnt

echo "Going into chroot to build kernel"
/usr/sbin/chroot ${CWD}/${WORKDIR} ./build-usbkernel-injail.sh
/usr/sbin/chroot ${CWD}/${WORKDIR} ./build-usbkernel-injail.sh ${DUID}

echo "Comming back from chroot"

Expand All @@ -79,7 +98,7 @@ echo "Building file system"
cd ${CWD}/${WORKDIR}/

# From Makefile that could not run in a chroot
make mr.fs rdsetroot KCONF=${KERNEL} LIST=${CWD}/${WORKDIR}/list.temp NBLKS=${NBLKS} DISKPROTO=${CWD}/${WORKDIR}/disktabs/${DISKTAB} $2 $3 $4
make mr.fs rdsetroot KCONF=${KERNEL} LIST=${CWD}/${WORKDIR}/list.temp NBLKS=${NBLKS} DISKPROTO=${CWD}/${WORKDIR}/disktabs/${DISKTAB}
cp ${CWD}/${WORKDIR}/obj/bsd ${CWD}/${WORKDIR}/obj/bsd.rd
${CWD}/${WORKDIR}/obj/rdsetroot ${CWD}/${WORKDIR}/obj/bsd.rd < ${CWD}/${WORKDIR}/obj/mr.fs
gzip -c9 ${CWD}/${WORKDIR}/obj/bsd.rd > ${CWD}/${WORKDIR}/obj/bsd.gz
Expand All @@ -95,3 +114,6 @@ mv ${CWD}/${WORKDIR}/obj/* ${CWD}/obj/

# Done
echo "Your kernel is stored here ${CWD}/obj/"
echo "The UID that are used in the ramdisk kernel is ${DUID}"
echo "You *MUST* pass this UID to build-usbimage.sh as the second parameter"
echo "or the image will fail to mount /flash."

0 comments on commit daaf1c9

Please sign in to comment.