Prepping a USB flash drive for a network system upgrade

I was upgrading the Cisco SD-WAN routers recently. According the Cisco, to manually up upgrade the ASR1002-HX via USB stick. The USB must not bigger than 32GB and must be formatted in FAT32 format.

Anyways I have I spare USB 32GB laying around and planning to upgrade my VyOS router/firewall via USB stick. I thought I would post how to create a partition and format the USB stick to FAT32.

Plug the USB stick to the laptop then locate the location of the USB stick. We can use lsblk or fdisk -l. This post we are working on /dev/sdb. Yours is probably different, so make sure you pick the correct one.

fdisk -l
...
... omitted for brevity
...
Disk /dev/sdb: 57.72 GiB, 61958258688 bytes, 121012224 sectors
Disk model: USB 3.0 FD      
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e460c94

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 121012223 121010176 57.7G  b W95 FAT32

Back to partitioning and formating using fdisk. Just in case, Ubuntu flavors should already have the dosfstools installed if you do not have it. It can be install via apt.

sudo apt install -y dosfstools

Ensure that USB stick has been unmounted: sudo umount /dev/sdb1; otherwise, continue and select the current USB stick

fdisk /dev/sdb

# The p option would print the partition of /dev/sdb
Command (m for help): p
Disk /dev/sdb: 57.72 GiB, 61958258688 bytes, 121012224 sectors
Disk model: USB 3.0 FD      
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e460c94

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 121012223 121010176 57.7G  b W95 FAT32

Now that we know that this is the USB stick, delete the partition by entering d

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help):

Create a new partition by using the n option. Keep all the default options

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-121012223, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-121012223, default 121012223): 

Created a new partition 1 of type 'Linux' and of size 57.7 GiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): 

Change the partition type by selecting t.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): b
Changed type of partition 'Linux' to 'W95 FAT32'.

Command (m for help): 

Write the changes by entering w. If you get the message below, it means that the USB is mounted. Make to unmount the USB first and redo the process from fdisk /dev/sdb section of this post.

# Output with error
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

# Must unmount the USB stick
sudo umount /dev/sdb1

# This should be the correct output
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Verify the US stick using the fdisk -l command.

sudo fdisk -l /dev/sdb
Disk /dev/sdb: 57.72 GiB, 61958258688 bytes, 121012224 sectors
Disk model: USB 3.0 FD      
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e460c94

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 121012223 121010176 57.7G  b W95 FAT32

Now that we have partitioned the USB stick, we need to format it to FAT32.

sudo mkfs -t fat -F 32 /dev/sdb1
mkfs.fat 4.1 (2017-01-24)

And we are done. Below is optional, but if you want to change the label of the USB stick, install mtools from the apt repository. This will allow us to rename the USB stick with the FAT32 format.

# Install mtools
sudo apt install -y mtools

# Check the current label
sudo mlabel -i /dev/sdb1 -s ::

# Change the label
sudo mlabel -i /dev/sdb1 ::fat32_usb

Cheers!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
WordPress Appliance - Powered by TurnKey Linux