Advertisement
efxtv

Formatting a USB flash drive for in Linux using the command line interface (CLI)

Nov 13th, 2024 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | Cybersecurity | 0 0
  1. Formatting a USB flash drive for in Linux using the command line interface (CLI):
  2.  
  3. # How to Format a USB Flash Drive for Windows and Linux in CLI
  4.  
  5. # Check the List of Drives and Partitions (List All Block Devices)
  6. lsblk
  7.  
  8. Note: Identify the correct disk carefully by its size. Selecting the incorrect disk may result in data loss.
  9.  
  10. In my case, the target disk is:
  11. - sdb (Disk MOUNT)
  12. - sda1 (Partition MOUNT
  13.  
  14. # List Selected Disk and Partitions (Disk on the First Line, Partitions Below)
  15. lsblk -fp /dev/sda
  16.  
  17. # Before Formatting the Disk, First Unmount It from the Linux Machine
  18. sudo umount /dev/sda1
  19.  
  20. # Wipe Data from /dev/sda (All Partitions Will Be Deleted)
  21. sudo wipefs -a /dev/sda
  22.  
  23. # Check the Disk and Observe that the Partition Table Should Be Deleted
  24. sudo fdisk -l /dev/sda
  25.  
  26. # Create a Partition from Unallocated Space
  27. sudo cfdisk /dev/sda
  28.  
  29. - Choose label type as DOS
  30. - Select New > Enter
  31. - Choose Primary > Enter
  32. - Select Type > Enter > Choose c W95 FAT32 (LBA) > Enter
  33. - Select Write > Enter > Type Yes > Enter
  34. - Select Quit
  35.  
  36. # Check the Flash Drive for File System (No Partition Created Yet)
  37. sudo fdisk -l /dev/sda
  38.  
  39. # Format the Disk Partition with FAT32 File System (To Create the Partition)
  40. sudo mkfs.vfat -n "USBFAT32" /dev/sda1
  41.  
  42. # Check the File System of the Disk with Partition 1
  43. lsblk -fp /dev/sda
  44.  
  45. # Format with NTFS File System
  46. sudo mkntfs -Q -L "USBNTFS" /dev/sdb1
  47.  
  48. # Format with ext4 (Linux-Based) File System
  49. sudo mkfs.ext4 -L "USBEXT4" /dev/sdb1
  50.  
  51. # Change the File System to Windows Compatible (FAT32)
  52. sudo mkfs.vfat -n "USBFAT32" /dev/sdb1
  53.  
  54. # Eject the Flash Drive
  55. sudo eject /dev/sdb
  56.  
  57. options used in the commands:
  58. -n: Sets the volume label for the filesystem being created.
  59. -L: Specifies the label for the filesystem (used with mkfs commands).
  60. -Q: Performs a quick format (used with NTFS formatting).
  61. -a: Wipes all filesystem signatures from the specified device (used with wipefs).
  62. -l: Lists partition tables and details (used with fdisk).
  63. -f: Forces the operation (used with lsblk to show more details).
  64. -p: Prints the UUIDs and labels of the partitions (used with lsblk).
  65.  
  66. Download the file here https://t.me/c/1480784123/2509/3953
  67. Admin at t.me/efxtv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement