Ubuntu - ErikStaats/Notes GitHub Wiki
- How can I tell Ubuntu to do nothing when I close my laptop lid?
- How to format a USB flash drive?
- Virtual console
Insert your USB drive and use lsblk
to find the USB drive device name. In this
example, the device name is "sda
" and there's a partition with the device name
"sda1
".
edee$ lsblk | grep "NAME\|disk\|part"
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.7G 0 disk
└─sda1 8:1 1 28.7G 0 part /media/erikstaats/6E6D-A430
nvme0n1 259:0 0 477G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476.4G 0 part /
edee$
Before formatting the drive, all mountpoints must be unmounted.
edee$ df | grep "Filesystem\|sda"
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 30017184 11872 30005312 1% /media/erikstaats/6E6D-A430
edee$ sudo umount /dev/sda1
edee$
Use dd
with device /dev/sda
to zero out the drive.
edee$ time (sudo dd status=progress if=/dev/zero of=/dev/sda bs=4k && sync)
30742802432 bytes (31 GB, 29 GiB) copied, 1438 s, 21.4 MB/s
dd: error writing '/dev/sda': No space left on device
7507969+0 records in
7507968+0 records out
30752636928 bytes (31 GB, 29 GiB) copied, 1584.72 s, 19.4 MB/s
real 26m24.730s
user 0m3.958s
sys 0m51.733s
edee$
Use fdisk
to create a partition table and add a partition. In this example,
the "o
" command is used to create a DOS partition table.
The "n
" command is used to create a new partition. The default partition
options will create a partition filling the entire storage.
Finally, the "w
" command is used to write the partition table and exit.
edee$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1d7f0292.
Command (m for help): o
Created a new DOS disklabel with disk identifier 0xfcc2488f.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-60063743, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-60063743, default 60063743):
Created a new partition 1 of type 'Linux' and of size 28.7 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
edee$ lsblk | grep "NAME\|disk\|part"
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.7G 0 disk
└─sda1 8:1 1 28.7G 0 part
nvme0n1 259:0 0 477G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476.4G 0 part /
edee$
Use mkfs.vfat
to format the partition for FAT format. Use the "-F 32
" option
to format for FAT32.
edee$ sudo mkfs.vfat -F 32 /dev/sda1
mkfs.fat 4.1 (2017-01-24)
edee$
Use mlabel
to set the drive label.
edee$ sudo mlabel -i /dev/sda1 ::"Eriks Drive"
edee$
Eject, remove, and reinsert the drive.
edee$ sudo eject /dev/sda1
edee$ lsblk | grep "NAME\|disk\|part"
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 28.7G 0 disk
└─sda1 8:1 1 28.7G 0 part /media/erikstaats/ERIKS DRIVE
nvme0n1 259:0 0 477G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476.4G 0 part /
edee$