S.U.F.F. - SuSE USB Floppy Formatter

After one of our users had issues formatting a USB connected floppy disk, it came to me that I might want to automate this procedure. Please find below my bash script I called S.U.F.F. for SuSE USB Floppy Formatter. S.U.F.F. requires no run time parameters, it can install the required ufiformat if allowed, should it be missing. All floppy disk sizes are support as well as setting a volume label when complete. To create S.U.F.F., copy and paste the text from the code block below into your favorite text editor and save it as the file suff in your local ~/bin folder (/home/username/bin/suff):

#!/bin/bash

#: Title       : S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00
#: Date Created: Sat Sep 10 10:04:11 CDT 2011
#: Last Edit   : Sat Sep 10 10:04:11 CDT 2011
#: Author      : James D. McDaniel
#: Version     : 1.00
#: Description : Floppy Disk Formatter Script
#: Options     : none

TITLE="S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00"

#
# Written for the openSUSE forums on Saturday September 10, 2011
#

#
# Copy and Paste the text of this script into a text editor and save 
# it as the file suff in the folder ~/bin (/home/username/bin).
# This script must be marked executable to be used.  Please run 
# the following Terminal command: chmod +x ~/bin/suff
#

declare -a format

#
# Check to see if we are root
#
if  $UID -ne 0 ]]; then
  id -Gn | grep -q wheel || echo "Root User Permissions are required, Please Enter the ..."
  echo
  sudo $0 $1
  exit 0
fi

#
# This is the standard GPL Statement, leave at the top of the script.
# Just use the command show_gpl after this function for it to be shown.
#

function show_gpl {
echo ""
echo "usbfloppyformat is a bash script file written to be used with openSUSE."
echo "Copyright (C) 2011 by James D. McDaniel, jmcdaniel3@austin.rr.com"
echo ""
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo ""
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo ""
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"
echo ""
}

#
# Locate next Substring by space seperator in a long string  
# Start looking at character position $1 in string $2
# Return location of next space, between sub-strings
#

function sub_string {
  counter=$1
  start=$2
  num2=${#start}
  while  $(( counter )) -lt $(( num2 + 1 )) ] ; do
  temp="${start:$(($counter)):1}"
  if  $temp != " " ]] ; then
    let counter=counter+1
  else
    return ${counter}
  fi
  done
  return ${counter}
}

# ----------------------------------------------------------------------------
# Prepair for install of ufiformat if needed by more than one distro
# The following coding provided by please_try_again
#

# install cpufrequtils under openSUSE, Fedora, Mandriva, Ubuntu
suselinux="zypper in"
mandrivalinux="urpmi"
fedora="yum install"
ubuntu="apt-get install"

# default to openSUSE if lsb_release is not found (or write more code to install
# lsb_release withouth confirmation or get the release name in another way)
install=suselinux
which lsb_release &>/dev/null && install=$(lsb_release -is | tr ":upper:]" ":lower:]" | tr -d " ")
install=${!install}
#-----------------------------------------------------------------------------

#
# Determine if the package ufiformat is installed
#

which ufiformat > /dev/null
Exit_Code=$?

if  $(( Exit_Code )) -ge 1 ] ; then
  tput clear
  echo "The ufiformat Utility Package is not installed!"
  echo
  echo -n "Would you like to install the ufiformat package(y/N)?"
  read CHOICE
  if  $CHOICE == [Yy] ]] ; then
    sudo $install ufiformat
  else
    exit 1
  fi
fi

#
# Main Program Starts Here
#

gui=true

while $gui ; do

  clear
  echo $TITLE

