Sobes.tech
Middle

How can you format a disk in Linux?

sobes.tech AI

Answer from AI

In Linux, disk formatting typically involves creating a new file system on a partition or disk. The main steps:

  1. Identify the device (e.g., /dev/sdb1) using lsblk or fdisk -l.
  2. If necessary, create or modify partitions using fdisk, parted, or gdisk.
  3. Format the partition with a file system creation command, for example:
  • For ext4:
sudo mkfs.ext4 /dev/sdb1
  • For xfs:
sudo mkfs.xfs /dev/sdb1
  • For vfat (FAT32):
sudo mkfs.vfat /dev/sdb1
  1. After formatting, you can mount the partition:
sudo mount /dev/sdb1 /mnt

Important: Formatting destroys all data on the partition, so be careful and ensure you have selected the correct disk/partition.

How can you format a disk in Linux? — DevOps - sobes.tech