Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Nov 2012 11:03:55 +1030
From:      "Daniel O'Connor" <doconnor@gsoft.com.au>
To:        "Sam Fourman Jr." <sfourman@gmail.com>
Cc:        hackers@freebsd.org
Subject:   Re: Custom FreeBSD usb memstick
Message-ID:  <BD8160AB-1835-432D-A580-C51B227755BA@gsoft.com.au>
In-Reply-To: <CAOFF%2BZ38yKaproZZmr57fA71RhbZNBo1bApPtTzbOM_Dk3MEgQ@mail.gmail.com>
References:  <CAOFF%2BZ38yKaproZZmr57fA71RhbZNBo1bApPtTzbOM_Dk3MEgQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 09/11/2012, at 8:37, Sam Fourman Jr. <sfourman@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=3D/bin:/usr/bin:/sbin:/usr/sbin
export PATH

BLOCKSIZE=3D10240

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=3D"${1}"

shift
SRC=3D"${1}"
shift
DIRS=3D"$@"

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 !=3D "y" ]; then
  echo "Aborting"
  exit 0
fi

TMPDIR=3D`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









Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BD8160AB-1835-432D-A580-C51B227755BA>