Formatting a Flash Drive in LINUX. Formatting Linux disk and flash drive. Low-level formatting What format to format a flash drive for Linux

There is no person in the modern world who has never resorted to using removable storage devices. Users store various files on them, from multimedia content to work documents. Sometimes there is a need to completely delete data from the media. In Windows OS this procedure is simple and does not require special knowledge. Formatting a flash drive in Linux is a more complex operation, and skills are desirable here.

Formatting a flash drive in Linux

Common reasons for the need to clean a flash drive are incorrect operation and the user’s desire to completely get rid of all information. If in the second case the standard capabilities of the system help, then if the flash drive malfunctions, they resort to low-level formatting, in which the value “0” is written to all memory sectors.

In Linux, this procedure can be performed in various ways - through the terminal or using third-party utilities. The choice depends entirely on the user's preferences.

How to open a flash drive in Linux

If the system involves a desktop environment, then mounting the drive usually occurs with minimal human intervention. When you connect a device, its shortcut will appear on the desktop. Next, you need to right-click on it and select “Mount”.

Otherwise, the operation is performed manually. First you need to find out the file name of the flash drive. A simple option is to look at it in the /dev/ directory, but to be on the safe side it is better to use the fdisk utility.

After connecting the media, enter the command in the terminal:

A list of names of available disks with information about the size and file system of their partitions will appear on the screen.

Using this information, it becomes clear which name corresponds to the desired flash drive. The next process is to write two lines:

  • sudo mkdir /mnt/usb – create a mount directory;
  • sudo mount /dev/sdc2 /mnt/usb – direct execution.

The drive can now be used.

Important! Upon completion of the work, the flash drive must be unmounted with the following command to avoid data loss and damage to the file system: sudo umount /dev sdc2.

How to format a flash drive in Linux Mint

It is possible to format a flash drive using standard Linux Mint tools. The application is initially included in the OS distribution. It supports formatting in the following file systems:

  • NTFS;
  • FAT32;
  • EXT4;
  • exFAT (since Linux Mint 19).

The program is located in the “Standard” section of the main menu and is called “Formatting a USB flash drive.”

The application will prompt you to fill in the volume label (drive name), select the desired device and file system in which the flash drive will be formatted. On Linux, you will need to enter the administrator password to perform this operation. Upon completion, a message indicating the successful completion of the procedure will be displayed on the screen.

How to format a flash drive in Linux via terminal

In the terminal, the flash drive is formatted using the mkfs utility. It works with all file systems supported on Linux. Example of running mkfs for FAT32:

sudo mkfs -t vfat -L USBFLASH /dev/sdc2

The -L option allows you to specify the partition label.

In other formats the command is identical. For example, you can format a flash drive in ext4 by setting:

sudo mkfs -t ext4 - /dev/sdc2

Important! For the drive to work with Windows, formatting is done in FAT32.

How to format a flash drive in Linux using Gparted

The Gparted utility can format a flash drive in any OS running on the Linux kernel: Debian, Ubuntu, Mint and others. Usually it is already contained in the distribution. Otherwise it needs to be installed. This is possible using the Ubuntu Program Center, or by running the command in the terminal:

  • sudo apt install gparted – for Ubuntu users;
  • sudo yum install gparted - on systems whose distributions are based on Red Hat.

The program is launched by selecting it in the menu, or by executing:

The main window of the program contains information about all connected drives, so there shouldn’t be any problems finding the right flash drive.

First of all, the drive is unmounted by selecting the appropriate item in the context menu.

Next, you need to decide on the formatting principle. If the media previously had any OS, it must be completely wiped. Low-level formatting of a flash drive in Linux becomes possible only in this way. Otherwise, you can skip this point.

In the Edit menu section, select New Partition Table. Next steps you need to follow:

  1. Select MBR table type.
  2. Agree to data loss.
  3. By pressing the “+” button, create a new partition using the entire free memory.
  4. Select the file system to format.

