How to repartition bootable flash install media?

When using 8GB or more USB sticks, the bootable install images for FreeBSD or PC-BSD leave unused space that I'd like to repartition and use with Windows or Linux. This new FAT partition must be the first (since Windows does not want to mount anything else from removable media even if it appears in the disk management console).

Is there a way to strip the downloaded install image from its embedded MBR and partition table in order to dump only the filesystem to a bootable second partition on the USB stick?
 
The memory stick images don't even have an MBR, just a "dangerously dedicated" bsdlabel. It should be possible to create an MBR with a couple of slices, then dd(1) the memory stick image to one of those slices. The memory stick would have to be made bootable, and to boot from the FreeBSD slice, it would have to be set active.
 
wblock@ said:
The memory stick images don't even have an MBR, just a "dangerously dedicated" bsdlabel.

This might be the reason, why I didn't manage to reformat such a stick. Not even zeroing the MBR-area worked, resulting that I marked my stick "NO USE".

Now the question I have is: How can such a "dangerously dedicated" stick be made usuable again for normal use? I failed with fdisk, gpart and bsdlabel altogether.
 
I modded bootable FreeBSD and PC-BSD install sticks with the following commands.

The UFS label of the root partition is 'interesting': FreeBSD-9.1-RELEASE-i386-memstick.img mounts root from /dev/ufs/FreeBSD_Install but I could not put the same label on the new 2nd partition because newfs -L refuses the '_' character. I found the ufsid with gpart list (when partition not mounted) and edited fstab to mount root from /dev/ufsid/$ufsid.
Is there another command older than gpart, newfs, tunefs to label with something containing '_'? No problem with PC-BSD mounting root from PCBSDUSB label.

Code:
#size FAT32 partition = previously unused space
gpart add -s 3684M -t fat32 da0
newfs_msdos -F32 /dev/da0s1

gpart add -t freebsd da0
gpart create -s bsd da0s2
gpart add -t freebsd-ufs da0s2
gpart bootcode -b /boot/mbr da0
gpart bootcode -b /boot/boot da0s2

mdconfig -a -t vnode -f PCBSD-9.1-x86-USBFULL.img
#md0 
mount -o ro /dev/md0a /mnt/img
LABEL=$(grep " / " /mnt/img/etc/fstab | awk "{print \$1}")
newfs -E -n -m 5 -L $LABEL /dev/da0s2a
umount /mnt/img

mount -o noatime /dev/da0s2a /mnt/usb0
pushd /mnt/usb0
dump -0arf - /dev/md0a | restore rvf -
popd
mdconfig -d -u 0
umount /mnt/usb0

gpart set -a active -i 2 da0
 
Back
Top