From mwiget at gmail.com Mon Jul 2 20:48:39 2007 From: mwiget at gmail.com (Marcel Wiget) Date: Mon, 2 Jul 2007 12:48:39 +0200 Subject: [flashboot] script to write flash directly with split flashboot and msdos partition Message-ID: While looking for a way to use larger than 128mb compact flash cards and an easy way to a) use Windows or OS/X to write configs and binaries directly on a flash card b) avoid the "do you want to initialize the flash" question in OS/X (and possible windows) c) A way to upload SW updates to a flashboot running device safely with recovery possibilities I created a little script, based on build-diskimage.sh that creates 2 partitions on the flash, split the available space in half and make the OpenBSD one bootable and populated with a generated kernel image. The idea, when running from ramdisk with modified rc scripts, is to allow the user to upload new configs/images/packages to the msdos partition, do some sanity checks, and then copy it over to the production part of the flash. WRAP specific issue with >128MB compact flash cards: The BIOS detects a different flash geometry than a PC. I found a workaround by starting the bootable OpenBSD partition on the last sector of the first track and head. It worked for my 128MB, 512MB and 1GB compact flash cards. Not sure if it breaks on other platforms though. Feel free to incorporate this script (or portions/ideas) into flashboot distribution if deemed useful. Marcel #!/bin/sh # # $Id$ # # Written by Marcel Wiget in 2007 # portions based on flashboot build-diskimage.sh # flashboot can be found at http://www.mindrot.org/projects/flashboot/) BASE=`pwd` DESTDIR=${DESTDIR:-${BASE}/flash-dist} KERNELFILE=${KERNELFILE:-${BASE}/obj/bsd.gz} SUDO=sudo MOUNTPOINT=/mnt # This is for boot.conf and should match the kernel ttyspeed. # Which should be 9600 for GENERIC-RD, 38400 for WRAP12 and 19200 for the rest. TTYSPEED=${TTYSPEED:-38400} # Don't start without a device contain the fash as a parameter if [ "$1" = "" ]; then cat << __EOC usage: $0 device This script erases any existing data on the specified flash drive and creates 2 equal size partitions and formats them, a bootable flashboot OpenBSD partition and a FAT-32 formatted MSDOS partition. The OpenBSD partition will be updated and configured with the flashboot standard distribution. A properly installed and compiled flashboot distribution is required. See http://www.mindrot.org/projects/flashboot/ WARNING: the content of the specified flash device will be DESTROYED! Example: $0 sd0 __EOC exit 1 fi DEVICE=$1 # Does the kernel exist at all if [ ! -r $KERNELFILE ]; then echo "ERROR! $KERNELFILE does not exist or is not readable." exit 1 fi # get fdisk info from DEVICE GEOMETRY=`${SUDO} fdisk $DEVICE 2>/dev/null | grep geometry: | awk '{print $4}' ` # device for real? if [ "X$GEOMETRY" == "X" ]; then echo "ERROR! /dev/$DEVICE does not exist or cant read flash geometry." exit 1 fi # echo -n "\n$DEVICE: Geometry is $GEOMETRY " cylinders=`echo $GEOMETRY | cut -d / -f 1` heads=`echo $GEOMETRY | cut -d / -f 2` sectors=`echo $GEOMETRY | cut -d / -f 3` let flashsize=$cylinders*$heads*$sectors/2048 echo "and holds about $flashsize MBytes" # sanity check. If the flash is bigger than 1GB, we're probably # dealing with a HD instead of a flash card! if [ "$flashsize" -gt "1024" ]; then echo "\nERROR! /dev/$DEVICE seems rather large ($flashsize MB)." echo "If you're sure this isn't your HD, please modify this script." echo "This script assumes flash cards used are <= 512MB" exit 1 fi echo "\nReady to partition and format flash drive in /dev/$DEVICE" echo "Hit ^C now if you're not sure this is the right flash or" echo "Enter to continue" read null # calculate CHS start end for OpenBSD and MSDOS partition let startcyl1=0 let endcyl1=$cylinders/2 let startcyl2=$endcyl1+1 let endcyl2=$cylinders-1 let head=$heads-1 # Create a new Master Boot Record with 2 partitions: # 0: OpenBSD bootable (where we will addd a disklabel) # 3: MSDOS partition # A standard behaviour of fdisk when using reinit is assumed. # Using the odd starting CHS of 0/0/32 helps us getting around # the problem on WRAP platforms where the bootstrap code has # a different oppinion about the flash's geometry. ${SUDO} fdisk -ye $DEVICE << __EOC >/dev/null 2>&1 reinit edit 0 A6 0 0 32 $endcyl1 $head $sectors edit 3 0B $startcyl2 0 1 $endcyl2 $head $sectors flag 0 update quit __EOC echo "\nNew partition table:" ${SUDO} fdisk $DEVICE 2>/dev/null # Edit now the new disklabel by defining partition a ${SUDO} disklabel -c -d -E $DEVICE << __EOC >/dev/null 2>&1 m a 4.2BSD w q __EOC # disklabel $DEVICE # initialize both new filesystems: echo "\nFormat MSDOS Partition:" ${SUDO} newfs_msdos -L OpenBSD /dev/r${DEVICE}i echo "\nFormat OpenBSD Partition:" ${SUDO} newfs /dev/r${DEVICE}a echo "\nMounting destination to ${MOUNTPOINT}..." if ! ${SUDO} mount -o async /dev/${DEVICE}a ${MOUNTPOINT}; then echo Mount failed.. exit fi echo "" echo "Copying bsd kernel, boot blocks and /etc/boot.conf..." ${SUDO} cp ${DESTDIR}/usr/mdec/boot ${MOUNTPOINT}/boot ${SUDO} cp ${KERNELFILE} ${MOUNTPOINT}/bsd ${SUDO} mkdir ${MOUNTPOINT}/etc ${SUDO} sed "/^stty/s/19200/${TTYSPEED}/" < ${BASE}/initial-conf/boot.conf > boot.conf$$ ${SUDO} cp boot.conf$$ ${MOUNTPOINT}/etc/boot.conf ${SUDO} rm -f boot.conf$$ echo "" echo "Installing boot blocks..." ${SUDO} /usr/mdec/installboot ${MOUNTPOINT}/boot ${DESTDIR}/usr/mdec/biosboot ${DEVICE} ${SUDO} mkdir ${MOUNTPOINT}/conf ${SUDO} mkdir ${MOUNTPOINT}/pkg # Here is where you add your own packages and configuration to the flash... echo "" echo "Unmounting and cleaning up..." ${SUDO} umount $MOUNTPOINT exit 0 ################################################ From niclas.rosell at iis.se Fri Jul 13 22:39:51 2007 From: niclas.rosell at iis.se (Niclas Rosell) Date: Fri, 13 Jul 2007 14:39:51 +0200 Subject: [flashboot] New backup and network configuration tools In-Reply-To: <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> References: <023E9DDFC555E3479AEBF917CE60A0B401137139@EXCHANGE.office.nic.se> <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> Message-ID: <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> Hi I have made som changes to resolv a issue with the config variable in rc.conf. Thanks Damien for pointing this out, I didnt read your question properly at first. I also renamed the config variable to initial_config in rc.conf, I think this is a better name. Now createconfig will only run from rc if initial_config exists and is set to YES. Upgrading from older releases that does not have initial_config variable should now be safe. /Niclas ons 2007-06-20 klockan 10:22 +0200 skrev Niclas Rosell: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello > > The changes i have made does not change the bootup behavior unless > config=YES is in rc.conf. > The "restoration" process (in rc.initial) of backup files on the > flash card is left untouched. When running a system with config=YES > (or by running createconfig manually) you are asked if you want to > make a backup of your changes. If the answer is yes then the changed > files will be copied to /flash/conf/ and will be restored by rc at > next reboot. > Any changes made at any time can be backed up by running the command > backupconfig. By default it only looks in /etc but you can change > this by editing /etc/backup.conf. Take a look in /flash/conf/ after > running backupconfig to verify. > Good to know is that if a USB memory stick is plugged in then that > will be used as /flash instead of the flash disk. > > At first I did not use config=NO/YES but instead i checked if there > was a backup on flash and used that instead of going into > createconfig (no questions asked), but that was before I was thinking > of backing up to a USB memory. > > I was thinking of renaming createconfig/backupconfig to > flashboot-autoconf/flashboot-backup. (thanks to Jakob for helping out > with the names) > > Niclas > > > > -----Ursprungligt meddelande----- > > Fr?n: Damien Miller [mailto:djm at mindrot.org] > > Skickat: den 20 juni 2007 06:43 > > Till: Niclas Rosell > > Kopia: flashboot at mindrot.org > > ?mne: Re: [flashboot] New backup and network configuration tools > > > > On Fri, 15 Jun 2007, Niclas Rosell wrote: > > > > > > > > -----BEGIN PGP SIGNED MESSAGE----- > > > Hash: SHA1 > > > > > > Hi > > > A few hours ago Jakob committed a some diffs from me. > > > It includes a new backup tool (backupconfig) and a network > > > configuration tool (createconfig). > > > Here is the short description of what it does. > > > > > > Createconfig is checking for existing backups and presents a > > > (very short) list of devices containing backups. It should detect > > if a usb > > > memory is inserted and contains a /conf/etc folder. > > > It then presents 4 options which should be self-explainatory. > > > > > > 0. Use existing config > > > 1. Manual setup > > > 2. DHCP > > > 3. Do not run createconfig > > > > > > > > > Backupconfig uses /etc/backup.conf and mtree to decide what > > files to > > > backup. backup.conf is for directories to look for changes > > and mtree > > > for files different then the version in bsd.gz. The backup is > > > then copied to /flash/conf/. > > > A mtree of the initial filesystem is stored in > > /root/flashboot.mtree. > > > Flashboot.mtree is created at the end of list. > > > > Thanks, I'm sure a lot of people will find these useful. > > > > Are there any caveats for people who are running flashboot > > systems who upgrade the a new image that incorporates these > > changes? It seems that their systems may not come back > > properly from a reboot if the "config" variable is not set in > > rc.conf. > > > > -d > > -----BEGIN PGP SIGNATURE----- > Version: PGP 8.1 > > iQA/AwUBRnjjqwXDAg/A+7GOEQLlvACfVWsnSBGHthalS6K0shdzkWj/EcEAoNY1 > n7WuKjG/HxkDrO7eTMc2IL6k > =iKMM > -----END PGP SIGNATURE----- > _______________________________________________ > flashboot mailing list > flashboot at mindrot.org > http://lists.mindrot.org/mailman/listinfo/flashboot > > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signerad meddelandedel Url : http://lists.mindrot.org/pipermail/flashboot/attachments/20070713/0bf8abae/attachment.bin From rd at tilde.se Thu Jul 19 23:14:08 2007 From: rd at tilde.se (Rickard Dahlstrand) Date: Thu, 19 Jul 2007 15:14:08 +0200 Subject: [flashboot] New backup and network configuration tools In-Reply-To: <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> References: <023E9DDFC555E3479AEBF917CE60A0B401137139@EXCHANGE.office.nic.se> <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> Message-ID: <469F63A0.6060208@tilde.se> What do you say, are we ready to start deploying binary-version of this?? Rickard. Niclas Rosell wrote: > Hi > > I have made som changes to resolv a issue with the config variable in > rc.conf. Thanks Damien for pointing this out, I didnt read your question > properly at first. > I also renamed the config variable to initial_config in rc.conf, I think > this is a better name. > Now createconfig will only run from rc if initial_config exists and is > set to YES. Upgrading from older releases that does not have > initial_config variable should now be safe. > > /Niclas > > > ons 2007-06-20 klockan 10:22 +0200 skrev Niclas Rosell: > Hello > > The changes i have made does not change the bootup behavior unless > config=YES is in rc.conf. > The "restoration" process (in rc.initial) of backup files on the > flash card is left untouched. When running a system with config=YES > (or by running createconfig manually) you are asked if you want to > make a backup of your changes. If the answer is yes then the changed > files will be copied to /flash/conf/ and will be restored by rc at > next reboot. > Any changes made at any time can be backed up by running the command > backupconfig. By default it only looks in /etc but you can change > this by editing /etc/backup.conf. Take a look in /flash/conf/ after > running backupconfig to verify. > Good to know is that if a USB memory stick is plugged in then that > will be used as /flash instead of the flash disk. > > At first I did not use config=NO/YES but instead i checked if there > was a backup on flash and used that instead of going into > createconfig (no questions asked), but that was before I was thinking > of backing up to a USB memory. > > I was thinking of renaming createconfig/backupconfig to > flashboot-autoconf/flashboot-backup. (thanks to Jakob for helping out > with the names) > > Niclas > > > >>> -----Ursprungligt meddelande----- > >>> Fr?n: Damien Miller [mailto:djm at mindrot.org] > >>> Skickat: den 20 juni 2007 06:43 > >>> Till: Niclas Rosell > >>> Kopia: flashboot at mindrot.org > >>> ?mne: Re: [flashboot] New backup and network configuration tools > >>> > >>> On Fri, 15 Jun 2007, Niclas Rosell wrote: > >>> > >>>> -----BEGIN PGP SIGNED MESSAGE----- > >>>> Hash: SHA1 > >>>> > >>>> Hi > >>>> A few hours ago Jakob committed a some diffs from me. > >>>> It includes a new backup tool (backupconfig) and a network > >>>> configuration tool (createconfig). > >>>> Here is the short description of what it does. > >>>> > >>>> Createconfig is checking for existing backups and presents a > >>>> (very short) list of devices containing backups. It should detect > >>> if a usb > >>>> memory is inserted and contains a /conf/etc folder. > >>>> It then presents 4 options which should be self-explainatory. > >>>> > >>>> 0. Use existing config > >>>> 1. Manual setup > >>>> 2. DHCP > >>>> 3. Do not run createconfig > >>>> > >>>> > >>>> Backupconfig uses /etc/backup.conf and mtree to decide what > >>> files to > >>>> backup. backup.conf is for directories to look for changes > >>> and mtree > >>>> for files different then the version in bsd.gz. The backup is > >>>> then copied to /flash/conf/. > >>>> A mtree of the initial filesystem is stored in > >>> /root/flashboot.mtree. > >>>> Flashboot.mtree is created at the end of list. > >>> Thanks, I'm sure a lot of people will find these useful. > >>> > >>> Are there any caveats for people who are running flashboot > >>> systems who upgrade the a new image that incorporates these > >>> changes? It seems that their systems may not come back > >>> properly from a reboot if the "config" variable is not set in > >>> rc.conf. > >>> > >>> -d _______________________________________________ flashboot mailing list flashboot at mindrot.org http://lists.mindrot.org/mailman/listinfo/flashboot >> >> >> ------------------------- >> _______________________________________________ flashboot mailing list flashboot at mindrot.org https://lists.mindrot.org/mailman/listinfo/flashboot -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.mindrot.org/pipermail/flashboot/attachments/20070719/7cd40cd6/attachment-0001.html From jakob at rfc.se Fri Jul 20 01:13:10 2007 From: jakob at rfc.se (Jakob Schlyter) Date: Thu, 19 Jul 2007 17:13:10 +0200 Subject: [flashboot] New backup and network configuration tools In-Reply-To: <469F63A0.6060208@tilde.se> References: <023E9DDFC555E3479AEBF917CE60A0B401137139@EXCHANGE.office.nic.se> <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> <469F63A0.6060208@tilde.se> Message-ID: <2EBF359F-1950-43B8-A742-A891237132B0@rfc.se> On 19 jul 2007, at 15.14, Rickard Dahlstrand wrote: > What do you say, are we ready to start deploying binary-version of > this?? why binary? jakob From rd at tilde.se Fri Jul 20 02:17:48 2007 From: rd at tilde.se (Rickard Dahlstrand) Date: Thu, 19 Jul 2007 18:17:48 +0200 Subject: [flashboot] New backup and network configuration tools In-Reply-To: <2EBF359F-1950-43B8-A742-A891237132B0@rfc.se> References: <023E9DDFC555E3479AEBF917CE60A0B401137139@EXCHANGE.office.nic.se> <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> <469F63A0.6060208@tilde.se> <2EBF359F-1950-43B8-A742-A891237132B0@rfc.se> Message-ID: <469F8EAC.4020902@tilde.se> Jakob Schlyter wrote: > On 19 jul 2007, at 15.14, Rickard Dahlstrand wrote: > >> What do you say, are we ready to start deploying binary-version of >> this?? > > why binary? kernels and diskimages.. From jakob at rfc.se Fri Jul 20 03:58:26 2007 From: jakob at rfc.se (Jakob Schlyter) Date: Thu, 19 Jul 2007 19:58:26 +0200 Subject: [flashboot] New backup and network configuration tools In-Reply-To: <469F8EAC.4020902@tilde.se> References: <023E9DDFC555E3479AEBF917CE60A0B401137139@EXCHANGE.office.nic.se> <023E9DDFC555E3479AEBF917CE60A0B4011372B1@EXCHANGE.office.nic.se> <1184330391.13642.13.camel@niclas-laptop42.office.nic.se> <469F63A0.6060208@tilde.se> <2EBF359F-1950-43B8-A742-A891237132B0@rfc.se> <469F8EAC.4020902@tilde.se> Message-ID: On 19 jul 2007, at 18.17, Rickard Dahlstrand wrote: >> why binary? > kernels and diskimages.. sure, but why isn't the shell-script enough? jakob