kobapan@wiLiki
Login
Linux

Linux:USBメモリのフォーマット

デバイスを確認

 $ sudo df
 /dev/sda1 15073280 9322528 5750752 62% /media/ubuntu/4F8E-8F31

アンマウント

 $ sudo umount /dev/sda1

マウントされてないデバイスを確認

 $ sudo fdisk -l
 $ sudo blkid

フォーマット

ラベルを設定する際のオプションは、コマンドのバージョンによって、nだったり、Lだったりするので、それぞれ確認する。

FAT32

数多くのOSで扱うことができる。1つの領域として確保できる容量は最大2テラバイトまで。1ファイルの容量は最大4GBまで。

 $ sudo mkdosfs -F32 -n "USB" /dev/sda1

NTFS

1ファイルの容量最大16TB。Windows以外で書き込む場合は工夫がいる。

 $ sudo mkfs -t ntfs -L usbdisk /dev/sda1

ext3

linuxでしか見れない。1ファイルが4GB以上でも保存できる。32GB以上の領域を1ボリュームとして設定できる。

 $ sudo mkfs.ext3 -L "USB-32GB" /dev/sda1

exFAT

1ファイルの容量最大16GB。Windows、Mac、Linuxでそのまま使える。

Windowsでも読めるように、パーティション設定する。下の例は、DebianのOSを入れてブートさるバックアップ用USBからの設定変更。

 $ sudo parted
 (parted) select /dev/sdc
 Using /dev/sdc
 (parted) print
 Model: ELECOM MF-PKU3 (scsi)
 Disk /dev/sdc: 31.7GB
 Sector size (logical/physical): 512B/512B
 Partition Table: gpt
 Disk Flags: 
 Number  Start   End     Size    File system  Name  Flags
  1      1049kB  537MB   536MB   fat32              boot, esp
  2      537MB   31.6GB  31.1GB
 (parted) set 1 boot off
 (parted) set 1 msftdata on
 (parted) print 
 Model: ELECOM MF-PKU3 (scsi)
 Disk /dev/sdc: 31.7GB
 Sector size (logical/physical): 512B/512B
 Partition Table: gpt
 Disk Flags: 
 Number  Start   End     Size    File system  Name  Flags
  1      1049kB  537MB   536MB   fat32              msftdata
  2      537MB   31.6GB  31.1GB
 (parted) rm 2
 Warning: Partition /dev/sdc1 is being used. Are you sure you want to continue?
 Yes/No?                                                                   
 (parted) resizepart 1 95%
 Warning: Partition /dev/sdc1 is being used. Are you sure you want to continue?
 Yes/No? Yes                                                               
 (parted) print                                                            
 Model: ELECOM MF-PKU3 (scsi)
 Disk /dev/sdc: 31.7GB
 Sector size (logical/physical): 512B/512B
 Partition Table: gpt
 Disk Flags: 
 Number  Start   End     Size    File system  Name  Flags
  1      1049kB  30.1GB  30.1GB                     msftdata
 (parted) quit             

sdc1 というデバイスIDのディスクにDOGUSB32Gというラベルをつけて、フォーマット

 $ sudo mkfs.exfat -n DOGUSB32G /dev/sdc1

確認

 $ sudo blkid

mkfs

実際に呼ばれるコマンドのラッパ

mkfs [options] [-t <filesystem type>] [parameters for the real filesystem builder] <device> [<size>]

実際に呼ばれるコマンド

mkfs.msdos

mkdosfs|mkfs.msdos|mkfs.vfat [ -a ] [ -A ] [ -b sector-of-backup ] [ -c ] [ -l bad-block-file ] [ -C ] [ -f number-of-FATs ] [ -F FAT-size ] [ -h number-of-hidden-sectors ] [ -i volume-id ] [ -I ] [ -m message-file ] [ -n volume-name ] [ -r root-dir-entries ] [ -R number-of-reserved-sectors ] [ -s sectors-per-cluster ] [ -S logical-sector-size ] [ -v ] device [ block-count ]

mkfs.ntfs

mkfs.ntfs|mkntfs -L volume-label ] [ -l ] [ -n ] [ -p part-start-sect ] [ -Q ] [ -q ] [ -S sectors-per-track ] [ -s sector-size ] [ -T ] [ -U ] [ -V ] [ -v ] [ -z mft-zone-multiplier ] [ --debug ] device [ number-of-sectors ]

mkfs.ext3

mkfs.ext3 [-c|-l filename] [-b block-size] [-C cluster-size] [-i bytes-per-inode] [-I inode-size] [-J journal-options] [-G flex-group-size] [-N number-of-inodes] [-m reserved-blocks-percentage] [-o creator-os] [-g blocks-per-group] [-L volume-label] [-M last-mounted-directory] [-O feature[,...]] [-r fs-revision] [-E extended-option[,...]] [-t fs-type] [-T usage-type ] [-U UUID] [-jnqvDFKSV] device [blocks-count]

mkfs.exfat

mkfs.exfat|mkexfatfs [ -i volume-id ] [ -n volume-name ] [ -p partition-first-sector ] [ -s sectors-per-cluster ] [ -V ] device

       -i volume-id
              A 32-bit hexadecimal number. By default a value based on current time is set.
       -n volume-name
              Volume name (label), up to 15 characters. By default no label is set.
       -p partition-first-sector
              First sector of the partition starting from the beginning of the whole disk.  exFAT super block has a field for this value but in fact  it's  optional
              and does not affect anything. Default is 0.
       -s sectors-per-cluster
              Number  of physical sectors per cluster (cluster is an allocation unit in exFAT). Must be a power of 2, i.e. 1, 2, 4, 8, etc. Cluster size can not ex‐
              ceed 32 MB. Default cluster sizes are: 4 KB if volume size is less than 256 MB, 32 KB if volume size is from 256 MB to 32 GB, 128 KB if volume size is
              32 GB or larger.
       -V     Print version and copyright.

Debian
Emacs
Firefox
Gauche
JavaScript
Linux
Scheme
LaTeX
GitHub

More ...