Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Formatting an SD card/Linux

From Hacks Guide Wiki
< Formatting an SD card
Revision as of 17:50, 31 August 2024 by Doge 2 (talk | contribs) (wip edit, still need to do something about cfdisk and eventually add gui options (gparted, kde partition manager))

This is an add-on section for formatting an SD card to FAT32.

This page is for Linux users only. If you are not on Linux, check out the Windows or Mac pages.

Instructions

  Before beginning these steps, copy all of your SD card's contents to a folder on your computer.
  The commands in this guide are case-sensitive. Enter them exactly as written, or there may be unintended consequences.

  1. Make sure your SD card is not inserted
  2. Open a terminal window and type watch lsblk
  3. Insert the SD card and watch for a new device appearing in lsblk
  4. Observe the output for the new device. It should match something like this:
    NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    mmcblk0     179:0    0 29.7G  0 disk 
    └─mmcblk0p1 179:1    0 29.5G  0 part /run/media/user/FFFF-FFFF
    
  5. Take note of the name of the device that now appears. In our example above, it was mmcblk0, but it could show up as sda or sdb, if you use a USB adapter
    • If RO is set to 1, make sure the lock switch is not slid down
  6. Hit CTRL + C to exit the menu
  7. Type sudo umount /dev/<device name>* (do not replace the *)
  8. Install the fdisk and dosfstools packages using your package manager of choice
  9. Type sudo fdisk /dev/<device name>
  10. Enter o, this will create a new MBR partition scheme
  11. Enter n, then press enter until you're returned to the prompt
    • The default values will work fine for all consoles
  12. Enter t, then enter 0c
  13. Enter a and then p - observe the output, and make sure the device is now formatted correctly:
    Disk /dev/mmcblk0: 29.72 GiB, 31914983424 bytes, 62333952 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: 0x########
    
    Device                Boot  Start      End  Sectors  Size Id Type
    /dev/<partition name>        8192 62333951 62325760 29.7G  c W95 FAT32 (LBA)
    
  14. If there are no issues, enter w - this will save changes and exit the fdisk prompt
  15. Type sudo mkfs.vfat /dev/<partition name> -s 64 to reformat the new partition
    • If the SD card is over 32GB in size, change 64 to 128
  16. Type sudo eject /dev/<device name>, then remove and reinsert the SD card
  17. Copy your data back onto the SD card

  1. Make sure your SD card is not inserted
  2. Open a terminal window and type watch lsblk
  3. Insert the SD card and watch for a new device appearing in lsblk
  4. Observe the output for the new device. It should match something like this:
    NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    mmcblk0     179:0    0 29.7G  0 disk 
    └─mmcblk0p1 179:1    0 29.5G  0 part /run/media/user/FFFF-FFFF
    
  5. Take note of the name of the device that now appears. In our example above, it was mmcblk0, but it could show up as sda or sdb, if you use a USB adapter
    • If RO is set to 1, make sure the lock switch is not slid down
  6. Hit CTRL + C to exit the menu
  7. Install the cfdisk and dosfstools packages using your package manager of choice
  8. Type sudo cfdisk /dev/<device name>
  9. Choose the Delete option and delete any existing partitions
  10. Choose the New option, keep partition size at the recommended size, and choose primary partition type
  11. Choose the Type option, scroll up until you see c W95 FAT32 (LBA) and select it
  12. Finally, choose the Write option.
  13. Choose the Quit option
  14. Type sudo eject /dev/<device name>, then remove and reinsert the SD card
  15. Copy your data back onto the SD card

  1. Make sure your SD card is not inserted
  2. Open a terminal window and type watch lsblk
  3. Insert the SD card and watch for a new device appearing in lsblk
  4. Observe the output for the new device. It should match something like this:
    NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    mmcblk0     179:0    0 29.7G  0 disk 
    └─mmcblk0p1 179:1    0 29.5G  0 part /run/media/user/FFFF-FFFF
    
  5. Take note of the name of the device that now appears. In our example above, it was mmcblk0, but it could show up as sda or sdb, if you use a USB adapter
    • If RO is set to 1, make sure the lock switch is not slid down
  6. Hit CTRL + C to exit the menu
  7. Install the parted and dosfstools packages using your package manager of choice
  8. Type sudo parted /dev/<device name> mklabel msdos
  9. Type sudo parted -a opt /dev/<device name> mkpart primary fat32 0% 100%
  10. Type sudo eject /dev/<device name>, then remove and reinsert the SD card.
  11. Copy your data back onto the SD card.