#
# Determine Floppy Drive designation
# 

  floppydrive=$(ufiformat --inquire --verbose | grep /dev/)

  if  "$floppydrive" == "" ] ; then
    echo
    echo "No USB connected Floppy Drive was found!"
    echo
    exit 1
  fi

  sub_string "0" "$floppydrive"
  Exit_Code=$?

  floppydrive=${floppydrive:0:$Exit_Code}

  echo
  echo "Your Floppy Disk Drive is called: $floppydrive"

  if mount|grep $floppydrive > /dev/null ; then

    echo
    echo "Your device $floppydrive is mounted and must be un-mounted!"
    echo
    echo -n "Would you like to un-mount your floppy disk $floppydrive (y/N)?: "
    read CHOICE

    if  $CHOICE == [Yy] ]] ; then
      umount $floppydrive
    else
      echo
      echo "Your floppy disk $floppydrive can't be formatted while mounted!"
      echo
      exit 1
    fi
  fi

  sizes=$(ufiformat -i /dev/sdj | grep -c formattable)
  line=$sizes
  start=1

  echo
  echo "$floppydrive supports the following $sizes Formats:"

  while  $line -gt 0 ] ; do

    format$start]=$(ufiformat -i /dev/sdj | grep formattable | sed -n $(( start ))p)
    let line=line-1
    let start=start+1

  done
      counter=0
      echo
      echo "   status      block size   kb"
      echo "--------------+-----+----+----"
      while  counter -lt sizes ]] ; do
    let counter=counter+1
    echo "$counter) ${format$counter]}"
      done
      echo
      echo -n "Enter the Format size to use [1-$((sizes))] (q=Quit):"
      read CHOICE

      if  $CHOICE =~ ^[0-9]+$ ]] ; then
    if  $CHOICE -le $sizes ]] &&  $CHOICE -gt 0 ]]; then
      gui=false
      let next1=1
      let Exit_Code=0
      format$CHOICE]=$( echo ${format$CHOICE]} | tr "  " " ")
      let length=${#format$CHOICE]}
      while  next1 -lt 5 ]] ; do
        let final=Exit_Code
        sub_string "$Exit_Code" "${format$CHOICE]}"
        Exit_Code=$?
        let Exit_Code=Exit_Code+1
        let next1=next1+1
      done
      let form=length-final+1
      size=${format$CHOICE]:final:form}
      echo
      echo -n "You have selected the format size of $size kb.  Continue (y/N)?:"
      read CHOICE
      if  $CHOICE == [Yy] ]] ; then
         echo
         echo "Formatting Floppy Disk Drive $floppydrive, Please Wait ...."
         echo
         ufiformat -f $size /dev/sdj
         echo
         echo "Please Enter The Floppy Disk Volume Label you wish to use.  Do not"
         echo "use any spaces or special charaters and max length is 13 charaters."
         echo
         echo -n "Please Enter the Disk Label or just press enter for the default: "
         read CHOICE
         /sbin/mkdosfs -I /dev/sdj -n "$CHOICE"
         echo 
         echo "Your Floppy Disk Format of $floppydrive is now Complete."
         show_gpl
      else
        echo
        echo "Floppy Disk Format was Aborted!"
        echo
      fi
    fi
      else
    if  $CHOICE == [Qq] ]] ; then
      show_gpl
      exit 0
    fi
      fi
done

exit 0

# End Of Script


To mark S.U.F.F. executable, open up a terminal session and run the following command:

chmod +x ~/bin/suff

To us S.U.F.F. , just open up a terminal session and type:

suff

If you have any issues or comments about the S.U.F.F. - SuSE USB Floppy Formatter - Version 1.00 script file, please let me know.

Thank You,

I have created a blog on the S.U.F.F. - SuSE USB Floppy Formatter bash script file. You can pick up the latest version from the blog any time you want.

S.U.F.F. - SuSE USB Floppy Formatter - Version 1.03 - Blogs - openSUSE Forums

Thank You,

For anyone that has installed the terminal web program wget, you can use the following terminal command to download version 1.05 of S.U.F.F. - SuSE USB Floppy Formatter. Just open a terminal session and type:

wget -nc http://paste.opensuse.org/view/download/57171820 -O ~/bin/suff

chmod +x ~/bin/suff

To use S.U.F.F. - SuSE USB Floppy Formatter, just open a terminal session and type:

suff

S.U.F.F. - SuSE USB Floppy Formatter is intended for use with a USB connected floppy disk drive. The original version 1.00 posted above had a few issues and should not be used. As always if you have any questions about this bash script file, just let me know.

Thank You,

Considering that I hardly ever use floppy disks these days, its kind of funny of how fun I have had getting the S.U.F.F. - SuSE USB Floppy Formatter working properly. Please find below, version 1.10 of the bash script. You can download it using wget as written below and mark it executable:

wget -nc  http://paste.opensuse.org/view/download/66154818 -O ~/bin/suff

chmod +x ~/bin/suff

And you can also find it on my Blog …

S.U.F.F. - SuSE USB Floppy Formatter - Version 1.10 - Blogs - openSUSE Forums

The latest fixes to suff include finding no disk in the floppy drive and looping the program when you want to format several disks in a row. About the only time I use floppy disks these days is to update a PC BIOS and now, my newest motherboard can also use a thumb drive. The days of installing a floppy drive in every PC may be past, but hang on to that trusty USB floppy disk as you never know when it might be needed. And don’t forget about using S.U.F.F.

Thank You,

Hi James,
I just left a message on the page with v1.30 of your script. Thanks so much, it fills a real need!

Don’t know if you were aware of this, being a ‘SUSE person’, but over on the Ubuntu forums, there was quite an upset a couple of years when one of the maintainers ‘broke’ USB floppy support, in a quest for a faster boot time. I get the impression that the time saving was negligible, and some said they couldn’t notice it. The maintainer said, no problem, because no one uses floppies, and besides, he didn’t own a drive, so he couldn’t and wouldn’t put it right again.

The users may not have noted a boot-time improvement, but they sure noticed the broken package.

It seems there’s certain types of technical, scientific and music-related hardware, that rely on floppies. Some of these items are very costly, have been providing service to their owners for years, and they weren’t prepared to toss these into the rubbish, because a maintainer couldn’t find a USB floppy drive – or whatever. The users of floppy-based hardware pledged never to upgrade the OS if this wasn’t fixed. Some used a work-around, that involved pinning the previous package – that still worked.

Anyway, USB floppy support has been restored, over at Ubuntu, in the more recent versions. Guess the guy found a drive on the Internet?

But the point is, thanks so much for your script. It deserves to be more widely publicized, and I will do what I can! :slight_smile:

Happy to hear S.U.F.F. is working for you as you need it to do so. I did answer you question in my blog as well.

Thank You,