mkusb

144 views
Skip to first unread message

s...@9front.org

unread,
May 6, 2012, 11:44:16 PM5/6/12
to 9fr...@googlegroups.com
NAME
mkusb - create a bootable USB device

DESCRIPTION
This script will make bootable a USB device. If the 9fat
partition is made large enough, the entire 9front.iso may
be copied into the root of the partition and used to boot
a stand alone terminal.

SYNOPSIS
mkusb [-dw] device

OPTIONS
-d create the bootable device
-w wipe the device

SEE ALSO
prep(8), /sys/src/boot/pc/mkfile

-sl

---

#!/bin/rc

# create bootable usb

fn logprog{
echo $"*
$*
}

fn dev{
dev=$1
cd /sys/src/boot/pc && mk 9bootfat mbr pbs
dev/mbr -m mbr $dev/data
dev/fdev -baw $dev/data
echo
echo 'This is dev/prep; use it to create a 9fat partition.'
echo 'NOTE: FAT16 partitions such as 9fat are limited to 2GB.'
echo 'When finished, type ''w'' and then ''q''.'
echo
dev/prep -b $dev/plan9
dev/format -b pbs -d -r 2 $dev/9fat
dossrv -f $dev/9fat usb.dos
mount -c /srv/usb.dos /n/usb.9fat
{
echo 'bootfile=/$cputype/9pcf'
echo 'mouseport=ask'
echo 'monitor=ask'
echo 'vgasize=ask'
} >/n/usb.9fat/plan9.ini
logprog cp 9bootfat /n/usb.9fat
logprog mkdir /n/usb.9fat/$cputype
logprog cp /$cputype/9pcf /n/usb.9fat/$cputype
unmount /n/usb.9fat
rm -f /srv/usb.dos
}

fn wipe{
dev=$1
echo 'echo delpart plan9 >'$"dev'/ctl'
echo delpart plan9 >$dev/ctl >[2]/dev/null
echo 'echo delpart 9fat >'$"dev'/ctl'
echo delpart 9fat >$dev/ctl >[2]/dev/null
logprog dd -if /dev/zero -of $dev/data -bs 51dev -count 4
}

fn usage{
echo usage: $0 [ -d device ] [ -w device ] >[1=2]
exit usage
}

if(! ~ $1 -* || ~ $#2 0)
usage

switch($1){
case -d
dev $2
case -w
wipe $2
case *
usage
}

Jens Staal

unread,
May 7, 2012, 1:25:51 AM5/7/12
to 9fr...@googlegroups.com
2012/5/7 <s...@9front.org>:
> NAME
>        mkusb - create a bootable USB device
>

Nice!

I was recently trying to boot the 9front.iso with syslinux since my
CD/DVD drive on my new laptop apparently reads the CD wrong
(complaints about corrupt file system during boot). This did
unfortunately not work (no idea why - syslinux does not give any
messages as far as I can see why it does not try to boot the iso).
Otherwise that would have been a very nice way to make bootable USBs.

Now I probably should try to make a bootable USB with this tool from a
9front instance running in a VM I guess :)

cinap_...@gmx.de

unread,
May 7, 2012, 3:36:37 AM5/7/12
to 9fr...@googlegroups.com
small suggesttion to the whipe part:

dev = /dev/sdXX
...

# remove sd partitions
awk '/^part/{if($2!="data"){print "delpart "$2}}' $dev/ctl >$dev/ctl

somehow, that code got garbled. theres dev/mbr and stuff that all
do not make any sense.

for the prep stuff... why not just create a single big dos partition
with disk/fdisk? or just check if its already formated with fat32
and just install the bootloader/kernel and copy the iso? (basicly
just disk/mbr and disk/format to install pbs)

we dont really need a plan9 partition table for this. 9bootfat is
perfectly capable of just sitting in a random dos partition.

the real problem i see is that disk/format doesnt format fat32.

i dont see how this script is usb related at all. all you need for
usb boot is make a fat filesystem with bootloader+kernel in it
on a harddrive.

--
cinap

cinap_...@gmx.de

unread,
May 7, 2012, 4:07:09 AM5/7/12
to 9fr...@googlegroups.com
there should be a generic way of making a harddrive bootable.
then we could just use this from the installer instead of
/rc/bin/inst/bootsetup and also use it to make usb drives
bootable.

something like:

mkbootfat [-b] /dev/sdXX

the -b switch would try to make everything from scratch:
- whipe
- install mbr
- make single dos partition (fdisk)
- format the dos partition

normal procedure is like:
- look for 9fat and dos partitions, let the user select one if multiple
choices are present.
- install pbs on dos partition (disk/format -b)
- mount and copy 9bootfat+kernel+plan9.ini to dos partition
- make dos partition active and optionally install mbr if not already done

--
cinap

s...@9front.org

unread,
May 7, 2012, 4:04:31 PM5/7/12
to 9fr...@googlegroups.com
> i dont see how this script is usb related at all. all you need for
> usb boot is make a fat filesystem with bootloader+kernel in it
> on a harddrive.

Of course you're right. This started as a blunt tool for myself,
then I thought it might be useful for others.

Some of it is poorly thought out.

-sl

s...@9front.org

unread,
May 7, 2012, 9:21:09 PM5/7/12
to 9fr...@googlegroups.com
This seems by far the best approach. I've repaired my hack of convenience,
but will aim for something general enough to be called by the installer.

-sl
Reply all
Reply to author
Forward
0 new messages