FAT

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page FAT and the translation is 34% complete.
Outdated translations are marked like this.
Other languages:
Resources

File Allocation Table (FAT)файловая система, использовавшаяся в MS-DOS (и последующих версиях Microsoft Windows до NT). Последние ревизии FAT (FAT32) используются в USB-накопителях[1]. В Linux имеет собственную реализацию и полностью поддерживается ядром Linux.

Хотя в FAT32 отсутствует множество возможностей, присущих современным файловым системам, применение этой файловой системы до сих пор можно найти в современных компьютерах, например, при использовании EFI System Partition. В 2006 году Microsoft разработала новую версию FAT (exFAT), которая обратно не совместима с предыдущей версией. См. статью exFAT для дальнейшей информации.

Установка

Ядро

ЯДРО Включение поддержки FAT (CONFIG_VFAT_FS)
File systems  --->
   DOS/FAT/NT Filesystems  --->
      < > MSDOS fs support
      <*> VFAT (Windows-95) fs support
      (437) Default codepage for FAT
      (iso8859-1) Default iocharset for FAT
      [ ]   Enable FAT UTF-8 option by default
   -*- Native language support  --->
      (iso8859-1) Default NLS Option
      <*>   Codepage 437 (United States, Canada)
      <*>   NLS ISO 8859-1  (Latin 1; Western European Languages)
      -*-   NLS UTF-8

Snippet

ФАЙЛ /etc/kernel/config.d/esp-linux6-1-111.config
CONFIG_FAT_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
CONFIG_FAT_DEFAULT_CODEPAGE=437
CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"

При монтировании разделов FAT может потребоваться указывать параметр codepage=. В примере выше используется кодовая страница для США и Канады, однако в случае необходимости можно использовать и другие. Также пользователи могут указать кодовую страницу по умолчанию для FAT в конфигурации ядра. Убедитесь, что в ядре включены все кодовые страницы, которые планируются использоваться.

Заметка
Помните, что параметр codepage, указанный вместе с командой mount, будет иметь приоритет над настройками ядра.

Не устанавливайте Default iocharset for fat в UTF-8, так как это не рекомендуется. Вместо этого укажите параметр utf8=true при монтировании раздела FAT (для этого необходим параметр ядра CONFIG_NLS_UTF8). Для более детальной информации смотрите man-страницу mount(8) и соответствующую документацию ядра, расположенную в /usr/src/linux/Documentation/filesystems/vfat.rst.

Установка

Необходимо установить пакет sys-fs/dosfstools для пользовательских утилит FAT:

root #emerge --ask sys-fs/dosfstools

Использование

Форматирование

Используйте mkfs.fat для создания создания файловой системы FAT:

user $mkfs.fat
mkfs.fat 4.2 (2021-01-31)
No device specified.
Usage: mkfs.fat [OPTIONS] TARGET [BLOCKS]
Create FAT filesystem in TARGET, which can be a block device or file. Use only
up to BLOCKS 1024 byte blocks if specified. With the -C option, file TARGET will be
created with a size of 1024 bytes times BLOCKS, which must be specified.
 
Options:
  -a              Disable alignment of data structures
  -A              Toggle Atari variant of the filesystem
  -b SECTOR       Select SECTOR as location of the FAT32 backup boot sector
  -c              Check device for bad blocks before creating the filesystem
  -C              Create file TARGET then create filesystem in it
  -D NUMBER       Write BIOS drive number NUMBER to boot sector
  -f COUNT        Create COUNT file allocation tables
  -F SIZE         Select FAT size SIZE (12, 16 or 32)
  -g GEOM         Select disk geometry: heads/sectors_per_track
  -h NUMBER       Write hidden sectors NUMBER to boot sector
  -i VOLID        Set volume ID to VOLID (a 32 bit hexadecimal number)
  -I              Ignore and disable safety checks
  -l FILENAME     Read bad blocks list from FILENAME
  -m FILENAME     Replace default error message in boot block with contents of FILENAME
  -M TYPE         Set media type in boot sector to TYPE
  --mbr[=y|n|a]   Fill (fake) MBR table with one partition which spans whole disk
  -n LABEL        Set volume name to LABEL (up to 11 characters long)
  --codepage=N    use DOS codepage N to encode label (default: 850)
  -r COUNT        Make room for at least COUNT entries in the root directory
  -R COUNT        Set minimal number of reserved sectors to COUNT
  -s COUNT        Set number of sectors per cluster to COUNT
  -S SIZE         Select a sector size of SIZE (a power of two, at least 512)
  -v              Verbose execution
  --variant=TYPE  Select variant TYPE of filesystem (standard or Atari)
  --invariant     Use constants for randomly generated or time based values
  --offset=SECTOR Write the filesystem at a specific sector into the device file.
  --help          Show this help message and exit

