Format flash linux terminal

How To Format USB Drive in Linux Command Line

USB formatting is the process of erasing all data from the disk and prepare it for use. Sometimes we are required to change the filesystem on our USB drive, In that case, we have to format the USB drive with the new filesystem type. Formatting a USB drive in Ubuntu using Terminal commands is much easier than formatting it in Windows systems.

This tutorial will help Ubuntu (Linux) users with the simple steps for format a USB flash drive using the command line.

Step 1 – 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.

Filesystem Size Used Avail Use% Mounted on /dev/sda1 28G 24G 2.3G 92% / udev 1.4G 12K 1.4G 1% /dev tmpfs 277M 1.2M 276M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1.4G 34M 1.4G 3% /run/shm /dev/sdc1 14.8G 1.4G 13.4G 10% /media/tecadmin 

Now, You can see that the USD drive is attached as /dev/sdc1 device. Which is mounted on /media/tecadmin.

Step 2 – Format USB Drive in Linux

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

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.

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

Conclusion

In this tutorial, you have learned to format a USB drive on a Linux system via the command-line interface.

Источник

How to Format USB Flash drive from command line on Linux / Ubuntu

If there is a lot of content on the usb flash drive and you want to erase all of it quickly then a simple way to do it is by formatting it. There are many gui tools available on linux to view and format partitions on storage devices like ssds and flash drives.

These include Gnome Disks, Gparted, KDE Partition manager and so on. Besides gui tools drives can also be formatted from the command line in linux, and the process is quite simple.

Читайте также:  How to 32 or 64 bit linux

Format from terminal

Here are the simple steps

1. Plug-in the drive: First insert the usb drive. However do not mount it from any file manager like Dolphin or Nautilus. In order to format the drive partitions it must stay unmounted.

2. Check the partition device path: Note down the partition path, which looks something like /dev/sdaX or /dev/sdbX . Once the system has detected the drive we can use the blkid, lsblk or mount command to check the partition devices. Here is a quick example

sudo lsblk -e7 -o "NAME,PTTYPE,FSTYPE,SIZE,LABEL,PARTLABEL,PATH,PHY-SEC,VENDOR"
$ sudo lsblk -e7 -o "NAME,PTTYPE,FSTYPE,SIZE,LABEL,PARTLABEL,PATH,PHY-SEC,VENDOR" NAME PTTYPE FSTYPE SIZE LABEL PARTLABEL PATH PHY-SEC VENDOR sda dos 111.8G /dev/sda 512 ATA └─sda1 dos ext4 95.4G /dev/sda1 512 sdb dos 111.8G /dev/sdb 512 ATA └─sdb1 dos swap 95.8G /dev/sdb1 512 sdc gpt 447.1G /dev/sdc 512 ATA └─sdc1 gpt ext4 400G /dev/sdc1 512 sdd dos iso9660 14.5G Fedora-KDE-Live-36-1-5 /dev/sdd 512 SanDisk ├─sdd1 dos 12.4G /dev/sdd1 512 └─sdd2 dos vfat 9.9M ANACONDA /dev/sdd2 512 $

Note the SanDisk usb drive in the above output which is mapped to device sdd with 2 partitions are /dev/sdd1 and /dev/sdd2 respectively.

3. Format with mkfs: Next format the partition using the mkfs command and specify the desired file-system. To format with FAT file-system use the following command:

sudo umount /dev/sdd1 sudo mkfs -t vfat /dev/sdd1 sudo eject /dev/sdd1

First unmount it, then create filesystem/format using the mkfs command and then eject when done.

Here is what the output of the mkfs command would look like:

$ sudo mkfs -t vfat /dev/sdd1 [sudo] password for enlightened: mkfs.fat 4.2 (2021-01-31) $

Now your partition is ready for use. Start by copy some files to it. Can also use gparted so that you dont have to remember the commands.

Note that the following commands are equivalent:

sudo mkfs -t vfat /dev/sdd1 or sudo mkfs.vfat /dev/sdd1

For other file-systems use any of the following commands:

  • mkfs.bfs
  • mkfs.cramfs
  • mkfs.exfat
  • mkfs.ext2
  • mkfs.ext3
  • mkfs.ext4 — Format to Ext4 file-system
  • mkfs.fat
  • mkfs.minix
  • mkfs.msdos
  • mkfs.ntfs — Format to NTFS file system
  • mkfs.vfat — Format to FAT-32

Other commands to check partition device path

Once you know the device name, you can use fdisk command as well to list the partitions in that particular drive:

$ sudo fdisk -l /dev/sdd Disk /dev/sdd: 14.53 GiB, 15597568000 bytes, 30464000 sectors Disk model: Cruzer Blade 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: 0x4953725b Device Boot Start End Sectors Size Id Type /dev/sdd1 4388864 30463999 26075136 12.4G 83 Linux /dev/sdd2 172 20455 20284 9.9M ef EFI (FAT-12/16/32) Partition table entries are not in disk order. $

The mount command can also be used to get the partition device path, however it will show only if the partition is mounted. So first you have to mount it, view using mount command then un-mount before formatting, which is tedious.

$ mount | grep -i '/dev/s' /dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) /dev/sda1 on /var/snap/firefox/common/host-hunspell type ext4 (ro,noexec,noatime,errors=remount-ro) /dev/sdc1 on /media/enlightened/a935afc9-17fd-4de1-8012-137e82662ff0 type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2) /dev/sdd2 on /media/enlightened/ANACONDA type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2) $

Find out the device from the mount output. In this case it is /dev/sdb1

Читайте также:  Навигация файловой системе linux

Formatting unallocated space

