LoginSignup
18

More than 5 years have passed since last update.

既存のEC2インスタンスに新規のEBSをアタッチする

Posted at

問題

作成したばかりのEBSVolumeはAWSConsoleからアタッチしただけでは使えない

$ sudo mount /dev/xvdf /mnt/data/
mount: /dev/xvdf is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/xvdf,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

解決

一度、フォーマットしてからマウントする

1. AWS ConsoleからEBSを新規に作成する

適当なサイズで作成する

2.EBSをEC2にアタッチする

Actions > Attach Volumeで既存のインスタンスにアタッチする

3. アタッチされていることを確認する

以下、Terminalからの作業

# lsblk

出力結果

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0    8G  0 disk 
└─xvda1 202:1    0    8G  0 part /
xvdf    202:80   0  100G  0 disk 

正しく、アタッチされているとxvdfが表示されています。

4. ファイルフォーマットを確認する。

# file -s /dev/xvdf

出力結果

/dev/xvdf: data

フォーマットされていないのでdataという表示です。

もし、フォーマットされていると以下のような表示になる。そのままマウントできる。

/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=fa5b665e-c3ee-4596-ac88-ae39494c7bf2 (needs journal recovery) (extents) (large files) (huge files)

5. ディスクをext4ファイルシステムでフォーマットする

# mkfs -t ext4 /dev/xvdf

出力結果

mke2fs 1.42.8 (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

6. フォーマットできたか確認する

# file -s /dev/xvdf

出力結果

/dev/xvdf: Linux rev 1.0 ext4 filesystem data, UUID=efec8dc6-53e1-4efc-ad17-4293f1a321e5 (needs journal recovery) (extents) (large files) (huge files)

7. ディスクをマウントする

# mkdir /mnt/data
# mount /dev/xvdf /mnt/data

8. マウントできたか確認する

# df -h /dev/xvdf

出力結果

ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/xvdf         99G  2.0G   92G    3% /mnt/data

アンマウントする

# umount /dev/xvdf

AWS Consoleからデタッチする

Actions > Detach Volumeで既存のインスタンスからデタッチする。
アンマウントしないでいきなりデタッチするとbusyになります。
busy状態のままでもディスクを正しくアンマウントすればデタッチされます。

参考

インスタンスへのボリュームの追加

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18