Working with flash and other filesystems

There’s nothing sexy about keeping flash neat and tidy. Too bad because it’s pretty easy to do. Let’s cover a couple of ways to keep things orderly. The first thing I do after I unpack and power up a switch is format the flash and install my required IOS. Why do I format it? Habit more than anything. I know I don’t need anything on there so why not just wipe it. I was at a customer the other day and we had to update the IOS before deployment. They asked if there was a way to delete the IOS instead of formatting flash (think in production IOS upgrade). Let’s take a quick look at an example.

First lets take a look at what is stored in flash.

STACK#dir

Directory of flash:/

    3  -rwx    19842267  Mar 29 2011 20:33:01 -05:00  c3750e-universalk9-mz.150-2.SE.bin

    9  -rwx       78657   Apr 8 2013 08:54:19 -05:00  config.text

If we want to delete the IOS we type delete with the full path and filename.

STACK#delete flash:c3750e-universalk9-mz.150-2.SE.bin

It doesn’t get much easier than that. For some reason Cisco always ships IOS with the Web Manager installed. That makes things a bit trickier. Let’s look at another example.

STACK2#dir

Directory of flash:/

    2  -rwx        1276  Feb 28 1993 18:03:35 -06:00  vlan.dat

    3  -rwx       10238  Apr 19 2012 02:43:15 -05:00  config.text

    4  drwx         192  Feb 28 1993 19:12:55 -06:00  c3750-advipservicesk9-mz.122-25.SEC1

We can see that this switch has the Wb Manager installed. Notice the d. For the non-Unix types that stands for directory. Let’s try and delete it.

STACK2#delete flash:c3750-advipservicesk9-mz.122-25.SEC1

Delete filename [c3750-advipservicesk9-mz.122-25.SEC1]?

Delete flash:c3750-advipservicesk9-mz.122-25.SEC1? [confirm]

%Error deleting flash:c3750-advipservicesk9-mz.122-25.SEC1 (Is a directory)

That doesn’t work. The actual problem is that the directory is not empty. So what do we do? We could go into the folder and delete the file(s) then try and delete the folder. In the switch above, there are 771 files and folders under the root c3750-advipservicesk9-mz.122-25.SEC1 folder! (want to see every file in flash…type dir /recursive) A manual delete doesn’t make much sense. That’s the reason I format the flash right out of the box. What about equipment already in production? We use the delete command with some switches.

STACK#delete /recursive /force flash:c3750-advipservicesk9-mz.122-25.SEC1

The /recursive switch deletes all the way down the folder structure. The /force deletes the file without prompting Are you sure? for each file.

Another thing I always configure is archiving the local config. Every time I save the config the switch saves the config to flash as well as to NVRAM. Storing to root of the flash filesystem would make a mess of it. Why not create an archive directory and store the configs in there? Let’s take a look at flash then create an archive directory.

STACK#dir flash1:

Directory of flash:/

    2  -rwx        1276  Feb 28 1993 18:03:35 -06:00  vlan.dat

    3  -rwx       10238  Apr 19 2012 02:43:15 -05:00  config.text

    4  drwx         192  Feb 28 1993 19:12:55 -06:00  c3750-advipservicesk9-mz.122-25.SEC1

STACK2#mkdir flash:archive

Create directory filename [archive]?

Created dir flash:archive

STACK#dir

Directory of flash:/

    2  -rwx        1276  Feb 28 1993 18:03:35 -06:00  vlan.dat

    3  -rwx       10238  Apr 19 2012 02:43:15 -05:00  config.text

    4  drwx         192  Feb 28 1993 19:12:55 -06:00  c3750-advipservicesk9-mz.122-25.SEC1

  366  drwx           0   Apr 8 2013 20:39:45 -05:00  archive

We now have a directory name archive. How do we look at the files in the archive folder (once we have some in there)?

STACK#dir flash:archive                

Directory of flash:/archive/

    8  -rwx       79953   Apr 8 2013 20:45:37 -05:00  running-config

There are times when you need to “go into” a folder such as archive to perform maintenance like deleting a large number of files. Like in Unix and Windows we can change directory.

STACK#cd archive

STACK#dir

Directory of flash:/archive/

    8  -rwx       79953   Apr 8 2013 20:45:37 -05:00  running-config

Note that before we changed directory we had to type dir flash:archive to view the folder contents. Once we changed directory we only have to dir. Sometimes we forget where we are in flash, but we can ‘print the working directory’.

STACK#pwd

flash:/archive/

STACK#

We can move up a single folder towards the root.

STACK#cd ..

STACK#pwd

flash:/

I like to keep the root of my file systems pretty clean, so I make a folder for just about everything that is custom. For example I create a folder for archived configs, archived IOS, TcL scripts, base configs and cut sheets, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *