Beginners Guide: Adding USB Storage, Linux Formatting and Permissions
#2
Question 
Formatting the drive for Linux use

You could use the flash drive right now, as is, but using a windows file system on linux is suboptimal. Instead, we will be making a new partition table and a linux partition. 

Caution: Doing the following will erase all data from the drive. Please make sure you backup any important data on the drive!


Invoke the fdisk command with the drive (sda) as an argument:

Code:
sudo fdisk /dev/sda



Type in "m" and press enter to get an extended menu. 


[Image: uCqBg1I.png]

You have the option to create a new partition table. DOS is the most compatible, but larger(equal or greater than 4TB) devices, GPT is used. For a flash drive, either would suffice. In this case, I will go with a GPT Table. So I type in "g" and hit "enter" 


Code:
Command (m for help): g

Created a new GPT disklabel (GUID: 99E3E866-3783-46DE-9FDA-FE25587DB875).

Now we can add a new partition: Press "n" 

The tool will then ask you to choose the partition number, I chose the default (1).

It then asks you what sector you want the partition to start and end (and how bit it will be by extension). I simply hit "enter' to select the default. 

The tool then confirms that a new partition is created. You can type in "p" to Print out the device and partition information: 


Code:
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-31266782, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-31266782, default 31266782): 

Created a new partition 1 of type 'Linux filesystem' and of size 14.9 GiB.

Command (m for help): p
Disk /dev/sda: 14.9 GiB, 16008609792 bytes, 31266816 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: gpt
Disk identifier: 99E3E866-3783-46DE-9FDA-FE25587DB875

Device     Start      End  Sectors  Size Type
/dev/sda1   2048 31266782 31264735 14.9G Linux filesystem
 


We are almost done making the partition. Type in "w" to write the changes to disk, and hit enter. It will write the changes to disk and exit the tool. You can rescan the device with "sudo fdisk -l /dev/sda" to confirm this. 

[Image: R32YT5D.png]


We now have a partition but its empty! We need to format it with a filesystem. I personally have used ext4 for many years without drama, and thats what I will use in this tutorial, but there is really nothing stopping you from using other filesystems like xfs or btrfs. 


You will need invoke the ext4 filesystem creation tool and tell it to format our newly created partition (/dev/sda1)


Code:
sudo mkfs.ext4 /dev/sda1
  
The filesystem tool might warn you about a prior filesystem, press "y" and hit "enter" to ignore the warning and proceed with the formatting. This warning happens sometimes when you don't completely format a drive before adding a new table and partitions.
It will take a moment and it will verify creation of the filesystem in the partition: 
Code:
rock64@rock64:~$ sudo mkfs.ext4 /dev/sda1 
mke2fs 1.42.13 (17-May-2015)
/dev/sda1 contains a vfat file system
Proceed anyway? (y,n) y
Creating filesystem with 3908091 4k blocks and 977280 inodes
Filesystem UUID: 8ed85af6-dc70-42a5-ba49-c5bdda0a426e
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done  

To confirm creation of the ext4 filesystem on the partition, you can use any of the following commands: 

Code:
lsblk -fs
or 

Code:
sudo parted -l
[Image: DVZZA8p.png]


This shows that you now have a ext4 filesystem on the first (and only) partition of the flash drive.

  Reply


Messages In This Thread
Formatting the drive for Linux use - by Ptheven - 08-15-2017, 08:23 AM
Mounting the Partition/Filesystem - by Ptheven - 08-15-2017, 09:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginners Guide: Migrating to SSD rontant 18 40,329 01-19-2022, 09:30 AM
Last Post: Ellesar Dragon
  Step by step guide PXE diskless configuration. burglar_ot 13 36,062 11-01-2020, 11:26 PM
Last Post: michael.gruner
Thumbs Up A guide for how I made RetroPie, RetroArch, and EmulationStation Work on the Rock64 Mrfixit2001 4 16,211 12-17-2018, 03:52 AM
Last Post: va88
  Guide - XRDP - Debian Stretch / Ubuntu Xenial / OMV S3phi40T 3 14,064 05-05-2018, 06:08 AM
Last Post: S3phi40T
Information Guide - Raid Array (Raid 0) Ptheven 0 4,863 10-07-2017, 09:22 AM
Last Post: Ptheven
Information Guide - Setting up a NFS Share Ptheven 0 5,531 09-26-2017, 04:44 AM
Last Post: Ptheven
  Guide - Setting up a SMB(Windows) file server Ptheven 0 12,659 08-21-2017, 08:54 AM
Last Post: Ptheven
Information Beginners Guide: Locating your board, connecting to it. Ptheven 5 16,047 08-21-2017, 04:12 AM
Last Post: Ptheven

Forum Jump:


Users browsing this thread: 1 Guest(s)