Skip to content

Commit

Permalink
20090904 release:
Browse files Browse the repository at this point in the history
Fix -disk option in flashrd parent script by giving umount up to 30 seconds (for slow flash) (and fix test exit status that skews mkdist end).
Stop zeroing out full vnd image in mkboot and mkdist, makes flashrd runs significantly faster with slow disk or flash.
Stop using kernel auto-disklabel for boot image, instead create our own disklabel with 63 sectors/track (higher chance of image compatibility for folks not able to run growimg).
Make /flash/old revert-on-failure more likely to work in stand/rc.
  • Loading branch information
yellowman committed Jun 2, 2012
1 parent 7758210 commit 5111d98
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 48 deletions.
29 changes: 20 additions & 9 deletions flashrd
Expand Up @@ -6,15 +6,13 @@

date=`date +%Y%m%d`
arch=`uname -m`
vers=20090902
vers=20090904

export device=svnd3 # least likely to conflict ?
export rootdevice=svnd2 # used to mount flash vnd for writing of stuff inside
export blocks=6080 # blocks to reserve for kernel ramdisk
export szezroot=szez.$arch-$date # 6080 flash root
export dest=flashimg.$arch-$date # final product
export count=950 # image block count
export bsize=1m # image block size

export vnddirs="root bin etc sbin usr" # must match vnddirs= in stand/rc and fstab
export vndsize="102400 auto 102400 auto auto" # min partition sizes (or auto) (in 512 byte sectors)
Expand All @@ -27,6 +25,19 @@ set -A mfssize 16384 # mfs sizes (in 512 byte sectors)

set -A part a d e f g h i j k l m n o p

# C/H/S for default "1GB" image, used by mkboot
#
# This is specified to get 63 sectors/track, therefore boot
# blocks work properly on most "disks" without resizing image!
#
# Completely ignored if -disk is specified
export cylinders=968
export trackscylinder=32
export sectorstrack=63
#
# Normally 512 (but, who knows, times they are a changin'!)
export bytessec=512

echo "flashrd $vers chris@nmedia.net"

if [ "$1" == "-disk" ]; then
Expand Down Expand Up @@ -89,13 +100,13 @@ fi
# fall back

4() {
umount -f $tmpmntvnd
umount $tmpmntvnd
}
3() {
vnconfig -u $device
}
2() {
umount -f $tmpmnt
umount $tmpmnt
}
1() {
vnuncfgroot
Expand Down Expand Up @@ -185,7 +196,7 @@ if [ ! -z "$mfsdirs" ]; then
x=0
for i in $mfsdirs; do
echo
echo "swap /$i mfs rw,nodev,nosuid,-s${mfssize[$x]} 0 0" >> $tmpfstab
echo "swap /$i mfs rw,nodev,nosuid,-s${mfssize[$x]} 0 0" >> $tmpfstab
let x=x+1
done
fi
Expand Down Expand Up @@ -235,7 +246,7 @@ c 4 mv $tmpfstab $tmpmntvnd/fstab

c 4 "echo $vers > $tmpmntvnd/.flashrd_version"

c 3 umount $tmpmntvnd
umountwait 3 $tmpmntvnd

###
#
Expand All @@ -245,15 +256,15 @@ c 3 mount /dev/$device$binpart $tmpmntvnd

c 4 cp bin/ro bin/rw $tmpmntvnd/

c 3 umount $tmpmntvnd
umountwait 3 $tmpmntvnd

###
#
# done with the main disk vnd

c 2 vnconfig -u $device

c 1 umount $tmpmnt
umountwait 1 $tmpmnt

###
#
Expand Down
18 changes: 18 additions & 0 deletions flashrd.sub
Expand Up @@ -30,3 +30,21 @@ c() {
}
fi
}

###
#
# Wait up to 30 seconds for the kernel to catch up,
# otherwise give up umount with fallback harness

umountwait() {
y=1

while ! umount $2 2>/dev/null; do
echo -n "...$y"
sleep 1
let y=y+1
if [ "$y" -gt 30 ]; then
c $1 umount $2
fi
done
}
2 changes: 1 addition & 1 deletion growimg
Expand Up @@ -188,7 +188,7 @@ cat <<-__New >>$NewLabel
if [ -z "$alt" ]; then
echo
echo Creating new image...
dd if=/dev/zero bs=$bytessec count=32 of=$NewImg >/dev/null
dd if=/dev/zero bs=$bytessec count=$bytessec of=$NewImg >/dev/null

