Code for booting the system from the TFTP server

Installing a new image onto your Cisco router can be a frightening endeavor. Fortunately, Alexander Prohorenko is here to take away a bit of the fright!

The show flash command displays a directory of the contents of flash memory. Now, you need to use the copy command to copy your image:
nas21#copy flash:c3640-is-mz.120-7.T.bin tftp:
IP address of remote host []?
filename to write on tftp host? c3640-is-mz.120-7.T.bin
writing c3640-is-mz.120-7.T.bin !!!!...
successful tftp write.

The image is successfully copied.

Don’t forget that in some implementations of TFTP, you must first create a dummy file on the TFTP server and give it read, write, and execute permissions before copying a file over it. For example, for the FreeBSD default TFTP 'tftpd' daemon, to copy a file to a TFTP server, I have to pass through:
white@onyx:/usr/tftp>touch some.filename
white@onyx:/usr/tftp>chmod a+rw some.filename
white@onyx:/usr/tftp>ls -al
total 2
drwxr-xr-x  2 root  wheel  512 Feb  3 09:48 .
drwxrwxrwt  5 root  wheel  512 Feb  3 09:47 ..
-rw-rw-rw-  1 root  wheel    0 Feb  3 09:48 some.filename

Do not forget to restrict read and write permissions after you finish working with the file!
The Remote Copy Protocol (RCP) requires that the client send a remote username for each RCP request to the server. When you copy an image from the router to a server using RCP, the Cisco IOS software sends the first valid username in the following list:
  • The remote username specified in the copy command, if one is specified
  • The username set by the ip rcmd remote-username command, if the command is configured
  • The remote username associated with the current TTY (terminal) process (For example, if the user is connected to the router through TELNET and was authenticated through the username command, the router software sends theTELNET username as the remote username.)
  • The router host name

In the example below, I'll try to copy a system image file from flash memory to the RCP server:
nas21#copy flash:c3640-is-mz.120-7.T.bin rcp:nas211@

Verifying checksum for `c3640-is-mz.120-7.T.bin' (file # 1)...[OK]
Writing 3640.old -

The image was copied.

The FTP copying process is quite similar to the one for RCP. The FTP protocol requires that the client send a remote username and password on each FTP request to the ftp server. When you copy a configuration file from the router to a server via FTP, the Cisco IOS software sends the first valid username in the following list:
  • The username specified in the copy command, if a username is specified
  • The username set by the ip ftp username command, if the command is configured
  • Anonymous

The router sends the first valid password in the following list:
  • The password specified in the copy command, if a password is specified
  • The password set by the ip ftp password command, if the command is configured

The router forms a password username@routername.domain. The variable username is the username associated with the current session; routername is the configured host name, and domain is the domain of the router. The username and password must be associated with an account on the FTP server.

If you are writing to the server, the FTP server must be properly configured to accept the FTP write request from the user on the router.
nas21#copy flash:c3640-is-mz.120-7.T.bin

writing 3640.old!!!!...
successful ftp write.

The image was copied to FTP server at,
using the username nas21 and the password nas21psw.

Installing a new image
Okay, now you have completed the first stage—the backup stage. The next step is to copy a new image file to your flash memory, thus replacing the old one.

Filenames in flash memory can be up to 63 characters long and are not case-sensitive because they are always converted to lowercase. The destination filename must be an alphanumeric expression.

You should be sure there is enough space available before copying a file to flash memory. You can do this with the following command:
nas15#show flash:

System flash directory:
File  Length   Name/status
  1   4703156  c3640-i-mz.120-7.T.bin 
  2   384056   mica-modem-pw. 
  3   25       snmpengineid 
[5087432 bytes used, 3301176 available, 8388608 total]
8192K bytes of processor board System flash (Read/Write)

The string
[5087432 bytes used, 3301176 available, 8388608 total]

indicates the available amount of space on the flash device. In this example, we have 3,301,176 bytes free.

If the space available is less than the amount needed, the copy command is partially executed, but the entire file is not copied into flash memory. The failure message
buffer overflow - xxxx/xxxx

appears, where xxxx/xxxx is the number of bytes read from the source file and the number of bytes available on the destination device. Click here to see a sample output of a successful process.
nas15#copy tftp:// flash:c3600-i-mz

Accessing file 'c3600-i-mz' on
Loading c3600-i-mz from (via Ethernet1/0): ! [OK]
Erase flash device before writing? [confirm]
Flash contains files. Are you sure you want to erase? [confirm]
Copy 'c3600-i-mz' from server
  as 'c3600-i-mz' into Flash WITH erase? [yes/no] yes

Erasing device... eeeeeeeeeeeeeeee ...erased
Loading c3600-i-mz from (via Ethernet1/0):
[OK - 1711088/4194304 bytes]
Verifying checksum... OK (0xF89A)
Flash device copy took 00:00:17 [hh:mm:ss]

If you have enough free space on your flash device, you can avoid erasing its content. (The FTP and RCP copying process would be the same as the one outlined in the above section.)

Before booting from flash memory, you must use the verify command to ensure that the checksum of the image in flash memory matches the checksum listed in the README file that was distributed with the system software image. The flash memory content listing does not include the checksum of individual files. To recompute and verify the image checksum after an image has been copied into flash memory or a flash memory device, use the verify command like this:
nas5#verify flash:c3640-i-mz.120-7.T.bin
Verified flash:c3640-i-mz.120-7.T.bin

The final stage: reboot
Now that you have completed the second stage, you're ready to get to the last stage—the reboot. But before reloading the router, you have to configure it to boot the correct image. Cisco can load the boot images from different places, starting with the flash memory device and finishing with the MOP server.

Below you see the output of the help system. This output is describing to you the different methods of booting.
nas5#config terminal
nas5(config)#boot system ?
  WORD   TFTP filename or URL
  flash  Boot from flash memory
  mop    Boot from a Decnet MOP server
  rcp    Boot from a server via rcp
  rom    Boot from rom
  tftp   Boot from a tftp server

I'm going to stop on two of the most usable ways of loading IOS images: from the flash device and from TFTP server.

To boot your router from the flash device, use the boot system command:
nas5#configure terminal
nas5(config)#boot system flash c3640-i-mz.120-7.T.bin

Click here to see the code used to boot the system from the TFTP server.
nas5(config)#boot system tftp://

You can also combine these boot options. In the example above, if the booting from flash fails, the router will try to boot from TFTP server.

After this, you must change the configuration register on your router:
nas5(config)#config-register 0x010F

Be aware that the value of config-register may vary from series to series on Cisco routers. To find this value for your router, simply refer to the supporting documentation that came with the router; it should be listed there. Now it's time to reload and have fun with your new IOS!
Don’t forget to keep a console cable connected to the Cisco router. Although the process depicted in this article is pretty trivial, you could be a victim of sudden power shutdown during the process of uploading a new IOS image to the flash memory. In this case, the only rescue would be that console cable. Being prepared for such an occasion will keep your network, router, and, most importantly, your job safe. Good luck!The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

Editor's Picks