USBメモリのext2フォーマット

USBフラッシュメモリ安いですね〜
1GBが2980円ですよ。勿論メーカにもよるんだけどね。
昔64MBで6000円とかしてた気がしたけど。
昨日、近くのPCショップでUSBメモリを買って、そんなことを思いました。


Linuxのみで使用する予定なのでフォーマットの練習を兼ねてext2でフォーマットをしてみようと思いました。
# 事後に、書いてるのでコマンド実行結果は全部載せてません。


とりあえずマウントする前に

# fdisk -l

ファイルシステムを確認すると、FAT16でフォーマットされてました。

# fdisk /dev/sda1

			------------snip------------

Command (m for help): p

			------------snip------------

2つのパーティションに分かれてました。(ような気がする)

Command (m for help): d

を使ってパーティションを全部消しました。
一応確認のために

Command (m for help): p

			------------snip------------

     Device Boot      Start         End      Blocks   Id  System

Command (m for help):

パーティション消えてます。

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1015, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1015, default 1015): 
Using default value 1015

Command (m for help): p

Disk /dev/sda1: 1015 MB, 1015005184 bytes
32 heads, 61 sectors/track, 1015 cylinders
Units = cylinders of 1952 * 512 = 999424 bytes

     Device Boot      Start         End      Blocks   Id  System
/dev/sda1p1               1        1015      990609+  83  Linux

Command (m for help): 

1GBフルサイズでext2用のパーティションを作成しました。

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

なんか途中でエラー出てますけど。


とりあえずフォーマット。

# mkfs -t ext2 -L labfiles /dev/sda1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=labfiles
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
123904 inodes, 247804 blocks
12390 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=255852544
8 block groups
32768 blocks per group, 32768 fragments per group
15488 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


さてfdiskでファイルシステムを見てみましょう。

# fdisk -l          
			------------snip------------

Disk /dev/sda: 1015 MB, 1015021568 bytes
33 heads, 63 sectors/track, 953 cylinders
Units = cylinders of 2079 * 512 = 1064448 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         954      991216    6  FAT16
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 1, 1) logical=(0, 0, 33)
Partition 1 has different physical/logical endings:
     phys=(215, 32, 63) logical=(953, 18, 43)

あれ?FAT16?でも、引数としてUSBメモリのデバイスファイルをあたえてやると

# fdisk -l /dev/sda1

Disk /dev/sda1: 1015 MB, 1015005184 bytes
32 heads, 61 sectors/track, 1015 cylinders
Units = cylinders of 1952 * 512 = 999424 bytes

     Device Boot      Start         End      Blocks   Id  System
/dev/sda1p1               1        1015      990609+  83  Linux

となってLinuxで認識してる。これext2のことだよね?
なんでこういう違いがでるんでしょう。


さらにマウントしてみると、

# mount -t auto /dev/sda1 /mnt/flash/
# df -T /mnt/flash/
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext2      975624      1224    924840   1% /mnt/flash

ext2になってる。
Windowsでも使えるようなUSBメモリ(これは多分FAT16)だとautoオプションでvfatが選択されますが、このファイルシステムだとautoがext2に展開される。
ちゃんとext2にフォーマットされてるようだ。
なんでFAT16の表示になるんだろう。。。
分からん。。。


とりあえずは使えてます。
# 実は最初は、mkfsでext2にすること自体できなかったがmkfs -cでブロックチェックしたらできた


[reference]
http://collie.low-temp.sci.yamaguchi-u.ac.jp/~ashida/comp/usbhdd.html
http://www.math.kobe-u.ac.jp/~kodama/tips-USB-floppy.html
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/750chkfstype.html
http://lists.debian.or.jp/debian-users/200204/msg00103.html
http://ozlabs.org/pipermail/linuxppc-embedded/2003-May/011068.html