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:
Type in "m" and press enter to get an extended menu.
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"
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:
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.
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)
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:
To confirm creation of the ext4 filesystem on the partition, you can use any of the following commands:
or
This shows that you now have a ext4 filesystem on the first (and only) partition of the flash drive.
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.
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.
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
Code:
sudo parted -l
This shows that you now have a ext4 filesystem on the first (and only) partition of the flash drive.