30.

fdisk ハードディスクへの操作コマンドの使い方

編集
この記事の要点
  • Linux の fdisk: ハードディスクのパーティション操作コマンド
  • 一覧表示: sudo fdisk -l
  • パーティション編集: sudo fdisk /dev/sdb(n=新規 / d=削除 / p=表示 / w=保存)
  • 2TB 超のディスクは parted / gdisk(GPT 対応)を使う

 

Linuxのfdiskはハードディスクに対する操作を行うことが出来ます。

 

ディスクの詳細情報を表示する

fdisk -l」で詳細情報を表示することが出来ます。

sudo fdisk -l
[sudo] t のパスワード: 
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
...

デバイス   起動 Start 最後から  セクタ  Size Id タイプ
/dev/sda1  *     2048 3907026943 3907024896  1.8T  c W95 FAT32 (LBA)


Disk /dev/sdb: 119.2 GiB, 128035676160 bytes, 250069680 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
Disklabel type: gpt

...


デバイス       Start 最後から セクタ  Size タイプ
/dev/sdb1       2048   2099199   2097152    1G Windows recovery environment
/dev/sdb2    2099200   2303999    204800  100M EFI System
/dev/sdb3    2304000   2566143    262144  128M Microsoft reserved
/dev/sdb4    2566144 153192807 150626664 71.8G Microsoft basic data
/dev/sdb5  192851968 233292280  40440313 19.3G Windows recovery environment
/dev/sdb6  233292281 250069496  16777216    8G Intel Fast Flash
/dev/sdb7  153194496 176228351  23033856   11G Linux filesystem
/dev/sdb8  176228352 192851967  16623616  7.9G Linux スワップ

Partition table entries are not in disk order.
 

 

ディスクの操作

fdisk デバイス名」でデバイスに対して対話型の操作を行うことが出来ます。

sudo fdisk /dev/sdb4

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

コマンド (m でヘルプ): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


コマンド (m でヘルプ): p
Disk /dev/sdb4: 71.8 GiB, 77120851968 bytes, 150626664 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
Disklabel type: dos
...

デバイス    起動      Start 最後から  セクタ   Size Id タイプ
/dev/sdb4p1      1920221984 3736432267 1816210284   866G 72 不明
/dev/sdb4p2      1936028192 3889681299 1953653108 931.6G 6c 不明
/dev/sdb4p3               0          0          0     0B  0 空
/dev/sdb4p4        27722122   27722568        447 223.5K  0 空

Partition table entries are not in disk order.

コマンド (m でヘルプ): d
パーティション番号 (1-4, default 4): 

Partition 4 has been deleted.

コマンド (m でヘルプ): d
パーティション番号 (1-3, default 3): 

Partition 3 has been deleted.

コマンド (m でヘルプ): d
パーティション番号 (1,2, default 2): 

Partition 2 has been deleted.

コマンド (m でヘルプ): d
Selected partition 1
Partition 1 has been deleted

コマンド (m でヘルプ): p

Disk /dev/sdb4: 71.8 GiB, 77120851968 bytes, 150626664 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
Disklabel type: dos
...

コマンド (m でヘルプ): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
パーティション番号 (1-4, default 1): 
First sector (2048-150626663, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-150626663, default 150626663):                 

Created a new partition 1 of type 'Linux' and of size 71.8 GiB.

コマンド (m でヘルプ): p
Disk /dev/sdb4: 71.8 GiB, 77120851968 bytes, 150626664 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
Disklabel type: dos
...

デバイス    起動 Start 最後から セクタ  Size Id タイプ
/dev/sdb4p1       2048 150626663 150624616 71.8G 83 Linux