if ! vnconfig $device $NewImg; then
echo % vnconfig failure
Expand Down
78 changes: 46 additions & 32 deletions mkboot
Expand Up @@ -7,25 +7,19 @@
date=`date +%Y%m%d`
arch=`uname -m`

if [ -z "$rootdevice" ]; then
export rootdevice=svnd3
fi
[ -z "$rootdevice" ] && export rootdevice=svnd3

if [ -z "$count" ]; then
export count=1024
fi
[ -z "$cylinders" ] && cylinders=968

if [ -z "$bsize" ]; then
export bsize=1m
fi
[ -z "$trackscylinder" ] && trackscylinder=32

if [ -z "$dest" ]; then
dest=flashimg.$arch-$date
fi
[ -z "$sectorstrack" ] && sectorstrack=63

if [ -z "$tmpmnt" ]; then
tmpmnt=`mktemp -d /tmp/mkboot.XXXXXXXX`
fi
[ -z "$bytessec" ] && bytessec=512

[ -z "$dest" ] && dest=flashimg.$arch-$date

[ -z "$tmpmnt" ] && tmpmnt=`mktemp -d /tmp/mkboot.XXXXXXXX`

vncfgroot() {
[ -z "$novnd" ] && c 0 vnconfig $rootdevice $1
Expand Down Expand Up @@ -58,33 +52,51 @@ vnuncfgroot() {
tmplabel=`mktemp /tmp/mkbootlabel.XXXXXXXX`

if [ -z "$novnd" ]; then
echo -n "Creating base image ($bsize*$count)"

c 0 "dd if=/dev/zero of=$dest bs=$bsize count=$count >/dev/null 2>&1"
echo
# Create vnd image, must zero out the first few sectors or else disklabel freaks out...
c 0 "dd if=/dev/zero bs=$bytessec count=$bytessec of=$dest > /dev/null 2>&1"
vncfgroot $dest
c 1 "fdisk -c $cylinders -h $trackscylinder -s $sectorstrack -f $distloc/usr/mdec/mbr -yi $rootdevice >/dev/null 2>&1"
c 1 disklabel $rootdevice > $tmplabel
totalsize=$((cylinders * trackscylinder * sectorstrack))
sectorscylinder=$((totalsize / cylinders))
else
# Disk specified, use default kernel geometry
c 0 "fdisk -f $distloc/usr/mdec/mbr -yi $rootdevice >/dev/null 2>&1"
c 0 disklabel $rootdevice > $tmplabel
totalsize=`awk -F: ' /^total sectors:/ {print $2} ' $tmplabel`
bytessec=`awk -F: ' /^bytes\/sector:/ {print $2} ' $tmplabel`
sectorstrack=`awk -F: ' /^sectors\/track:/ {print $2} ' $tmplabel`
sectorscylinder=`awk -F: ' /^sectors\/cylinder:/ {print $2} ' $tmplabel`
trackscylinder=`awk -F: ' /^tracks\/cylinder:/ {print $2} ' $tmplabel`
cylinders=`awk -F: ' /^cylinders:/ {print $2} ' $tmplabel`
fi

vncfgroot $dest

c 1 "fdisk -yi $rootdevice >/dev/null 2>&1"

c 1 "disklabel $rootdevice | egrep -v ^type: > $tmplabel"

totalsize=`awk -F: ' /^total sectors:/ {print $2} ' $tmplabel`
sectorstrack=`awk -F: ' /^sectors\/track:/ {print $2} ' $tmplabel`
totalmbytes=$((((totalsize / 1024) * bytessec) / 1024))
echo "Using disk geometry $cylinders/$trackscylinder/$sectorstrack ($totalmbytes MB)"

# Main partition comprises the total disk, minus first sector
asize=$((totalsize - sectorstrack))

cat >>$tmplabel <<-EOF
# Remove most disklabel info, write disk geometry, partitions
egrep -v "^type:|^boundstart:|^boundend:|^total sectors:|^bytes/sector:|^sectors/track:|^sectors/cylinder:|^tracks/cylinder:|^cylinders:|^ .:|^#|^. partitions:|^.. partitions:|^$" < $tmplabel > ${tmplabel}.new
cat >> ${tmplabel}.new <<-EOF
type: ESDI
bytes/sector: $bytessec
sectors/track: $sectorstrack
tracks/cylinder: $trackscylinder
sectors/cylinder: $sectorscylinder
cylinders: $cylinders
total sectors: $totalsize
a: $asize $sectorstrack 4.2BSD 1024 8192 16
c: $totalsize 0 unused 0 0
EOF
c 1 mv ${tmplabel}.new $tmplabel

c 1 "disklabel -R $rootdevice $tmplabel >/dev/null 2>&1"
c 1 disklabel -R $rootdevice $tmplabel

echo -n Creating filesystem on /dev/r${rootdevice}a
c 1 "newfs /dev/r${rootdevice}a >/dev/null 2>&1"
c 1 "newfs -S $bytessec /dev/r${rootdevice}a >/dev/null 2>&1"
echo

c 1 mount /dev/${rootdevice}a $tmpmnt
Expand All @@ -97,6 +109,8 @@ c 2 "$distloc/usr/mdec/installboot $tmpmnt/boot $distloc/usr/mdec/biosboot $root

c 2 mkdir $tmpmnt/new $tmpmnt/old

c 1 umount $tmpmnt
umountwait 1 $tmpmnt

vnuncfgroot

exit 0
33 changes: 29 additions & 4 deletions mkdist
Expand Up @@ -148,20 +148,45 @@ done

###
#
# This step isn't strictly necessary. The kernel will just fill in the free space automatically during write if the disklabel purports a large image!
# Setup openbsd.vnd with a little bit of zeros

echo -n "Creating openbsd.vnd $((disktotal / 2048))MB "
c 0 "dd if=/dev/zero of=$tmpdir/openbsd.vnd bs=512 count=$disktotal >/dev/null 2>&1"
echo -n "Size openbsd.vnd $((disktotal / 2048))MB "
c 0 "dd if=/dev/zero of=$tmpdir/openbsd.vnd bs=512 count=512 >/dev/null 2>&1"
echo

c 0 vnconfig $device $tmpdir/openbsd.vnd

###
#
# Read in fake label as basis for real one
#
# We build a label here instead of using the kernel's auto-generated
# one so the user doesn't have to sit around and wait for dd of zeros!
#
# (The kernel would have generated a fake disklabel of the right size
# if the dd step above was bs=512 count=$disktotal)

c 1 "disklabel $device > $tmplabel"

egrep -v "^boundstart:|^boundend:|^total sectors:|^bytes/sector:|^sectors/track:|^sectors/cylinder:|^tracks/cylinder:|^cylinders:|^ .:|^#|^. partitions:|^.. partitions:|^$" < $tmplabel > ${tmplabel}.new

bytessec=512
sectorstrack=100
sectorscylinder=100
trackscylinder=1
cylinders=$((disktotal / sectorstrack))
cat >> ${tmplabel}.new <<-EOF
bytes/sector: $bytessec
sectors/track: $sectorstrack
tracks/cylinder: $trackscylinder
sectors/cylinder: $sectorscylinder
cylinders: $cylinders
total sectors: $disktotal
c: $disktotal 0 unused 0 0
EOF
c 1 mv ${tmplabel}.new $tmplabel

###
#
# Build, write vnd disklabel
Expand Down Expand Up @@ -196,7 +221,7 @@ for i in $vnddirs; do
echo -n " copy"
c 2 tar cf - -C $distloc/$i . | tar xpf - -C $tmpmntdir

c 1 umount $tmpmntdir
umountwait 1 $tmpmntdir

echo
let x=x+1
Expand Down
2 changes: 1 addition & 1 deletion mkrdroot
Expand Up @@ -150,6 +150,6 @@ c 2 cp etc/rc $tmpmntdir/etc/rc

c 2 cp stand/rc $tmpmntdir/stand/rc

c 1 umount $tmpmntdir
umountwait 1 $tmpmntdir

c 0 vnconfig -u $device
5 changes: 4 additions & 1 deletion stand/rc
Expand Up @@ -57,7 +57,10 @@ unvndmnt()
{
x=0

umount /$i
for i in $vndddirs; do
umount /$i
done

vnconfig -u $vnd
}

Expand Down

0 comments on commit 5111d98

Please sign in to comment.