Deleting Files from Flash

Problem

You want to erase files from your router’s flash.

Solution

To delete all of the files from your router’s flash memory, use the erase command:

Router1#erase slot1:
Erasing the slot1 filesystem will remove all files! Continue? [confirm] <enter>
Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased
Erase of slot1: complete
Router1#

Tip

Not all router types support the erase command.

You can remove individual files from the router’s flash memory with the delete command:

Router1#delete slot1:c3620-ik9s-mz.122-13.bin
Delete filename [c3620-ik9s-mz.122-13.bin]? <enter> 
Delete slot1:c3620-ik9s-mz.122-13.bin? [confirm] <enter>
Router1#

Discussion

As we have indicated, there are two ways to delete files from flash, depending on the type of router. The difference arose because Cisco routers use three different kinds of filesystems, called Class A, Class B, and Class C. Table 1-2 shows the filesystems that Cisco’s most common routers use.

Table 1-2. Supported filesystems of common Cisco routers

Router typeFilesystem type
7000 (RSP)Class A
7500 (RSP 2 ,4, and 8)Class A
12000Class A
Route Switch Module (RSM)Class A
1600Class B
2500Class B
3600Class B
4000Class B
AS5300Class B
AS5800Class C
7100Class C
7200Class C

Table 1-3 lists some of the different filesystem commands, their meanings, and the filesystems that they work with.

Table 1-3. Filesystem commands and their meanings

CommandFilesystemDescription
DeleteAllMarks the files as deleted, but does not permanently remove them from flash.
SqueezeAPermanently removes all files that have been marked as deleted.
FormatA and CErases the entire flash device.
VerifyAllVerifies that the IOS file’s checksum matches the value encoded in the image.
UndeleteA and BRecovers deleted files.
EraseA and BErases the entire flash device.

The erase command is not available on all router types. On routers that use the Class C filesystem, you can remove files from the flash only with the delete command.

The delete command marks files as deleted, but does not permanently remove them:

Router1#show slot1:

PCMCIA Slot1 flash directory:
File  Length   Name/status
  1   11992088  c3620-ik9s-mz.122-13.bin [deleted] 
[16515072 bytes used, 0 available, 16515072 total]
16384K bytes of processor board PCMCIA Slot1 flash (Read/Write)

Router1#

You can permanently remove this file and reclaim the space on the flash device with the squeeze command. Note, however, that only routers with the type A filesystem support this command:

Router1#squeeze slot1:
Squeeze operation may take a while. Continue? [confirm] <enter>
squeeze in progress... 
Squeeze of slot1 complete
Router1#

The squeeze function can take up to several minutes, so be patient. Once the squeeze command is complete, you can view the flash device to verify that the file is gone:

Router1#show slot1:

PCMCIA Slot1 flash directory:
No files in PCMCIA Slot1 flash
[0 bytes used, 16515072 available, 16515072 total]
16384K bytes of processor board PCMCIA Slot1 flash (Read/Write)

Router1#

The file is has now been permanently removed, and you can no longer recover it with the undelete command. On routers with filesystems that do not support the squeeze command, the only way to permanently remove deleted files is to use the erase command. However, the erase command deletes the entire flash system and will not permit you to delete individual files. It’s all or nothing. In the next recipe, we will look at ways to partition flash devices to reduce the impact of the erase command.

See Also

Recipe 1.12

Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.