Draco's Weblog

My Personal Programming & Electronics Journal.

Format Disk to MS-DOS FAT

| Comments

Formatting a USB stick or external drive into MS-DOS FAT32 file system.

We will be using gpart utility as well as newfs_msdos

Follow these steps, run as root.

1
2
3
4
# dd if=/dev/zero of=/dev/da0 bs=1k count=1
# gpart create -s mbr da0
# gpart add -t "\!11" da0
# newfs_msdos -F32 /dev/da0s1

Line 1: We will first clear the partition info using dd command, make sure you use the right device name: /dev/da0 in my case.

Line 2: Create an MBR (Master Boot Record) on that device. Line 3: Add a new mbr partition, we use !11 type for mbr (with proper escaping for BASH),

when I used the mbr type gpart didn’t recognize it.

Line 4: Constructs a new MS-DOS FAT file system of type 32.

Convert BIN/CUE Image to ISO/CDR

| Comments

If you are familiar with torrents, you might have downloaded a bin/cue cd image before.

The bin/cue CD format is used by some non-Unix cd-writing software, but it’s not supported by most other programs. image.bin is the raw cd image, and image.cue is the track index file containing track types and offsets.

On FreeBSD I’ll be using the bchunk command. Read more on the man page bchunk(1)

You can install bchunk from ports, first update your ports tree and then build it.

1
2
3
# portsnap fetch update
# cd /usr/ports/sysutils/bchunk
# make install clean

Then just run bchunk.

1
# bchunk -v image.bin image.cue basename

The basename is used for the beginning part of the created track files.

This will create a new iso and cdr files which can be mounted to a vnode memory disk.

Mount ISO File Format

| Comments

Sometimes I get files in the iso format, perhaps ripped of a CD or something and I want to use the files without burning it to a CD.

This is the way I do it on FreeBSD.

First open a terminal, then type the following commands,

1
2
# mdconfig -a -t vnode -f path/to/file.iso -u 1
# mount -v -t cd9660 /dev/md1 /media/iso

Where path/to/file.iso is the real path to your file, and /media/iso is where you mount the iso.

You must be root to run these commands. This basically attaches a vnode type memroy disk from that iso file and creates an md device with the number specified in the -u option.

After that I copy the mounted data else where, and then un mount the vnode memory disk created in the above steps.

1
2
# umount /media/iso
# mdconfig -d -u 1

That’s all folks!