Palm84 某所の日記

死のうは一定、しのびクマには何しよぞ...

最近のLinuxのfdiskコマンドの初期設定のことなど

パッケージやバージョンによっては違いあると思いますンで、あくまで一例でござい。SystemRescueCd 3.7.1 での確認でありんす。

仕様じゃなくて、あくまで default の話。

  1. 表示・指定がシリンダ番号(1から)ではなく、セクタ番地(0から)
  2. 第1パーティション新規作成の offset(開始位置)デフォルトはセクタ2048(従来はHDならセクタ63とか)
  3. offset 8192 のSDカードなどでも offset 2048 がデフォルト(※ 再作成時など注意)
  4. -u=cylinders を指定するとシリンダ数表示
  5. -c=dos 指定で C/H/S 設定表示
  6. -c=dos 指定では offset 63 がデフォルト(H/S 255/63 の場合)

まぁ普通にHDなら問題ないかもですけど。USBメモリやSDカードの場合は注意しといた方がいいかなってかんじです。

下記は SystemRescueCd 3.7.1、4GB microSDHC 及び 16GB USBフラッシュメモリ での確認です。

  • バージョンとヘルプ
root@sysresccd /root % fdisk -v
fdisk from util-linux 2.22.2

root@sysresccd /root % fdisk -h
Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track

4GB microSDHC

  • fdisk -l - 表示がセクタ番地。最近のはほとんどこれかな。
root@sysresccd /root % fdisk -l /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 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
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        8192     7741439     3866624    b  W95 FAT32
  • -u=cylinders でシリンダ番号で表示、-c=dos で C/H/S 設定表示
root@sysresccd /root % fdisk -lu=cylinders -c=dos /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 sectors
128 heads, 63 sectors/track, 960 cylinders
Units = cylinders of 8064 * 512 = 4128768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           2         960     3866624    b  W95 FAT32
  • 普通に fdisk 実行
root@sysresccd /root % dd if=/dev/zero of=/dev/sdb bs=512 count=8194
8194+0 records in
8194+0 records out
4195328 bytes (4.2 MB) copied, 13.3538 s, 314 kB/s

root@sysresccd /root % fdisk /dev/sdb
Welcome to fdisk (util-linux 2.22.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xa144c6af.

Command (m for help): p

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 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
Disk identifier: 0xa144c6af

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-7745535, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-7745535, default 7745535): 
Using default value 7745535
Partition 1 of type Linux and of size 3.7 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 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
Disk identifier: 0xa144c6af

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     7745535     3871744    b  W95 FAT32

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

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
  • デフォルトのままでの実行後の内容はこんなかんじ。Windows 7 と同じ
root@sysresccd /root % fdisk -l /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 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
Disk identifier: 0xa144c6af

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     7745535     3871744    b  W95 FAT32

root@sysresccd /root % fdisk -lu=cylinders -c=dos /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 sectors
122 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 7564 * 512 = 3872768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa144c6af

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1024     3871744    b  W95 FAT32
  • 旧式(DOS形式)指定して実行
root@sysresccd /root % dd if=/dev/zero of=/dev/sdb bs=512 count=2050
2050+0 records in
2050+0 records out
1049600 bytes (1.0 MB) copied, 5.98311 s, 175 kB/s


root@sysresccd /root % fdisk -u=cylinders -c=dos /dev/sdb
Welcome to fdisk (util-linux 2.22.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb8926659.

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (with command 'c').
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.

Command (m for help): p

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 sectors
122 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 7564 * 512 = 3872768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8926659

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First cylinder (1-1024, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1024, default 1024): 
Using default value 1024
Partition 1 of type Linux and of size 3.7 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 sectors
122 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 7564 * 512 = 3872768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8926659

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1024     3872737    b  W95 FAT32

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

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
  • DOS形式指定の内容こんなかんじ。offset は C/H/S のセクタ数に合わせて、シリンダ数が1024以下に。
root@sysresccd /root % fdisk -l /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 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
Disk identifier: 0xb8926659

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          62     7745535     3872737    b  W95 FAT32

root@sysresccd /root % fdisk -lu=cylinders -c=dos /dev/sdb

Disk /dev/sdb: 3965 MB, 3965714432 bytes, 7745536 sectors
122 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 7564 * 512 = 3872768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8926659

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1024     3872737    b  W95 FAT32

16GB USBフラッシュメモリ

  • 普通に fdisk 実行
root@sysresccd /root % dd if=/dev/zero of=/dev/sdc bs=512 count=2050
2050+0 records in
2050+0 records out
1049600 bytes (1.0 MB) copied, 2.55526 s, 411 kB/s

root@sysresccd /root % fdisk /dev/sdc
Welcome to fdisk (util-linux 2.22.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6dd6ecfc.

Command (m for help): p

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 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
Disk identifier: 0x6dd6ecfc

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-31405823, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31405823, default 31405823): 
Using default value 31405823
Partition 1 of type Linux and of size 15 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 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
Disk identifier: 0x6dd6ecfc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048    31405823    15701888    c  W95 FAT32 (LBA)

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

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
  • デフォルトのままでの実行後の内容はこんなかんじ。Windows 7 と同じ
root@sysresccd /root % fdisk -l /dev/sdc

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 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
Disk identifier: 0x6dd6ecfc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *        2048    31405823    15701888    c  W95 FAT32 (LBA)

root@sysresccd /root % fdisk -l -u=cylinders -c=dos /dev/sdc        

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 sectors
56 heads, 32 sectors/track, 15334 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6dd6ecfc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           2       15335    15701888    c  W95 FAT32 (LBA)
  • 旧式(DOS形式)指定して実行
root@sysresccd /root % dd if=/dev/zero of=/dev/sdc bs=512 count=2050
2050+0 records in
2050+0 records out
1049600 bytes (1.0 MB) copied, 3.54364 s, 296 kB/s

root@sysresccd /root % fdisk -u=cylinders -c=dos /dev/sdc
Welcome to fdisk (util-linux 2.22.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd8682994.

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (with command 'c').
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.

Command (m for help): p

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 sectors
64 heads, 32 sectors/track, 15334 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd8682994

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
Using default value 1
First cylinder (1-15334, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-15334, default 15334): 
Using default value 15334
Partition 1 of type Linux and of size 15 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 sectors
64 heads, 32 sectors/track, 15334 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd8682994

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1       15334    15702000    c  W95 FAT32 (LBA)

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

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
  • DOS形式指定の内容こんなかんじ。offset は C/H/S のセクタ数に合わせて、H/S が 64/32、シリンダ数は1024以下にならない
root@sysresccd /root % fdisk -l /dev/sdc                            

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 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
Disk identifier: 0xd8682994

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *          32    31404031    15702000    c  W95 FAT32 (LBA)

root@sysresccd /root % fdisk -l -u=cylinders -c=dos /dev/sdc

Disk /dev/sdc: 16.1 GB, 16079781888 bytes, 31405824 sectors
64 heads, 32 sectors/track, 15334 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd8682994

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1       15334    15702000    c  W95 FAT32 (LBA)

※ 旧式指定で 160GB HD(イメージ)の場合は offset 63(H/S 255/63) となってました。

いわゆるオサーンの「レガシー」な話でありますた。orz

ほなねん