{"id":17025,"date":"2023-11-19T02:01:26","date_gmt":"2023-11-19T02:01:26","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=17025"},"modified":"2023-11-19T04:13:26","modified_gmt":"2023-11-19T04:13:26","slug":"how-to-format-usb-drives-and-sd-cards-on-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/19\/how-to-format-usb-drives-and-sd-cards-on-linux\/","title":{"rendered":"How to Format USB Drives and SD Cards on Linux."},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"407\" src=\"https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-18.png\" alt=\"\" class=\"wp-image-17026\" srcset=\"https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-18.png 768w, https:\/\/www.appservgrid.com\/paw92\/wp-content\/uploads\/2023\/11\/image-18-300x159.png 300w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Before you can use an SD card or USB drive, it needs to be formatted and partitioned. Typically most USB drives and SD cards come preformatted using the FAT file system and do not need to be formatted out of the box. However, in some cases, you may need to format the drive.<\/p>\n\n\n\n<p>In Linux, you can use a graphical tool like GParted or command-line tools such as&nbsp;<code>fdisk<\/code>&nbsp;or&nbsp;<code>parted<\/code>&nbsp;to format the drive and create the required partitions.<\/p>\n\n\n\n<p>This article explains how to format a USB Drive or SD Card on Linux using the&nbsp;<code><strong>parted<\/strong><\/code>&nbsp;utility.<\/p>\n\n\n\n<p>It\u2019s important to note that formatting is a destructive process, and it will erase all the existing data. If you have data on the UDB drive or the SD card, make sure you back it up.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-parted\"><strong>Installing&nbsp;<code>parted<\/code><\/strong><\/h3>\n\n\n\n<p>GNU Parted is a tool for creating and managing partition tables. The parted package is pre-installed on most Linux distros nowadays. You can check if it is installed on your system by typing:<\/p>\n\n\n\n<p><strong>$ <code>parted --version<\/code><\/strong><\/p>\n\n\n\n<p>Copy<code>parted (GNU parted) 3.2 Copyright (C) 2014 Free Software Foundation, Inc. ...<\/code><\/p>\n\n\n\n<p>If&nbsp;<code>parted<\/code>&nbsp;is not installed on your system, you can install it using your distribution package manager.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-parted-on-ubuntu-and-debian\"><strong>Install&nbsp;<code>parted<\/code>&nbsp;on Ubuntu and Debian<\/strong><\/h3>\n\n\n\n<p><strong>$ <code>sudo apt update <\/code><\/strong><\/p>\n\n\n\n<p><strong><code>$sudo apt install parted<\/code><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-parted-on-centos-and-fedora\"><strong>Install&nbsp;<code>parted<\/code>&nbsp;on CentOS and Fedora<\/strong><\/h3>\n\n\n\n<p><strong>$ <code>sudo yum install parted<\/code><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"identifying-the-usb-or-sd-card-name\"><strong>Identifying the USB or SD Card Name<\/strong><\/h3>\n\n\n\n<p>Insert the USB flash drive or SD card into your Linux machine and find the device name using the&nbsp;<code>lsblk<\/code>&nbsp;command:<\/p>\n\n\n\n<p><strong>$ <code>lsblk<\/code><\/strong><\/p>\n\n\n\n<p>The command will print a list of all available block devices:<\/p>\n\n\n\n<p><code>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ... <\/code><\/p>\n\n\n\n<p><code>sdb 8:16 1 14.4G 0 disk<\/code><\/p>\n\n\n\n<p><code> \u2514\u2500sdb1 8:17 1 1.8G 0 part \/media\/data ... <\/code><\/p>\n\n\n\n<p>In the example above, the name of the SD device is&nbsp;<code>\/dev\/sdb<\/code>, but this may vary on your system.<\/p>\n\n\n\n<p>You can also use the&nbsp;<code>dmesg<\/code>&nbsp;command to find the device name:<\/p>\n\n\n\n<p><strong>$ <code>lsblk<\/code><\/strong><\/p>\n\n\n\n<p>Once you attach the device,&nbsp;<code>dmesg<\/code>&nbsp;will show the device name:<\/p>\n\n\n\n<p><code>... [ +0.000232] sd 1:0:0:0: [sdb] 30218842 512-byte logical blocks: (15.5 GB\/14.4 GiB) ... <\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"securely-wipe-up-the-data-optional\"><strong>Securely Wipe Up the Data (Optional)&nbsp;<\/strong><\/h2>\n\n\n\n<p>Before formatting the drive, you can securely wipe out all the data on it by overwriting the entire drive with random data. This ensures that the data cannot be recovered by any data recovery tool.<\/p>\n\n\n\n<p>You need to completely wipe the data only if the device is going to be given away. Otherwise, you can skip this step.<\/p>\n\n\n\n<p>Be very careful before running the following command and irrevocably erase the drive data. The&nbsp;<code>of=...<\/code>&nbsp;part of the&nbsp;<code>dd<\/code>&nbsp;command must point to the target drive:<\/p>\n\n\n\n<p><strong>$ <code>sudo dd if=\/dev\/zero of=\/dev\/sdb bs=4096 status=progress<\/code><\/strong><\/p>\n\n\n\n<p>Depending on the size of the drive, the process will take some time to complete.<\/p>\n\n\n\n<p>Once the disk is erased, the&nbsp;<code>dd<\/code>&nbsp;command will print \u201cNo space left on device\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>15455776768 bytes (15 GB, 14 GiB) copied, 780 s, 19.8 MB\/s \ndd: error writing '\/dev\/sdb': No space left on device\n3777356+0 records in\n3777355+0 records out\n15472047104 bytes (15 GB, 14 GiB) copied, 802.296 s, 19.3 MB\/s\n\n<strong>Creating a Partition and Formatting<\/strong>\n\nThe most common file systems are exFAT and NTFS on Windows, EXT4 on Linux, and FAT32, which can be used on all operating systems.\n\nWe will show you how to format your USB drive or SD card to FAT32 or EXT4. Use EXT4 if you intend to use the drive only on Linux systems, otherwise format it with FAT32. A single partition is sufficient for most use cases.\n\n<strong>Format with FAT32<\/strong>\n\nFirst, create the partition table by running the following command:\n\n<strong>$ sudo parted \/dev\/sdb --script -- mklabel msdos<\/strong>\n\nCreate a Fat32 partition that takes the whole space:<\/code><\/pre>\n\n\n\n<p><strong>$ sudo parted \/dev\/sdb &#8211;script &#8212; mkpart primary fat32 1MiB 100%<\/strong><\/p>\n\n\n\n<p>Format the boot partition to FAT32:<\/p>\n\n\n\n<p><strong>$ <code>sudo mkfs.vfat -F32 \/dev\/sdb1<\/code><\/strong><\/p>\n\n\n\n<p>$ <strong><code>mkfs.fat 4.1 (2017-01-24)<\/code><\/strong><\/p>\n\n\n\n<p>Once done, use the command below to print the partition table and verify that everything is set up correctly:<\/p>\n\n\n\n<p><strong>$ <code>sudo parted \/dev\/sdb --script print<\/code><\/strong><\/p>\n\n\n\n<p>The output should look something like this:<code>Model: <\/code><\/p>\n\n\n\n<p><code>Kingston DataTraveler 3.0 (scsi) Disk \/dev\/sdb: 15.5GB Sector size (logical\/physical): 512B\/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 15.5GB 15.5GB primary fat32 lba<\/code><\/p>\n\n\n\n<p>That\u2019s all! You have formatted your device.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"format-with-ext4\"><strong>Format with EXT4<\/strong><\/h3>\n\n\n\n<p>Create a GPT partition table by issuing:<\/p>\n\n\n\n<p><strong>$ <code>sudo parted \/dev\/sdb --script -- mklabel gpt<\/code><\/strong><\/p>\n\n\n\n<p>Run the following command to create a EXT4 partition that takes the whole space:<\/p>\n\n\n\n<p><strong>$ <code>sudo parted \/dev\/sdb --script -- mkpart primary ext4 0% 100%<\/code><\/strong><\/p>\n\n\n\n<p>Format the partition to ext4:<\/p>\n\n\n\n<p><strong>$ <code>sudo mkfs.ext4 -F \/dev\/sdb1<\/code><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mke2fs 1.44.1 (24-Mar-2018)\n\/dev\/sdb1 contains a vfat file system\nCreating filesystem with 3777024 4k blocks and 944704 inodes\nFilesystem UUID: 72231e0b-ddef-44c9-a35b-20e2fb655b1c\nSuperblock backups stored on blocks: \n\t32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208\n\nAllocating group tables: done                            \nWriting inode tables: done                            \nCreating journal (16384 blocks): done\nWriting superblocks and filesystem accounting information: done   <\/code><\/pre>\n\n\n\n<p>Verify it by printing the partition table:<\/p>\n\n\n\n<p><strong>$ <code>sudo parted \/dev\/sdb --script print<\/code><\/strong><\/p>\n\n\n\n<p>The output should look something like this:<code>Model:<\/code><\/p>\n\n\n\n<p><code> Kingston DataTraveler 3.0 (scsi) Disk \/dev\/sdb: 15.5GB Sector size (logical\/physical): 512B\/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 15.5GB 15.5GB ext4 primary<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Formatting a USB drive or SD card on Linux is a pretty straight forward process. All you need to do is insert the drive, create a partition table, and format it with FAT32 or your preferred file system.<\/p>\n\n\n\n<p><a href=\"https:\/\/linuxize.com\/post\/how-to-format-usb-sd-card-linux\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before you can use an SD card or USB drive, it needs to be formatted and partitioned. Typically most USB drives and SD cards come preformatted using the FAT file system and do not need to be formatted out of the box. However, in some cases, you may need to format the drive. In Linux, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/19\/how-to-format-usb-drives-and-sd-cards-on-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Format USB Drives and SD Cards on Linux.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-17025","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/17025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=17025"}],"version-history":[{"count":4,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/17025\/revisions"}],"predecessor-version":[{"id":17031,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/17025\/revisions\/17031"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=17025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=17025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=17025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}