Skip to content

Instantly share code, notes, and snippets.

@tankibaj
Last active January 30, 2021 01:38
Show Gist options
  • Save tankibaj/8f0af2c0aedae5753ef94d57543a3d35 to your computer and use it in GitHub Desktop.
Save tankibaj/8f0af2c0aedae5753ef94d57543a3d35 to your computer and use it in GitHub Desktop.

Attach USB to System

Insert a USB drive into your system and identify your USB drive correctly. This is the step you need to take care, because you may format the wrong disk if not correctly identify your disk.

lsblk

Output:

NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                   8:0    0 111.8G  0 disk
├─sda1                8:1    0   512M  0 part /boot/efi
└─sda2                8:2    0 111.3G  0 part
  ├─vgubuntu-root   253:0    0 110.3G  0 lvm  /
  └─vgubuntu-swap_1 253:1    0   980M  0 lvm  [SWAP]
sdb                   8:16   1  58.4G  0 disk
└─sdb1                8:17   1  58.4G  0 part
df -h

Output

Filesystem                 Size  Used Avail Use% Mounted on
udev                       1.9G     0  1.9G   0% /dev
tmpfs                      381M  1.9M  379M   1% /run
/dev/mapper/vgubuntu-root  109G   11G   93G  11% /
tmpfs                      1.9G     0  1.9G   0% /dev/shm
tmpfs                      5.0M  4.0K  5.0M   1% /run/lock
tmpfs                      1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                  511M   16M  496M   4% /boot/efi
tmpfs                      381M   20K  381M   1% /run/user/1000
/dev/sdb1                   59G   67M   59G   1% /media/naim/24FE0D9D29511F6A

Now, You can see that the USB drive is attached as /dev/sdb device. Which is mounted on /media/naim/24FE0D9D29511F6A .

Format USB Drive

Whenever we attach a USB drive in Ubuntu, it automatically mounted to the system. We can not format any disk on Linux systems which are already mounted. So first un-mount /dev/sdb1 USB drive on your system.

sudo umount /dev/sdb1

Now, Use one of the following commands as per the file system you want. To format a USB drive, most of the users prefer VFAT and NTFS file systems because they can be easily used on the Windows operating system.

Format with vFat File System

sudo mkfs.vfat /dev/sdb1 

Format with NTFS File System

sudo mkfs.ntfs /dev/sdb1 

Format with EXT4 File System

sudo mkfs.ext4 /dev/sdb1 

Similarly, you can format USB Flash drive with any required file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment