Custom FreeBSD usb memstick
Daniel O'Connor
doconnor at gsoft.com.au
Fri Nov 9 00:34:11 UTC 2012
On 09/11/2012, at 8:37, Sam Fourman Jr. <sfourman at gmail.com> wrote:
> I have a interest in playing around with the scripts that create the
> memstick image when you run make release...
> can anyone point me in the right direction, how would I go about
> modifying the size of the partition that gets created on the memstick
> image
It uses makefs to create an image that is just the right size for the files that are included.
I wrote a script that will format a given device and splat the installer stuff on it, ie
cat >make-usb.sh <<EOF
#!/bin/sh
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH
BLOCKSIZE=10240
if [ $# -lt 2 ]; then
echo "$0 device src [path ..]"
echo ""
echo "For example"
echo "$0 destdev srcdir extra1 extra2 ..."
echo ""
echo "For example.."
echo "$0 /dev/da1 /usr/obj/usr/src/release/release /crypt/ros/system/install-os.sh /tmp/image.txz.*"
echo ""
echo "Note that srcdir must have a release built (we need the boot loader from it)"
echo "If the path is a directory its contents will be copied"
exit 1
fi
if [ ! -c "${1}" ]; then
echo "${1} isn't a device"
exit 1
fi
DEV="${1}"
shift
SRC="${1}"
shift
DIRS="$@"
for d in $DIRS; do
if [ ! -e "${d}" ]; then
echo "${d} doesn't exist"
exit 1
fi
done
echo "WARNING WARNING WARNING WARNING WARNING WARNING"
echo "Continuing will destroy all data on ${DEV}"
echo "WARNING WARNING WARNING WARNING WARNING WARNING"
echo "Do you wish to continue? (y/n)"
read answer
if [ $answer != "y" ]; then
echo "Aborting"
exit 0
fi
TMPDIR=`mktemp -d -q /tmp/makeusb.XXXXXX`
if [ $? -ne 0 ]; then
echo "Unable to create temporary directory"
exit 1
fi
mkdir "${TMPDIR}/mnt"
gpart destroy -F ${DEV} || echo -n
gpart create -s GPT ${DEV}
gpart add -t freebsd-boot -s 64K ${DEV}
gpart bootcode -b ${SRC}/boot/pmbr -p ${SRC}/boot/gptboot -i 1 ${DEV}
gpart add -t freebsd-ufs -l FreeBSD_Install ${DEV}
newfs "${DEV}p2"
mount "${DEV}p2" "${TMPDIR}/mnt"
tar -C "${SRC}" -cf - . | tar -C "${TMPDIR}/mnt" -xf -
for d in ${DIRS}; do
if [ -d "${d}" ]; then
tar -C "${d}" -cf - . | tar -C "${TMPDIR}/mnt" -xf -
else
cp -pRP "${d}" "${TMPDIR}/mnt"
fi
done
echo '/dev/gpt/FreeBSD_Install / ufs ro,noatime 1 1' > ${TMPDIR}/mnt/etc/fstab
sync
umount "${TMPDIR}/mnt"
rm -rf "${TMPDIR}"
EOF
The usage example is specific to my work - I have a big tarball full of preinstalled ports which the script copies to the USB key along with a script to install it, but you don't need that, just run..
sh ./make-usb.sh /dev/da1 /usr/obj/usr/src/release/release
(Obviously /dev/da1 should be your USB key, check dmesg etc etc)
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
More information about the freebsd-hackers
mailing list