User Tools

Site Tools


formatting

If you want to send us your comments, please do so. Thanks
More on comments


Formatting

Partitions and filesystmes

Before you can format a partition it needs to exist. See these pages for more information
See Partitions
See Filesystem on how to set up an new / empty harddisk and the partitions
See Check filesystem on how to check and repair a filesystem

Check ext4 filesystem

fsck -C -r -t ext4 -l -V /dev/sdxn

Check for bad blocks (do not use the badblocks command, use e2fsck, see the Important note: on the badblocks man page)

e2fsck -c -c -f -C 0 -v /dev/sdxn

-c -c does a read write test. Do not do this on SSD's. Then only use one -c
-C 0 shows the progress. 0 is the file descriptor

Ext4 without journal

Advantages

  • Avoids writing to the journal on the drive when used on an SSD
  • Saves harddisk space. Initially very little. On a 2TB drive about 0.12 GB
  • Might speed up write actions since the journal doesn't have to be written

mkfs.ext4 commands

mkfs optionFunctionRemark
-vverbose
-ccheck for bad blocks. Read only test. This can take a long time
-c -ccheck for bad blocks. Read write test. This can take a long time. About four times as long as with a single -c
-FForce mke2fs to create a file system
-Iadd this option if partitioning does not work
-t fs-typeSpecify the filesystem type (i.e., ext2, ext3, ext4, etc.) that is to be created.
-L labelnamelabel
-mreserved-blocks-percentageDefault is 5%. Lowering this value saves space. This can come handy when using a drive just as backup. The value can also be a fraction of a percent like 0.2% (values are rounded down to on decimal after the point)
-nSee what would be done without doing it
-Nnumber-of-inodes
-O feature[,…]Create a filesystem with the given features (filesystem options), overriding the default filesystem options
-O ^64bitCreate a 32 bit filesystem. This can avoid boot issues
-O has_journalfeature: Create an ext3 journal (as if using the -j option). Maybe the manpage needs an update for ext4
-O extentfeature: extents is a much more efficient encoding which speeds up filesystem access, especially for large files
^feature: To disable a feature, simply prefix the feature name with a caret (^) character
deviceThe device to be formatted like /dev/sdx

Format with mkfs.ext4

Make sure the device is unmounted

mkfs.ext4 -v -c -O extent -O has_journal -t ext4 -L new-volume-label /dev/sdx1

After formatting journaling can be disabled with

tune2fs -O ^has_journal /dev/sdx

Errors

mkfs.ext4: invalid blocks '/dev/sdx' on device 'Drivelabel'

Probable causes

  • A partition table needs to be made on the drive.
  • An empty partition needs to be made
  • The partition type has to be set to something like ext4

Format a partition with ext2

mkfs.ext2 -L new-volume-label /dev/sdx1

Options that might be usefull. In the example below space is saved in case there will be only large files on the harddisk

CommandExample
-L new-volume-label-L Debian9
-m reserved-blocks-percentage-m 0.1
-N number-of-inodes-N 100
-T usage-type[,…]-T largefile
-v verbose-v
mkfs.ext2 -L TheLabel -N 100 -T largefile -m 0.1 /dev/sdx1

Source: Formatting an ext2/3 partition and the mkfs.ext2 man page

FAT filesystem

mkdosfs, mkfs.fat, mkfs.msdos and mkfs.vfat are the same program

Check vfat filesystem

Some options of dosfsck

-aAutomatically repair the filesystem
-lList path names of files being processed
-rInteractively repair the filesystem
-tMark unreadable clusters as bad
-vVerbose mode
-VPerform a verification pass
-wWrite changes to disk immediately

Example:

dosfsck -w -r -l -a -v -V -t /dev/sdxn

VFAT number of files

The rootfolder kan hold 512 files with a 8.3 (characters) filename. If long filenames are used this number is reduced
Sub-directories do not have this limitation
See What is the difference between vfat and fat32 file systems for more information

Format an USBdrive with fat32

Do

CommandRemark
umound [path to the moudted drive]Unmount the USBdrive
fdisk -l
dosfsck -vV /dev/sdxnCheck the filesystem, verbose and verification
mkdosfs -F 32 -n TheLabel -v -I /dev/driveFormat the drive

Example:

mkdosfs -F 32 -n TheLabel -v -I /dev/sdd

When running Windows

you can use GRC's Initdisk

Format an USBdrive with ntfs

Unmount the USBdrive

fdisk -l
e2fsck -c -c -f -C 0 /dev/sdxn (Check for bad blocks)
dosfsck -vV /dev/sdxn (check the filesystem, verbose and verification)
mkntfs --fast --label TheVolumeLabelOfYourChoice --verbose /dev/sdx1

Example:

mkntfs --fast --label Thelabel --verbose /dev/sdd1

Mount with (with only ntfs an Input/output error can occur)

mount -t ntfs-3g /dev/sdx1 /mnt/mountpoint/

For mount errors see Mount

SDcard

Do as root

Format with ext4

mkfs -t ext4 /dev/sdx1

Format with the FAT filesystem

Choose -F 32 for SDcards larger that 1GB

mkdosfs -v -c -F 16 -I -n DRIVELABEL /dev/sdx1

Remove the card and reinsert it.
Check with blkid if the card is detected by the system.
Mount it and check if you can write and read it.

Format with ExFAT

Over ExFAT

Some options
--boundary-align=alignment Important, see manpage
--cluster-size=size Important, see manpage
--full-format Zeros the entire disk device while creating the exFAT filesystem
--volume-label=label
--verbose
As root do for a 16 GB SDcard

mkfs.exfat --boundary-align=4MiB --cluster-size=32kiB --volume-label=LABEL --verbose /dev/sdxn

Diskette

Do, as root:

CommandRemark
umound [path to the moudted diskttte]Unmount the diskette
fdisk -lCheck if the diskette drive is present
dosfsck -vV /dev/sdxCheck the filesystem, verbose and verification
mkdosfs -F 12 -n THELABEL -v /dev/sdxFormat the drive. Only use capital letters for the label

Example:

mkdosfs -F 12 -n THELABEL -v /dev/sdX

Superfloppy

A superfloppy is a removable medium with no MBR nor GPT. The entire medium is treated as a single partition
Examples:

  • Floppy disk drives
  • CD-ROM
  • DVD-ROM

Read and change the label

Do as root

ext2/ext3/ext4 partitions

Show the label

e2label /dev/sdx5

Set a new label

e2label /dev/sdx2 TheNewLabel

vfat partitions

The program can be found in the Dosfstools package Show the label

dosfslabel /dev/sdx

Set a new label

dosfslabel /dev/sdx TheNewLabel

Or use

fatlabel /dev/sdb TheNewLabel
fatlabel -i /dev/sdb

Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
formatting.txt · Last modified: 14-02-2024 19:04 by wim