To format a USB pen (also known as a USB flash drive) in Linux, you can use the fdisk
or gparted
utilities.
Here's how to format a USB pen using fdisk
:
Insert the USB pen into the computer and determine its device name:
Run the following command to list all the available block devices on the system:
lsblk
Look for the USB pen in the list. It should be identified by a device name, such as /dev/sdb
.
Run the fdisk
utility:
Run the fdisk
utility and specify the device name of the USB pen as the argument. For example:
sudo fdisk /dev/sdb
Delete the existing partition:
Type d
to delete the existing partition.
Type 1
to select the first partition.
Create a new partition:
Type n
to create a new partition.
Type p
to create a primary partition.
Type 1
to create the first partition.
Press Enter to accept the default values for the partition start and end sectors.
Write the changes to the partition table:
Type w
to write the changes to the partition table.
Create a filesystem on the partition:
Use the mkfs
command to create a filesystem on the partition. For example:
sudo mkfs -t ext4 /dev/sdb1
ext4
with the filesystem type of your choice (e.g., xfs
).That's it! The USB pen should now be formatted and ready for use.
Alternatively, you can use the gparted
utility to format the USB pen. gparted
is a graphical partition editor that allows you to create, delete, and resize partitions in a visual interface. To use gparted
, follow these steps:
Install gparted
:
Run the following command to install gparted
:
sudo apt-get install gparted
Run gparted
:
Run the gparted
command and select the USB pen from the device list.
Delete the existing partition:
Right-click on the partition and select "Delete" from the context menu.
Create a new partition.