After completing these steps, in the Edit section you need to click Apply to apply the changes. The flash drive is formatted, you can skip the next step.

If the previous steps are not necessary, then formatting becomes easier. To do this, call up the context menu of the flash drive, in which you select the Format to command.

How to format a disk in Linux

When performing subsequent operations, you need to be extremely careful, since even the slightest error can lead to disruption of the file system.

First, you need to view the list of block devices connected to your computer. This is done using the lsblk command. The utility shows disk names, their sizes and other media characteristics. In this case, there are two HDDs: one has the system installed, the second is intended for storing files.

To format a hard drive, the Parted utility is often used. It can be launched via the terminal:

You will need to enter the administrator password, since the work uses superuser mode. Upon successful entry, a program window will appear.

The next step is to create a partition table: MBR or GPT. Let the first type be selected, then enter the command into the terminal:

Here mklabel creates a table, and msdos assumes its type is MBR.

Directly creating partitions has a template:

(parted) mkpart |Partition type| |File system| |Start of the section| |End of section|

For example, if you need one partition that will take up the entire amount of memory, the template will look like:

(parted) mkpart primary ext3 1MiB 100%

For a 2 GB partition:

(parted) mkpart primary ext3 1MiB 2GB

The memory count for the third partition will now start at 2 GB, that is, if you want to set 3 GB, the entry looks like this:

(parted) mkpart primary ext3 1MiB 2GB 5GB

The print parameter is used to view the resulting table.

Now you can exit Parted and format the desired disk using the well-known mkfs utility.

Conclusion

Having encountered the problem once, the user understands that formatting a flash drive in Linux is not as difficult a task as it is thought to be. What’s unusual is that most operations have to be performed through the terminal console. In fact, this approach allows for a more flexible approach to formatting. If the terminal causes difficulties, utilities with an advanced graphical interface come to the rescue.

In this article we will talk about how to format a flash drive in Linux. Let's give an example of the most convenient ways to do this. Everything is done very simply and quickly. We are more than confident that even a beginner can cope here.

Formatting a Flash Drive in LINUX Ubuntu

You can use the drives through the GUI, they are installed by default and are easy to use. Since everything happens more than clearly and most importantly, it’s convenient.

By the way, we previously wrote about the main characteristics of your system.

  • Click the Unity Dash icon
  • Enter “Disks” in the Search column
  • 3rd point: click on the “Disks” icon


After this, a window will open and the application will appear:

  • Select the USB drive you need to format.
  • Click on the gear icon and select Format
    A special small window will appear, just select the option you want and click “Format”

Additionally:

  • There is also an option to find the desired disk and right-click on it. A new menu will appear in which you need to click on the corresponding item - Formatting.
  • After a new window opens, select in which format to format the disk and click on the desired button.

Method 2: Gparted tool

You can format a flash drive using the Gparted program. Which is used by a huge number of Linux users. There you can perform almost all basic tasks with disks that are connected to the device. This can be said to be a leader among similar programs. If you decide to do this using this program, now we will tell you how to install it.

sudo apt-get install gparted

Method 3: Using a terminal

go to Super mode by typing "su" followed by the super mode password

which will show the entire volume on your computer, or you can also use

to view the USB flash drive, suppose it could be /dev/sdb1 enter a command like:

umount /dev/sdb1

mkfs.vfat /dev/sdb1

How to format a disk in fat32 format

Then, edit

mkfs.vfat -n ‘name_for_your_pendrive’ -I /dev/sdb1

to add a name for your pendrive

conclusions

As you understand, this is done very simply. Formatting a USB flash drive in LINUX Ubuntu is very simple. Moreover, there are so many options, and you can choose the most convenient one for yourself.

If you have any questions about the topic " Formatting a Flash Drive in LINUX"- write them in the comments. We will definitely read them and if you have something to add to this article, also tell us about it.

If you find an error, please highlight a piece of text and click Ctrl+Enter.

Most users only know one operating system, Windows, but there are other quality systems.

