DEV Community

hub
hub

Posted on

formate usb-sticks on Ubuntu-. on the command-line and not with gui-tools

hi there good day dear folks
i want to make sure >how to formate usb-sticks on Ubuntu-. on the command-line and not with gui-tools
so i thought it would be the best to write down my idea. Well its so: writing down the things helps me to make sure that i can discuss all the ideas and plans with others - this helps me alot
so i loe to hear from you - do you think that the written down procedures are all right - an i do so!?

to begin with the beginning:
To show the USB drive among all storage partitions and volumes on your computer use:

lsblk
we can also use:
df
Suppose it may be /dev/sdy1. Unmount it with:

sudo umount /dev/sdy1
sTo format drive with the FAT32 file system format:
udo mkfs.vfat -F 32 /dev/sdy1

To set a file system label for our pen drive in the process:

sudo mkfs.vfat -F 32 -n 'name_for_our_pendrive' /dev/sdy1
well that said i think we must include the -F 32 part to specify the FAT size, it is not 32 by default in ubuntu 19.10. For more info see man mkfs.fat.h-drive

well i wanna do this the Command-Line way.
I dont wanna formate the device from the GUI, i will go the Command lie way and do this way.
first of all- i Open the Terminal (Ctrl+Alt+T)
then i list my block storage devices by issuing the command lsblk
afterwards i identify my pen drive by it's SIZE. In my case its /dev/sdb

see like so:
charles@NS010: $ lsbkk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 10G 0 part /
├─sda2 8:2 0 208.1G 0 part /home/han/daten
└─sda3 8:3 0 14.8G 0 part
sdb 8:17 1 1.8G 0 disk
└─sdb1 8:17 1 1.8G 0 part /media/charles/data
sr0 11:0 1 1024M 0 rom

then i do the following: i erase everything in the pen drive (well my friends say that this step is also optional):
then i do the following

sudo dd status=progress if=/dev/zero of=/dev/sdb bs=4k && sync

and then i continue
Replace /dev/sdb with our corresponding device.
well its ptretty important that we type very carefully this name or we may end up erasing one of our other disks. This will take some time. (option status=progress is not mandatory but provide ou some feedback)
It will pretend to be stuck. Just be patient.
for example:

dd if=/dev/zero of=/dev/sdb bs=4k && sync
dd: error writing '/dev/sdb': No space left on device

3984257+0 records in
3984256+0 records out
9127512576 bytes (8.1 GB) copied, 1236.37 s, 6.6 MB/s

now we are going to make a new partition table in the device:
sudo fdisk /dev/sdb
Then here we ress letter o to create a new empty DOS partition table.

and now i am ready to make a new partition:

doing so i first:
press letter n to add a new partition. then i will be prompted for the size of the partition.
Making a primary partition when prompted, if i am not very sure.
Then i press letter w to write table to disk and exit.

Format the new partition.
so my new partition label with the command lsblk

well - in my case it is /dev/sdb1.
Once again at this point we have to pay attention to this name as there will
not be any protection to prevent we to erase an other disk.

charles@NS010: $ lsbkk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 10G 0 part /
├─sda2 8:2 0 208.1G 0 part /home/han/daten
└─sda3 8:3 0 14.8G 0 part

sdb 8:17 1 1.8G 0 disk
└─sdb1 8:17 1 1.8G 0 part
sr0 11:0 1 1024M 0 rom

charles@NS010: $
well its so : writing down the things helps me to make sure that i can discuss all the ideas and plans with others - this helps me alot

so i loe to hear from you
what do you say!?

Top comments (0)