Partitioning and formatting SD cards on Linux
To partition and format an SD card in Linux, follow these steps: First, connect the SD card to your PC. Then, use the fdisk command in the bash command line to partition the SD card. Finally, use the mkfs command to create a file system (format) on the SD card.
The main commands are as follows:
First, use sudo fdisk -l
to confirm which device in /dev
corresponds to the SD card.
Assuming we have determined that the SD card corresponds to /dev/sde
, we can enter sudo fdisk /dev/sde
to start the partitioning operation:
- Enter
d
to delete partitions. Keep entering until all partitions are deleted. - Enter
n
to create the first partition as the boot partition. - Enter
t
to change the partition type toW95 FAT32
. Boot partitions are generally of this type. - Enter
a
to set the partition as the boot partition. - Enter
n
to create the second partition as the root file system partition. - Since the root file system partition type is usually
Linux
, and the default partition type is alreadyLinux
, there is no need to entert
to change the partition type. - Enter
w
to save and exit.
Finally, after partitioning, we can create the file systems:
|
|
In the above code, the first line creates a FAT32 file system for the boot partition and names it as BOOT
. The second line creates an ext4 file system for the root file system partition and names it as rootfs
.