The problem with the above approach is that it cannot detect un-allocated free space that is not inside any partition. To view the unallocated space on any drive use the parted command as follows:

$ sudo parted /dev/sdd print free Model: SanDisk Cruzer Blade (scsi) Disk /dev/sdd: 15.6GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1024B 88.1kB 87.0kB Free Space 2 88.1kB 10.5MB 10.4MB primary fat16 esp 10.5MB 2247MB 2237MB Free Space 1 2247MB 15.6GB 13.4GB primary $

In the above command we need to specify the drive device name followed by options «print free». Note the table contains entries marked «Free Space» The 3rd entry in this case indicates about 2.2 GB of free un-allocated space lying on the usb drive.

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

One Comment

  1. FELIPE ORELLANA ROVIROSA August 12, 2019 at 12:12 pm SO good, so simple and concise. It works right on. thanks Silver Moon ! Felipe

Источник

How to Format USB Drives in Linux

Occasionally, it is necessary to format the USB drive (for example, when changing the file system or deleting data). However, many Linux users are afraid to start the formatting process, thinking it is either a very complicated or time-consuming task.

In this tutorial, you will learn how to format the USB drive in Linux using three quick and simple methods:

How to Format USB Drives in Linux.

  • A system running Linux
  • A USB drive
  • Access to the terminal/command line
  • A user account with sudo/root privileges

Which File System to Use for USB Formatting?

There are many file systems in use, differing by maximum file size and operating system compatibility. The most commonly used file systems when formatting a USB drive are:

Their main features and differences are:

File System Supported File Size Compatibility Ideal Usage
FAT32 up to 4 GB Windows, Mac, Linux For maximum compatibility
NTFS 16 EiB – 1 KB Windows, Mac (read-only), most Linux distributions For internal drives and Windows system files
exFAT 16 EiB – 1 KB Windows, Mac, Linux (requires extra drivers to access) For files larger than 4 GB

Method 1: Format USB Using the Terminal

The easiest and fastest way to format a USB drive in Linux is through the terminal. The procedure consists of three steps:

  1. Locating the USB drive.
  2. Unmounting and formatting the USB drive.
  3. Verifying the process was successful.

Follow the instructions below to format a USB drive using the terminal.

Step 1: Locate USB Drive

Open the terminal and run the following command:

The terminal prints out a list of all mounted partitions and relevant information: used space, available space, used space percentage, and the path.

Locate the USB in the list and find the corresponding device. In this example, the USB drive is /dev/sdb1 .

Note: If you are unsure of the drive designation, unplug the USB drive temporarily before running the df command again. The device that is now gone from the list is your USB device.

Читайте также:  Nginx red hat linux

Listing all partitions with df command.

Step 2: Unmount and Format USB Drive

Unmount the USB drives before formatting. To do so, run this command:

Unmounting the USB drive.

After unmounting, format the USB drive using the preferred file system (replace sdb1 with the name of your device):

Step 3: Verify USB Drive Formatting

Confirm the formatting process has completed successfully:

A USB drive with no files indicates successful formatting.

Verifying that the formatting process is done.

Method 2: Format USB Using Disk Utility

The GNOME Disk Utility is a graphical tool for partitioning and formatting storage drives in Linux.

Follow the outlined steps to format a USB drive using the Disk Utility tool.

Step 1: Open Disk Utility

  1. Launch the Application menu.
  2. Type “disk” in the search bar.
  3. Click the Disks icon.

Opening the Disk Utility

Step 2: Identify the USB Drive

Locate the USB drive from the left pane and select it. The right pane contains details about the drive, such as model name, size, serial number, and contents.

Locating USB drive in the Disk Utility.

Step 3: Format the USB Drive

1. Click the gear icon and select the Format Partition option from the drop-down menu.

Selecting the formatting option.

2. Type the preferred name for the USB drive.

Optionally, enable the Erase option to overwrite the existing data from the USB drive. Choose the file system format and click on the Next button.

Setting up the formatting options.

3. A pop-up appears with a warning message about data deletion and formatting details. Start the formatting process by clicking the Format button.

Warning about data deletion.

4. The progress line displays the remaining time until the formatting process completes. Close the Disk Utility when the job completes.

Formatting progress line displaying remaining time until the operation ends.

Method 3: Format USB Using GParted Tool

Formatting via GParted takes the most time as it involves an additional step – installing the tool. However, it is a handy tool that you can use even after you have finished formatting the USB drive.

Follow the steps below to format a USB drive using the GParted tool.

Step 1: Install GParted Tool

1. Open the terminal and install the GParted tool using this command:

Confirm the installation by pressing y and then hit Enter. Wait until the process completes.

Installing the GParted tool.

2. Run the GParted tool with:

The terminal loads the GParted home screen.

The GParted home screen.

Step 2: Start the Formatting Process

1. Select the /dev/sdb option from the drop-down menu at the top of the GParted home screen.

Selecting the USB drive in the GParted tool.

2. Right-click the /dev/sdb1 partition and select Format to. Choose the preferred file system from the list to continue.

Selecting formatting settings in GParted tool.

Step 3: Start the Process

1. Click the green checkmark button to apply all operations.

Applying formatting operation.

2. A pop-up appears with a warning message about data deletion. Click Apply to continue.

A pop-up containing warning message.

The GParted formats the drive. The time required for the formatting process varies depending on the size and type of the USB drive.

Formatting process.

3. Click the Close button to exit the menu when the operation completes.

Closing formatting menu in GParted tool.

In this article, you learned how to format a USB drive in Linux using several methods. Additionally, we went through the main features and differences between the three most commonly used file systems.

Источник

Оцените статью
Adblock
detector