コマンド (m でヘルプ): t
Selected partition 1
Partition type (type L to list all types): L

 0  空              24  NEC DOS         81  Minix / 古い Li bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux スワップ  c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux 拡張領域  c7  Syrinx         
 5  拡張領域        41  PPC PReP Boot   86  NTFS ボリューム da  非 FS データ   
 6  FAT16           42  SFS             87  NTFS ボリューム db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux プレーン  de  Dell ユーティリ
 8  AIX             4e  QNX4.x 第2パー  8e  Linux LVM       df  BootIt         
 9  AIX 起動可能    4f  QNX4.x 第3パー  93  Amoeba          e1  DOS access     
 a  OS/2 ブートマネ 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad ハ ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
 f  W95 拡張領域 (L 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  隠し FAT12      56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC  
12  Compaq 診断     5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
14  隠し FAT16 <32M 61  SpeedStor       ab  Darwin ブート   f4  SpeedStor      
16  隠し FAT16      63  GNU HURD または af  HFS / HFS+      f2  DOS セカンダリ 
17  隠し HPFS/NTFS  64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18  AST SmartSleep  65  Novell Netware  b8  BSDI スワップ   fc  VMware VMKCORE 
1b  隠し W95 FAT32  70  DiskSecure Mult bb  隠し Boot Wizar fd  Linux raid 自動
1c  隠し W95 FAT32  75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e  隠し W95 FAT16  80  古い Minix      be  Solaris ブート  ff  BBT            
Partition type (type L to list all types): 

Partition type (type L to list all types): 83
Changed type of partition 'Linux' to 'Linux'.

コマンド (m でヘルプ): p
Disk /dev/sdb4: 71.8 GiB, 77120851968 bytes, 150626664 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
Disklabel type: dos
...

デバイス    起動 Start 最後から セクタ  Size Id タイプ
/dev/sdb4p1       2048 150626663 150624616 71.8G 83 Linux

コマンド (m でヘルプ): w
The partition table has been altered.

 

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. ls ファイル/ディレクトリ一覧表示
  2. sudo ユーザー指定
  3. cron/crontab ジョブの自動実行と登録方法
  4. wget http通信によるファイルダウンロード
  5. rm ファイル/ディレクトリ削除
  6. pwd カレントディレクトリの表示
  7. cd ディレクトリの移動
  8. ./configure
  9. make
  10. make install
  11. unzip ファイルの解凍
  12. mv ファイル/ディレクトリの移動および名称変更
  13. mkdir ディレクトリの作成
  14. touch 空ファイルの新規作成
  15. vi テキストディタの使用
  16. find ファイル/ディレクトリ検索
  17. grep 文字列の検索
  18. tail ファイルの末尾表示
  19. curl HTTP通信によるリクエスト
  20. nslookup ドメインのIP解決
  21. apt update パッケージリストの情報を更新
  22. apt upgrade パッケージの更新
  23. ln リンク/ショートカットの作成と削除
  24. rsync ファイル/ディレクトリの同期
  25. ssh リモートとの暗号化通信
  26. scp sshを利用したファイルのコピー
  27. unzip zip ファイルを解凍する
  28. cp ファイル/ディレクトリのコピー
  29. diffファイルの差分抽出
  30. fdisk ハードディスクに対する操作
  31. lsblk デバイスをツリー状で表示する
  32. kill プロセスを終了させる
  33. zip ファイルやディレクトリをzip形式に圧縮する
  34. hostコマンド
  35. chmod 権限の変更
  36. ip IPアドレスの確認
  37. chown コマンド(所有者の変更)
  38. chgrp ファイル/ディレクトリのグループ情報の変更
  39. nohupと'&' プログラムのバックグラウンド実行(ssh接続時)
  40. lsof 開いているポート番号の確認
  41. tar ファイルの圧縮と解凍
  42. file ファイルの種類を表示
  43. cat ファイルの中身を表示
  44. head ファイルの先頭部分を表示
  45. wc 行数/単語数/文字数を確認
  46. shutdown システムのシャットダウンと再起動
  47. ps プロセスの確認
  48. which コマンドの絶対パスを調べる
  49. yum RedHat系ディストリビューションの管理
  50. mount ファイルシステムのマウント
  51. 特定フォルダ以下の特定拡張子のファイルを再帰的に削除する方法
  52. 特定のフォルダとそのサブフォルダ内にある特定のファイル名のファイルを再帰的に削除
  53. sed テキスト処理用ストリームエディタ
  54. awk フィールド単位の柔軟なテキスト処理
  55. sort 行の並び替え
  56. uniq 重複行の除去・カウント
  57. cut 行から特定列を切り出し
  58. tr 文字の置換・削除
  59. less ページャでファイルを読む
  60. more 古典ページャ
  61. xargs 標準入力をコマンド引数に変換
  62. paste 複数ファイルを列方向に結合
  63. top プロセスの動的監視
  64. htop 強化版インタラクティブプロセス監視
  65. nice プロセスの優先度を指定して起動
  66. renice 実行中プロセスの優先度を変更
  67. jobs シェル管理下のジョブ一覧
  68. bg ジョブをバックグラウンドで実行
  69. fg バックグラウンドジョブをフォアグラウンドに
  70. killall プロセス名でまとめて終了
  71. pgrep プロセス名から PID を検索
  72. pkill プロセス名でシグナルを送信
  73. uname システム情報の表示
  74. uptime システム稼働時間とロードアベレージ
  75. free メモリ使用状況の表示
  76. df ディスク使用量 (ファイルシステム単位)
  77. du ディレクトリ・ファイル単位の使用量
  78. lscpu CPU 情報の表示
  79. lsmod 読み込み済みカーネルモジュール一覧
  80. lspci PCI デバイス一覧
  81. dmesg カーネルリングバッファの表示
  82. w ログイン中ユーザーと負荷の表示
  83. ping ホストへの到達性とラウンドトリップ確認
  84. traceroute ホストまでの経路を表示
  85. netstat ネットワーク接続・ルーティング表示 (旧式)
  86. ss netstat 後継、ソケット統計
  87. ifconfig ネットワークインターフェース表示・設定 (旧式)
  88. dig DNS リゾルバ問い合わせの定番
  89. route ルーティングテーブル表示 (旧式)
  90. iptables Linux パケットフィルタリング
  91. telnet TCP 接続診断・古典的リモートログイン
  92. arp ARP テーブルの表示・編集 (旧式)
  93. useradd ユーザーアカウントの作成
  94. usermod 既存ユーザーアカウントの変更
  95. userdel ユーザーアカウントの削除
  96. passwd パスワードの変更・管理
  97. groupadd グループの追加
  98. id ユーザーとグループの ID・所属を表示
  99. whoami 現在のユーザー名を表示
  100. su 別ユーザーに切り替え
  101. dnf Red Hat 系の次世代パッケージマネージャ (yum 後継)
  102. pacman Arch Linux のパッケージマネージャ
  103. echo 文字列・変数の出力
  104. export 環境変数の設定と継承
  105. alias コマンドの別名定義
  106. source / . スクリプトをカレントシェルで実行
  107. history コマンド履歴の表示・操作
  108. type コマンドの種別 (組み込み/関数/エイリアス/外部) を表示
  109. env 環境変数表示と一時設定でコマンド実行
  110. set シェルオプションと位置パラメータの操作
  111. unset 変数・関数の削除
  112. printf C 風書式付き出力
  113. systemctl systemd ユニットの管理
  114. service init.d 互換のサービス管理
  115. journalctl systemd ジャーナルログの参照
  116. crontab 定期実行ジョブの登録・編集
  117. at 指定時刻に 1 回だけコマンド実行
  118. umount ファイルシステムのアンマウント
  119. reboot システムを再起動
  120. halt システムを停止
  121. date 日付・時刻の表示と設定
  122. hostname ホスト名の表示・設定
  123. gzip ファイルを Deflate で圧縮
  124. gunzip gzip 圧縮ファイルの展開
  125. bzip2 高圧縮率の圧縮コマンド
  126. xz LZMA2 ベースの高圧縮コマンド
  127. zstd Facebook 製の高速圧縮コマンド
  128. dpkg Debian パッケージの低レベル操作
  129. rpm Red Hat パッケージの低レベル操作
  130. snap Canonical の sandbox パッケージマネージャ
  131. apt Debian/Ubuntu の高レベルパッケージマネージャ
  132. 7z 7-Zip コマンドラインツール

最近更新/作成されたページ