An excellent option is Linix, the advantages of which are obvious - it is free. And due to its low popularity, much fewer viruses are created for this OS, which is also an important factor.

The only negative is that if you are used to using Windows, you will have to forget everything and learn the OS again. Also, some simple processes become too complex. For example, many are interested in how to format a flash drive in Linux, since there may not be a standard function for this.

Formatting a flash drive in Linux

There are several ways to clean removable memory media, which we will tell you about now:

1. Manual formatting.
To manually clear memory, you will need to launch a command prompt and enter “# dmesg | tail" to find out the media name that was assigned by the system:

When you enter the command, you will receive this information, and the name of the disk is indicated in square brackets. Now you need to enter a new formatting command:

To format to FAT32 use the command - $ sudo mkfs.vfat /dev/disk name


To format to NTFS use the command - $ sudo mkfs.ntfs /dev/disk name

2. Palimpsest utility.
This useful utility may already be built into your Ubuntu. After launching it, just select the removable drive and proceed to format the partition. A window will appear where you can select the file system and also set the disk name:

If your operating system does not have such a utility, just type in the command line - sudo apt-get install palimpsest. The program will be installed on your computer and you can use it.

3. Gparted program.
When using this program, formatting flash drives is even easier. It is enough to select a disk in the main window of the utility, right-click on it and then select the file system in the formatting item:

After another visit to friends with Windows installed, I discovered a bunch of all sorts of junk on my flash drive, such as auto-drivers, incomprehensible exe files, daddies... Fortunately, there was nothing particularly valuable on the device, so I decided to format it... So as not to poke around in those 7 GB in search of brought in :)

Despite the fact that Linux has been my only operating system for quite some time, I haven’t had to format flash drives. Therefore, when doing it for the first time, I decided to keep the stages for myself, in case I forget in the next few years...

By and large, the operation can be performed in “three clicks” using some kind of party manager. And if suddenly for some unknown reason it is not included in the distribution, you can at least use the same gparted: install and run.

I will do this using the command line, simultaneously performing “low-level formatting” in order to get rid of all sorts of software bads, problems with the file system and boot sector that can arise when the device is unsafely removed...
All operations must be carried out on behalf of the superuser.

First, we look at whether the system sees our device, and more broadly, whether the flash drive is alive in hardware
sudo lsusb

Here it is, my Apaser!
Next, you need to determine how the flash drive is detected by the system, how it is designated in dev. There are two options:
ls /dev/disk/by-id -l
That is, we simply scroll through the disks by id. The result looks like this:

The resulting image will display all disk devices. I left a note in the picture regarding the flash device.

Now I know that my flash drive is recognized as sdd. In any case, the likelihood of formatting the wrong device has decreased :)
You can also look at the flash drive via hdparm (but not necessary):

I see that write protection is turned off.
I'm starting to format.
sudo dd if=/dev/zero of=/dev/sdd
With this command I fill all the space with zero bytes. After executing the command, all data will be irretrievably lost! Along the way, we will get rid of software bads, damaged tables, boot sector, etc.

The procedure is quite long, the image shows that my 8GB flash drive was filled with “zeros” for 3300 seconds (approx. 55 minutes) at a speed of 2.4 MB/s. We don’t pay attention to the message about running out of space, because the flash drive has a certain finite size, but the “zero” generator has no size :)
Just in case, I look at the numbers “read and written”; a large difference in the values ​​will indicate some physical problems: it was written down, but could not be subtracted...

I'm starting to work on creating sections...
sudo fdisk /dev/sdd

At startup, the utility begins to swear angrily about the fact that it didn’t find anything... Of course! So much time was filled with zeros.
And after swearing, he offers help in resolving the situation - press m, he says. We press = s... And we see a list of possible actions that we can take. I'm interested in creating a new section - letter n

Moreover, this section will be the main (p) and the first (1). I leave all other values ​​at default by simply pressing Enter.

I'll see what happened in the end - p

