Linux での HDD のフォーマット

たぶん厳密にはLinuxではディスクのフォーマットとは言わないのだと思うが、「パーティションつくってファイルシステムをつくる」は長いので。

新しいデバイスの特定

新しいディスクを接続したら、まずはどのデバイスかを特定する。

たいていは /dev/sdX (Xa,b,...など)になっているから

ls /dev/sd*

とすれば、数字がないデバイスがあるはず。数字がないのはパーティションが存在しないから。これが新しいディスクの判別になる。

ちなみに物理的なディスクと /dev/sda, /dev/sdbとかいう紐づけはいつも同じとは限らない。たとえばマザーボードのポートを入れ替えれば変わる。

 ls /dev/sd*
/dev/sda /dev/sdb /dev/sdc /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdf5 /dev/sdg1 /dev/sda1 /dev/sdb1 /dev/sdd /dev/sde /dev/sdf /dev/sdf2 /dev/sdg

パーティションを作成する

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.9 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries in memory.
Command (? for help): p
Disk /dev/sdc: 7814037168 sectors, 3.6 TiB Model: WDC WD40EZAX-00C Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): 56D311FC-40F6-4595-A1EF-F22475078708 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 7814037134 Partitions will be aligned on 2048-sector boundaries Total free space is 7814037101 sectors (3.6 TiB) Number Start (sector) End (sector) Size Code Name
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y Command (? for help): p
Disk /dev/sdc: 7814037168 sectors, 3.6 TiB Model: WDC WD40EZAX-00C Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): 1B330559-0C65-4A25-A4BD-1D27D0A8199F Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 7814037134 Partitions will be aligned on 2048-sector boundaries Total free space is 7814037101 sectors (3.6 TiB) Number Start (sector) End (sector) Size Code Name
Command (? for help): n
Partition number (1-128, default 1): 1 First sector (34-7814037134, default = 2048) or {+-}size{KMGTP}: Last sector (2048-7814037134, default = 7814035455) or {+-}size{KMGTP}: Current type is 8300 (Linux filesystem)
Command (? for help): p
Disk /dev/sdc: 7814037168 sectors, 3.6 TiB Model: WDC WD40EZAX-00C Sector size (logical/physical): 512/4096 bytes Disk identifier (GUID): 1B330559-0C65-4A25-A4BD-1D27D0A8199F Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 7814037134 Partitions will be aligned on 2048-sector boundaries Total free space is 3693 sectors (1.8 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 7814035455 3.6 TiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc. The operation has completed successfully.

確認するとこんな感じ:

$ ls /dev/sdc*
/dev/sdc /dev/sdc1

ファイルシステムを作成する

$ sudo mkfs.ext4 /dev/sdc1
mke2fs 1.47.0 (5-Feb-2023) Creating filesystem with 976754176 4k blocks and 244195328 inodes Filesystem UUID: 50431c6a-4b22-47c9-a1f6-f1396a6cbee9 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544 Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done

Adsense広告