Форматирование раздела /dev/sdx9 в файловую систему FAT32 с меткой «ESP» и подробным выводом:

root #mkfs.fat -v -F 32 -n "ESP" /dev/sdx9

Файловые системы FAT можно монтировать командой mount. Изменять размер файловой системы можно с помощью sys-fs/fatresize.

Case sensitivity

In the original FAT file system only short filenames (8.3 or SFN) are possible, and they are being stored in all upper case only. The systems using the original FAT file system were not case-sensitive (like MS-DOS). As extension to FAT, VFAT not only allows long filenames (LFN) but also lower case letters in filenames. VFAT is case-preserving, but for compatibility reasons existing operating systems (such as Microsoft Windows 95 and Windows NT) were still treating filenames case-insensitive. On the other hand, Unix traditionally was strictly case-sensitive.

In Linux vfat defaults to treating names case-insensitive (mount option check=r for relaxed). VFAT can, however, also be mounted with strict case-checking, mount option check=s, but this can cause problems.

Manual mount options

Предупреждение
Using anything other than the default options will cause problems! You have been warned! See section Problem cases for details.

For short names of directories and files (8.3, i.e. "short filenames" or SFN) the behavior of how the name is stored in the filesystem and how it is displayed can be changed using mount option shortname, which defaults to mixed since Linux kernel 2.6.32 (December 2009).[2]

file system mount option display short name short name example store long name long name example
FAT12
FAT16
FAT32
VFAT
FILENAME.EXT
shortname=lower always forced to lower case filename.ext when the short name is not all upper case
shortname=win95 upper case FILENAME.EXT when the short name is not all upper case
shortname=winnt as is (original) FILENAME.EXT when the short name is not all lower case or all upper case
shortname=mixed as is (original) FILENAME.EXT when the short name is not all upper case
VFAT FILENA~1.EXT FileName.Ext
shortname=lower always forced to lower case when the short name is not all upper case FileName.Ext
shortname=win95 upper case when the short name is not all upper case FileName.Ext
shortname=winnt as is (original) when the short name is not all lower case or all upper case FileName.Ext
shortname=mixed as is (original) when the short name is not all upper case FileName.Ext
VFAT LONGNA~1.EXT long name.ext
shortname=lower always forced to lower case when the short name is not all upper case long name.ext
shortname=win95 upper case when the short name is not all upper case long name.ext
shortname=winnt as is (original) when the short name is not all lower case or all upper case long name.ext
shortname=mixed as is (original) when the short name is not all upper case long name.ext

A special case is an all lower case short filename, e.g. filename.ext. If it is created with shortname=winnt, no LFN VFAT entry will be created.

file system mount option store long name long name example display short name short name example
VFAT filename.ext FILENAME.EXT
shortname=winnt when the short name is not all lower case or all upper case as is (short name) FILENAME.EXT
shortname=lower always forced to lower case filename.ext
shortname=win95 upper case FILENAME.EXT
shortname=mixed as is FILENAME.EXT

If the file is created with shortname=lower|win95|mixed however, there will be a VFAT entry (LFN) and a short filename as well, e.g. FILENA~2.EXT. Whenever there is an LFN, VFAT will display the LFN, not the SFN. This is particularly tricky since the LFN entry might look like an 8.3 SFN, as in the example filename.ext.

file system mount option long name example display short name short name example
VFAT filename.ext FILENA~2.EXT
shortname=lower filename.ext lower case
shortname=win95 filename.ext upper case
shortname=winnt filename.ext as is
shortname=mixed filename.ext as is ~

Problem cases

With the default settings existing file systems will just work.[3] Firstly, VFAT currently defaults to relaxed case-checking (mount option check=r). This means that names for directories and files below the mount point will always work as long as they otherwise match in any possible combination of upper and lower case spelling, e.g. filename.ext will be found even when e.g. FILENAME.EXT or FileName.Ext is actually present, because the difference is only in case.

And secondly, short names (8.3, SFN) that are not all upper case will get an additional long filename entry to store the case correctly i.e. making VFAT case-preserving (mount option shortname=mixed).