Amazing. We have a partition, but it’s really Linux. Correcting the situation - t

The t argument allows you to change the section ID. Therefore, after clicking on t, we are asked to select section (1) and ID from a fairly wide list of options. I am interested in the possibility of using a flash drive both on computers with Linux as an operating system, and on Windows machines. Moreover, without installing special drivers, which are needed, for example, for exFAT.

And one more thing... The flash drive is 8 GB in size, which means I can no longer use fat16 as a file system. That is, fat32 remains - the letter b. We're jamming...

That is, as a result of this manipulation, my flash drive is ready to take on the load of the FS: we created the main partition and assigned an identifier corresponding to FAT32 to it.
Everything is done, all that remains is to write down the result - the letter w.

Well, there is one last trick left - you need to format the prepared flash drive.
mkfs.vfat -F32 /dev/sdd1

That is, we create (mkfs) a fat32 file system (vfat -F32) on the /dev/sdd1 device
All! The flash drive is ready to go!

=========
P.S.

fdisk help commands

a boot flag toggle
b editing bsd disc label
c toggle the DOS compatibility flag
d delete partition
l list of known file system types
m display this menu
n adding a new partition
o creating a new empty DOS partition table
p partition table output
q exit without saving changes
s creating a new blank Sun disk label
t change the partition system id
u Changing screen/content units
v partition table check
w write partition table to disk and exit
x additional functionality (for experts only

fdisk - usage

Usage:
fdisk change partition table
fdisk -l list partition table(s)
fdisk -s give partition size(s) in blocks

Options:
-b sector size (512, 1024, 2048 or 4096)
-c[=] compatible mode: ‘dos’ or ‘nondos’ (default)
-h print this help text
-u[=] display units: ‘cylinders’ or ‘sectors’ (default)
-v print program version
-C specify the number of cylinders
-H specify the number of heads
-S specify the number of sectors per track

Based on this very good article

Formatting a flash drive is a fairly simple task that every user often faces. In the Windows operating system, everything is done intuitively and literally in a couple of clicks. But in Linux everything is not so simple. It may even seem that formatting a flash drive in Linux is very difficult. Actually this is not true.

There are several ways to solve such a simple task in Linux, and today we will look at the most interesting of them. Namely, formatting a flash drive using Gparted, the terminal and the Disks utility in Ubuntu or any other distribution that uses Gnome. First, let's look at a technique that will work in all distributions - using the terminal and the utility mkfs.

Formatting a USB flash drive in Linux using the terminal

Format a flash drive in the terminal is not very difficult, but first you need to know how to identify this flash drive in the system. All devices in Linux are defined as files in the /dev directory, and so is your flash drive.

But if you just go to this directory, it will be difficult for you to determine which file is responsible for the flash drive, because all the files for the drives look similar. Usually the name starts with sd, then another letter: a, b, c, d and so on, depending on the order in which the disk is connected to the system. Next comes the number of the partition on the flash drive, usually it is 1, because a flash drive usually contains only one partition. For example /dev/sdb1 or /dev/sdc1.

Step 1. Determine the name of the flash drive

The easiest way to determine the name of a flash drive in the system is to use the utility fdisk, but this option is only suitable if you know the size or label of the flash drive. Just run the command:

Disk /dev/sdb: 15 GiB, 16064184320 bytes, 31375360 sectors
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: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 31375359 31373312 15G with W95 FAT32 (LBA)

It will display all connected devices, including your flash drive, in the terminal. All you have to do is find it by size, which is written in the column size. In our example, the flash drive is represented by the file /dev/sdb1.

You can also find out the file name of the flash drive using the utility df, only for this it must be mounted into the file system. To see which devices are connected to which folders, run:

/dev/sda5 51131020 16232716 34361116 33% /
/dev/sda6 153342012 143601876 8788232 95% /home
/dev/sdb1 15670272 4927568 10742704 32% /run/media/sergiy/4AA9-C01D

Now you can understand that the flash drive is mounted to the folders /mnt, /media, /run/media, and the size is also indicated here in the column available. Usually this is quite enough.

Step 2. Unmount the flash drive

If the flash drive is mounted in a file system, then you will not be able to format it. Therefore, you first need to unmount it, to do this run:

sudo umount /dev/sdb1

Here /dev/sdb1 is the name of the flash drive in the file system, which we learned in the previous step.

Step 3: Formatting

$ sudo mkfs -t file system device

Any system supported can be used as a file system, for example, ext4, ntfs, xfs, btrfs, vfat. But for normal operation of a flash drive in Windows, it is recommended to use the vfat file system. Using the option -L You can set the section label. Then the command will look like this:

sudo mkfs -t ext4 -L FLASH /dev/sdb1

For the vfat file system option -L is not supported, you should use it instead -n:

sudo mkfs -t vfat -n FLASH /dev/sdb1

After formatting the flash drive in Linux is completed, the flash drive will be ready for use.

Formatting a flash drive in Gparted

Another universal method to format a flash drive in Linux is to use the Gparted disk management utility.

Step 1. Install Gparted

Usually it is already installed on the system, but if not, you can install this program from the official repositories. To do this, type in Ubuntu:

sudo apt install gparted

And in Red Hat and distributions based on it:

Step 2. Search for a flash drive

Finding a flash drive in this program will not be difficult for you. You can switch between devices in the upper right corner. You can find your flash drive by label, size, file system - all the information is displayed here, so you shouldn’t have any problems with the search.

Step 3. Unmount the flash drive

Also, as in the previous case, you need to unmount the flash drive to format it. To do this, right-click on the flash drive section and select Umount:

I'm guessing there is only one partition on the flash drive. Therefore, all actions will need to be performed only for him. If there are several partitions, unmount them all.

Step 4. Completely erase the flash drive

If Linux or another operating system was previously installed on the flash drive, it must be completely cleared, including the partition table. This is the only way you can perform low-level formatting of a Linux flash drive. If not, you don’t need to do anything like that, move on to the next step. Open a menu item Edit and press New Partition Table.

Select the MBR table type and confirm that you agree that all data on the flash drive will be lost. Then use the button with the "+" sign to create a new partition for all the free space. You also need to select a file system here.

Then open the item again Edit and press Apply to apply the changes. Done, your flash drive is formatted, you can skip the sixth step.

Step 5. Formatting the flash drive

If you used the previous method, then you don’t need to do anything. The flash drive is ready for use. If not, you will only need to format one partition. To do this, click on this section and select Format to in the context menu:

Then select the file system, again, for the flash drive to work in Windows, you need to use FAT.

That's all, now the flash drive is ready for use, and you can connect it to the system and write files there. But let's look at another method that is only suitable for Gnome.

How to format a flash drive using Disk

Disk Utility is the standard disk management utility on Linux distributions that use the Gnome desktop environment.

Step 1: Launch Disk Utility

You can launch the program from the Dash main menu by simply searching for Disk, which usually comes with the system by default:

Step 2. Search for a flash drive

You can very easily find the flash drive in the main program window: firstly, it is in the last place, and secondly, the disk label, size and other parameters are displayed here:

Step 3: Formatting

Formatting here is very easy, just click Format Volume:

Then select the file system and name of the flash drive:

All that remains is to confirm the action to format the Linux flash drive:

Formatting a flash drive in Ubuntu 16.04

Another method specifically for this operating system. Here, formatting a Linux flash drive is generally very simple. Find your device in the Nautilus file manager, right-click on it and select Format...:

Select the formatting method, file system and name of the flash drive, then click Format:

Ready. When the process is complete, your flash drive will be completely clean and ready to use.

conclusions

That's all. Now you know that formatting a flash drive in Linux is not such a difficult task. It is enough to execute a few commands or a couple of mouse clicks. And in Ubuntu, in general, everything is done in an elementary way. If you have any questions, ask in the comments!

To conclude the video about how flash drives and memory chips are made: