USB stick

Jump to: navigation, search
How to format and manage USB stick (USB drive) for data storage transfer. To make openSUSE installation USB stick, see SDB:Live_USB_stick.

Tested on openSUSE

Recommended articles

Related articles


Choose right file system

USB sticks are usually used for data sharing. To use a USB stick on different systems, you need to choose right file system that can be read and write by all operating systems you might use.

exFAT

exFAT/FAT64 should be your first choice for many reasons:

  1. Supported by Linux, BSD, Windows (Vista and newer) and Mac (10.6.5 and newer)
  2. Supported by most music players and smart TV
  3. Almost unlimited single file size: 16 EiB = 18446744073.71 GB
  4. Optimized for better performance on Flash drive

FAT

FAT/FAT32 is another good choice if your single file size is smaller than 4 GB. It supports wider range of operating systems and devices, especially old systems and devices.

Other

NTFS, the current default Windows file system, is also supported by Linux and Mac but still has some issues. Most electronic devices don't support NTFS by now. So it is not recommended.

XFS, EXT4, BtrFS are only supported by Linux and BSD. Windows and Mac support none of them unless install special drivers. However, if you only work with Linux and BSD, they are totally fine.

XFS is good at large files. It is widely used on modern Linux systems for data storage. However, if you have thousands of small files, the copy/move performance of XFS is not so good.

EXT4 is very old and doesn't support Flash memory as well as newer file systems. But its writing and reading speed is faster than XFS and BtrFS.

BtrFS is the new default Linux file system. It has many amazing features but most of them are not necessary for your USB stick.

Create and format partition

Start YaST Partitioner tool: YaST --> System --> Partitioner

View tree list on the left pannel. In "Hard disks" section, find your USB devices. "sda" is your system hard disk, and it contains partitions "sda1", "sda2", "sda3"... Your USB stick should be "sdb", "sdc", etc. You can recognize by their storage space and device information.

If your USB stick used to be a openSUSE installer, it contains several hidden partition. When you plug it to computer, it won't be recognized as a storage device and you cannot find it on file manager sidebar.

You can delete old partitions on your USB stick and create new one. One single partition is enough for USB sticks and drives.

  1. Choose Primary partition (max. 4 partition) should be enough
  2. Use all space of storage device
  3. Choose Data and independent software as role/usage
  4. Select FAT file system (it is exFAT actually) or whatever you need (see previous section)
  5. Choose Do not mount partition

You can always undo or cancel before clicking "Finish".

If everything is okay, click "Finish" button to execute partitioning actions.

Create and format partition in terminal

You can manage partitions on USB stick with fdisk (or gdisk for GPT partition layout) or parted. "/dev/sdb" is our USB flash drive we will be using in the following sections.

Create partition with fdisk command

Open your terminal and run

# sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.41.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

Next type p to check if there is any partitions

Command (m for help): p
Disk /dev/sdb: 16 GiB, 17179869184 bytes, 33554432 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: 0x510a86c1

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdb1          2048  7815167  7813120  3.7G 83 Linux
/dev/sdb2       7815168 33554431 25739264 12.3G 83 Linux

As you can see there is two partitions (sdb1 and sdb2). If you don't have any partitions, you can just go to Creating new partitions section.

Deleting unnecessary partitions

To delete these partitions, type d

Command (m for help): d
Partition number (1,2, default 2):

And select which partiton you want delete

Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Repeat this until you delete all partitions.

Creating new partition

To create new partition, type n. Next select primary partition type with p, then 1 to create partition number 1 and two time just type Enter to allocate full space of USB flash drive for partition.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-33554431, default 2048): <ENTER> 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-33554431, default 33554431): <ENTER>

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

You can check what will be done before writing the changes in fdisk typing p

Command (m for help): p
Disk /dev/sdb: 16 GiB, 17179869184 bytes, 33554432 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: 0x510a86c1

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 33554431 33552384  16G 83 Linux

If everything is correct just type w to save changes

Command (m for help): w
The partition table has been altered.

You should now have your partiton

# lsblk /dev/sdb
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sdb     259:0    0       16G  0 disk 
`-sdb1  259:1    0       16G  0 part 

Formating partition

FAT32
sudo mkfs.fat -F32 -n <usb-label> /dev/<usb-stick>
-F option in most case are default set to 32 so it can be ommit.

exFAT

Required packages

sudo zypper install exfat-utils fuse-exfat

Then

sudo mkfs.exfat -n <usb-label> /dev/<usb-stick>

NTFS

Required packages

sudo zypper install ntfs-3g ntfsprogs

Then

sudo mkfs.ntfs --quick --label <usb-label> /dev/<usb-stick>
Icon-warning.png
Warning: --quick option is very important ! Without it your USB stick will be formatting very long. All data on USB are going overwriting be zeros. This may also decrease lifetime of your USB flash drive !

EXT4
sudo mkfs.ext4 -L <usb-label> /dev/<usb-stick>

XFS

Required packages

sudo zypper install xfsprogs

Then

sudo mkfs.xfs -L <usb-label> -f /dev/<usb-stick>
Icon-warning.png
Warning: Without -f option mkfs.xfs will not overwrite previous filesystem on that partition.

BtrFS

Required packages (It should be installed by default on OpenSUSE)

sudo zypper install btrfsprogs

Then

sudo mkfs.btrfs -L <usb-label> /dev/<usb-stick>

Change partition label

You can give a partition a meaningful name. If it already has a name but you do not like it, you can change it. USB stick written for openSUSE system installation are usually named like "openSUSE_Leap_42.2-x86_64-DVD". Formating USB stick doesn't change the label. You need some command to rename USB sticks.

FAT/exFAT

If your USB stick use FAT or exFAT:

sudo mlabel -i /dev/sdb1 ::Jimmy_16GB

Change "sdb1" to actual partition name of USB stick. The label cannot be too long. If label contains space, use "\ " instead " " in command.

NTFS

sudo ntfslabel /dev/<usb-stick> <new-label>
To get a label of NTFS partition just type sudo ntfslabel /dev/<usb-stick>

EXT4

sudo e2label /dev/<usb-stick> <new-label>
To get a label of EXT4 parition just type sudo e2label /dev/<usb-stick>

BtrFS

sudo btrfs filesystem label /dev/<usb-stick> <new-label>
To get a label of BtrFS parition just type sudo btrfs filesystem label /dev/<usb-stick>

XFS

sudo xfs_admin -L <new-label> /dev/<usb-stick>
To get a label of XFS parition just type sudo xfs_admin -l /dev/<usb-stick>

External links