ピナクルのくるくるパソコン術

みんなが使えるパソコン術を提供します。

【Ubuntu】外付けHDDの接続・フォーマット


Linuxでの外付けHDDの接続・フォーマット方法を記載します。

* 手順

  1. 外付けHDDを挿入し、デバイスファイルを確認する

    外付けHDDを挿入するとデバイスファイルが作成されるので、
    dmesgコマンドで作成されたデバイスファイルを確認します。

    [  243.716956] usb-storage 1-1.3:1.0: USB Mass Storage device detected
    [  243.717805] scsi host0: usb-storage 1-1.3:1.0
    [  243.718366] usbcore: registered new interface driver usb-storage
    [  243.730245] usbcore: registered new interface driver uas
    [  244.737224] scsi 0:0:0:0: Direct-Access     MARSHAL  MARSHAL_EXTERNAL 0    PQ: 0 ANSI: 6
    [  244.738834] sd 0:0:0:0: Attached scsi generic sg0 type 0
    [  244.741174] sd 0:0:0:0: [sda] Spinning up disk...
    [  245.759932] ..ready
    [  246.786853] sd 0:0:0:0: [sda] 3907029168 512-byte logical blocks: (2.00 TB/1.82 TiB)
    [  246.787520] sd 0:0:0:0: [sda] Write Protect is off
    [  246.787539] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
    [  246.788350] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
    [  247.010626]  sda: sda1 sda2
    [  247.033816] sd 0:0:0:0: [sda] Attached SCSI disk
    
  2. フォーマットする
    sudo mkfs -t ext4 /dev/sda

    私は今回ext4にフォーマットしたいのでext4を指定しています。
    この時表示されるUUIDは後で使うので控えておいてください。

    ubuntu@ubuntu:~$ sudo mkfs -t ext4 /dev/sda
    mke2fs 1.45.5 (07-Jan-2020)
    Found a gpt partition table in /dev/sda
    Proceed anyway? (y,N) y
    Creating filesystem with 488378646 4k blocks and 122101760 inodes
    Filesystem UUID: e1795d2f-db0a-4e61-aef9-1112dc355f02
    Superblock backups stored on blocks:
         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
         4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
         102400000, 214990848
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (262144 blocks):
    done
    Writing superblocks and filesystem accounting information: done
    
  3. 手動でマウントする
    sudo mount /dev/sda /mnt/hdd

    私は今回/mnt/hddにマウントしたいのでを指定しています。
    みなさんは適時読み替えてください。

    dfコマンドでマウントできたか確認できます。

     /dev/sda       1921803544   77852 1824033580   1% /mnt/hdd 
  4. 自動マウント設定をする

    自動マウントするためには、設定を/etc/fstabファイルに書き込みます。
    UUIDはフォーマット時に表示されたものを使用しますので注意してください。

     UUID=e1795d2f-db0a-4e61-aef9-1112dc355f02       /mnt/hdd        ext4    defaults 0       0 

    sudo mount -aでこの設定を基に手動マウントできます。
    再起動前に設定が正しいか確認しておくといいですよ。