Важно
On platforms with UEFI this is especially important for compatibility with existing directories and files on the EFI System Partition (ESP), which is vital for the boot configuration. Systems using FAT and VFAT traditionally haven't been case-sensitive, hence it is to be expected that existing directories and filenames differ slightly in their use of upper and lower case letters. With the default settings for vfat, Linux is adapting to this convention and treats the whole mount point case-insensitive as well, i.e. /efi/EFI/boot/bootx64.efi (assuming the ESP is mounted under /efi) and other EFI bootloader paths will always work as expected.

If only Linux is installed and all file references remain exactly the same, everything should also work with strict case-checking (mount option check=s). However, since the VFAT file system stores two filenames in some but not all cases, one short (8.3, SFN) and one long name (LFN), conventions regarding the management of those names can cause additional problems. The obvious example is the use of shortname=winnt, which will convert a short filename in all lower case to a standard FAT filename in all upper case, and skip creating an LFN counterpart. For example, the filename bootx64.efi would be stored as traditional 8.3 short filename (SFN) BOOTX64.EFI only. Additionally, shortname=winnt will display short filenames as is, so the originally written bootx64.efi doesn't exist, and together with strict case-checking this will cause big problems under Linux.

Устранение проблем

Медленная скорость копирования файлов

If file transfer speeds are slow (can be viewed using iotop), ensure the filesystem is mounted with the async filesystem option. Edit /etc/fstab (or /etc/autofs/auto.misc when using autofs) system files as needed, likely removing the sync mount option. By default, filesystems are mounted using the async mount option.

Заметка
The filesystem sync mount option inhibits slower transfer speeds than the default async mount option. The sync mount option may cause flash media life-cycle shortening also! See man mount option sync explanation.

If file transfer speeds are still slow, try remounting the filesystem with the flush mount option:

root #mount -o remount,flush /path/to/mountpoint

Alternative operating system compatible filesystems

Try UDF filesystem using UDFTools, requiring sys-fs/udftools and Linux kernel UDF filesystem driver. Recently code was added to mkudffs for a fix for creating a mock partition increasing compatibility with Microsoft related operating systems. If using an older Linux kernel, ensure block size is set to 512 for increased compatibility. Most options are now default for compatibility, except for the required --bootarea=mbr creating the mock partition.

root #mkudffs --bootarea=mbr --label=your_label /dev/device_file

Попробуйте файловую систему F2FS от Samsung.

Аппаратные ошибки реализации символов UTF-8/UTF-16

Sometimes hardware firmware bugs will occur on embedded devices (eg. car radios) when reading their required formatted FAT/FAT32 filesystems containing UTF-8 characters. A workaround is to ensure initially mounting the FAT filesystem using (current default) mount options codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro.

For short filenames, codepage=437 is IBM-PC characters or basically ASCII. For long filenames, iocharset=iso8859-1 specifies ASCII. The option shortname=mixed is default, and can also try shortname=win95 option. Of which, are all current defaults. Additionally to further remedy UTF-8/UTF-16 incompatible characters, use a loop with sed to replace all incompatible UTF-8/UTF-16 characters with an underscore or other ASCII character. (See this replace_chars.sh script.)

For reference, this bug was encountered with a Sony car radio. The MEX-GS610BT radio model would hard reset upon attempting to read a USB flash media/drive containing UTF-8/UTF-16 characters.

As mentioned previously, see /usr/src/linux/Documentation/filesystems/vfat.txt, the Linux Kernel vfat source code documentation, for further explanation on whether to use codepage, iocharset, or utf8 mount options.

Unsorted files and folders

When writing files to the FAT/FAT32 filesystem, devices used for reading the filesystem may show the files and folders as unsorted. Commonly, viewer prefer seeing files and folders sorted alphabetically. Install sys-fs/fatsort, and issue the following command:

root #fatsort /dev/device_file

Смотрите также

  • ExFAT — файловая система от Microsoft, оптимизированная для устройств хранения данных, основанных на памяти flash
  • ext4 — дисковая файловая система с открытым исходным кодом, и самая последняя версия серии «расширенных файловых систем».
  • btrfs — copy-on-write (CoW, копирование при записи) файловая система для Linux, предназначенная для реализации расширенных возможностей, в то же время уделяя особое внимание отказоустойчивости, самовосстановлению и простоте администрирования.
  • removable media — any media that is easily removed from a system.
  • /etc/fstab — файл конфигурации, который определяет, как и когда должны подключаться основные файловые системы, особенно во время загрузки.

Внешние ресурсы

Ссылки