Although more computers are becoming network connected every day, there are many instances where you need to transfer files by the ol' sneaker-net method. Here are some hints, tips and short-cuts for doing this, aimed at users who are new to Linux or Unix. (There may even be some information useful to old-timers...)
What do I use floppies for? As a consultant, I frequently do contract work for companies which, because of security policies, do not connect to the 'Net. So, FTP'ing files which I need from my network at home is out of the question.
My current contract as an example, I am using Linux as an X-Windows terminal for developing software on their DEC Alphas running OSF. (I blew away the Windoze '95 which they had loaded on the computer they gave me.) I often need to bring files with me from my office at home, or backup my work to take back home for work in the evening. (Consultants sometimes work flex-hours, which generally means more hours...)
Why use cpio(1) or tar(1) when copying files? Because it is a portable method of transferring files from a group of subdirectories with the file dates left intact. The cp(1) command may or may not do the job depending on Operating Systems and versions you are dealing with. In addition, specifying certain options will only copy files which are new or have changed.
Formatting, Filesystems and Mounting
The first thing you need to do to make the floppies useful is to format them, and usually lay down a filesystem. There are also some preliminary steps which make using floppy disks much easier, which is the point of this article.
I find it useful to make my username part of the floppy group in the
/etc/group file. This saves you from needing to su to root much of
the time. (You will need to log out and log back in again for this to take
I also use the same username both on the client's machine and
my home office which saves time. The line should now look like this:
The following setup is assumed for the examples I present here.
The root user must have the system directories in the PATH
Add the following to the .profile file in /root if not already there by
su'ing to root.
You can also use your favorite editor to do this... I prefer vim(1) and have this symlinked to /usr/bin/vi instead of elvis(1) which is usually the default on many distributions. VIM has online help, and multiple window support which is very useful! (A symlink is created with a -s option to ln(1), and is actually called a symbolic link.)su - # this should ask for the root password. cat >> .profile PATH=/sbin:/usr/sbin:$PATH <ctrl>-D
Next, add the following lines to the /etc/fstab file:
(I have all the user mountable partitions in one place under /mnt.
You may want a different convention, but this is useful. I also have
/mnt/cdrom symlinked to /cd for convenience.)
/dev/fd0 /mnt/fd0 ext2 noauto,user 1 2
Still logged in as root, make the following symlink:
(If you have more than one floppy drive, then add the floppy number
These two things make mounting and unmounting floppies a cinch. The mount(8) command follows the symlink and accesses the /etc/fstab file for any missing parameters, making it a useful shortcut.ln -s /mnt/fd0 /fd -or- ln -s /mnt/fd0 /fd0
To make the floppy usable as an ext2fs Linux filesystem, do the following
(The username is whatever username you use on regularly on the
system. You, of course, should not use the root user for normal
You may need to specify the geometry of the floppy you are using. If it is the standard 3.5 inch double sided disk, you may need to substitute /dev/fd0H1440 for the device name (in 1.2.x kernels). If you have a newer 2.xx kernel and superformat(1), you may want to substitute this for fdformat. See the notes in the Miscellaneous section below, or look at the man page. You may now exit out of su(1) by typing:export PATH=/sbin:/usr/sbin:$PATH # not needed if you set environment fdformat /dev/fd0 mke2fs /dev/fd0 mount /dev/fd0 /mnt/fd0 chown username /mnt/fd0
From this point on, you may use the mount(8) and umount(8)
commands logged in as your normal username by typing the following:
mount /fd umount /fd
For backing up my work to take home or to take back to the office I use
cpio(1) instead of tar(1) as it is far more flexible, and
better at handling errors etc. To use this on a regular basis, first create
all the files you need by specifying the command below without
the -mtime -1 switch. Then you can make daily backups from the base
directory of your work using the following commands:
cd directory mount /fd find . -mtime -1 -print | cpio -pmdv /fd sync umount /fd
When the floppy stops spinning, and the light goes out, you have your work backed up. The -mtime option to find(1) specifies files which have been modified (or created) within one day (the -1 parameter). The options for cpio(1) specify copy-pass mode, which retain previous file modification times, create directories where needed, and do so verbosely. Without a -u (unconditional) flag, it will not overwrite files which are the same age or newer.
This operation may also be done over a network, either from NFS mounted filesystems, or by using a remote shell as the next example shows.
This example uses cpio(1) to send files from the remote system, and update the files on the floppy disk mounted on the local system. Note the pipe (or veritical bar) symbol at the end of the remote shell line. The arguments which are enclosed in quotes are executed remotely, with everything enclosed in braces happening in a subshell. The archive is sent as a stream across the network, and used as input to the cpio(1) command executing on the local machine. (If both systems are using a recent version of GNU cpio, then specify -Hcrc instead of c for the archive type. This will do error checking, and won't truncate inode numbers.)mount /fd cd /fd rsh remotesystem '(cd directory; find . -mtime -1 -print | cpio -oc)' | cpio -imdcv sync cd umount /fd
To restore the newer files to the other computer, change directories to
the base directory of your work, and type the following:
cd directory mount -r /fd cd /fd find . -mtime -1 -print | cpio -pmdv ~- cd - umount /fd
If you needed to restore the files completely, you would of course leave out the -mtime parameter to find(1).
The previous examples assume that you are using the bash(1) shell, and uses a few quick tricks for specifying directories. The "~-" parameter to cpio is translated to the previous default directory. In other words, where you were before cd'ing to the /fd directory. (Try typing: echo ~- to see the effect, after you have changed directories at least once.) The cd ~- or just cd - command is another shortcut to switch directories to the previous default. These shortcuts often save a lot of time and typing, as you frequently need to work with two directories, using this command to alternate between them or reference files from where you were.
If the directory which you are tranferring or backing up is larger than a single floppy disk, you may need to resort to using a compressed archive. I still prefer using cpio(1) for this, although tar(1) will work too. Change directories to your work directory, and issue the following commands:
The -Hcrc option to cpio(1) is a new type of archive which older versions of cpio might not understand. This allows error checking, and inode numbers with more than 16 bits.cd directory mount /fd find . -mtime -1 -print | cpio -ovHcrc | gzip -v > /fd/backup.cpio.gz sync umount /fd
Of course, your original archive should be created using find(1)
without the -mtime -1 options.
Floppy as a Raw Device for Large Files or Directories
Sometimes it is necessary to backup or transfer a file or directories which are larger than a floppy disk, even when compressed. For this, we finally need to resort to using tar.
Prepare as many floppies as you think you'll need by using the fdformat(8) command. You do not need to make filesystems on them however, as you will be using them in raw mode.
If you are backing up a large set of subdirectories, switch to the base subdirectory and issue the following command:
This command will prompt you when to change floppies. Wait for the floppy drive light to go out of course!cd directory tar -cv -L 1440 -M -f /dev/fd0 .
If you need to backup or transfer multiple files or directories, or just a single large file, then specify them instead of the period at the end of the tar command above.
Unpacking the archive is similar to the above command:
cd directory tar -xv -L 1440 -M -f /dev/fd0
Finally, here are some assorted tips for using floppies.
The mtools(1) package is great for dealing with MS-DOG
floppies, as we sometimes must. You can also mount(8) them as a Linux
filesystem with either msdos or umsdos filesystem types. Add another
entry to the /etc/fstab entry you made before, so that the two
lines will look like this:
You can now mount an MS-DOS floppy using the command:/dev/fd0 /mnt/fd0 ext2 noauto,user 1 2 /dev/fd0 /mnt/dos msdos noauto,user 1 2
You can also symlink this to another name as a further shortcut.mount /mnt/dos
ln -s /mnt/dos /dos mount /dos
The danger of using the mount(8) commands rather than mtools(1)
for users who are more familiar with MSDOS, is that you need to explicitly
unmount floppies before taking them out of the drive using
step can make the floppy unusable! If you are in the habit of forgetting, a simple
low-tech yellow Post-it note in a strategic place beside your floppy drive might
save you a few headaches. If your version of Post-it notes has the <BLINK>
tag, use it! ;-)
Newer systems based on the 2.xx kernel are probably shipped with fdutils. Check to see if you have a /usr/doc/fdutils-xxx directory, where xxx is a version number. (Mine is 4.3). Also check for the superformat(1) man page. This supersedes fdformat(1) and gives you options for packing much more data on floppies. If you have an older system, check the ftp://ftp.imag.fr/pub/Linux/ZLIBC/fdutils/ ftp site for more information.
The naming convention for floppies in newer 2.xx kernels has also changed, although the fd(4) man page has not been updated in my distribution. If you do not have a /dev/fd0H1440 device, then you probably have the newer system.