LoginSignup
0
0

More than 3 years have passed since last update.

インスタンスストアの自動マウント方法(忘備)

Posted at

インスタンスストアの自動マウント方法(忘備)

インスタンスストアはホストに依存する。
再起動(実行ホストが変わる)とデバイス自体が別物になるので毎々ファイルシステム作成とマウントが必要になるので/etc/rc.localにファイルシステム作成とマウントコマンド書いておく

環境

  • os: CentOS Linux release 7.6.1810 (Core)
  • ami-id: ami-045f38c93733dd48d
  • instance-type: t2.micro

環境確認

os
# more /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
ami-id,instance-typ
# ec2metadata --ami-id --instance-type
ami-045f38c93733dd48d
x1e.4xlarge
disk
# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   50G  0 disk
mqxvda1 202:1    0   50G  0 part /
xvdb    202:16   0  447G  0 disk #インスタンスストア
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       50G  1.5G   49G   3% / #EBSのみマウントされている
devtmpfs        241G     0  241G   0% /dev
tmpfs           241G     0  241G   0% /dev/shm
tmpfs           241G   25M  241G   1% /run
tmpfs           241G     0  241G   0% /sys/fs/cgroup
tmpfs            49G     0   49G   0% /run/user/0
tmpfs            49G     0   49G   0% /run/user/1000
# ls -la /dev/xv*
brw-rw----. 1 root disk 202,  0 Aug 20 04:57 /dev/xvda
brw-rw----. 1 root disk 202,  1 Aug 20 04:57 /dev/xvda1
brw-rw----. 1 root disk 202, 16 Aug 20 04:56 /dev/xvdb #インスタンスストア
# more /etc/fstab

# /etc/fstab
# Created by anaconda on Mon Jan 28 20:51:49 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f41e390f-835b-4223-a9bb-9b45984ddf8d /                       xfs     defaults        0 0
/dev/xvdb       /mnt    auto    defaults,nofail,x-systemd.requires=cloud-init.service,comment=cloudconfig       0       2
#既に記載があるがファイルシステムが作成されていないのでマウントされない

作業

mkdir,mount
# mkfs -t ext4 /dev/xvdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
29302784 inodes, 117184940 blocks
5859247 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2264924160
3577 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, 71663616, 78675968,
        102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
# mount -a
# # df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       50G  1.5G   49G   3% /
devtmpfs        241G     0  241G   0% /dev
tmpfs           241G     0  241G   0% /dev/shm
tmpfs           241G   25M  241G   1% /run
tmpfs           241G     0  241G   0% /sys/fs/cgroup
tmpfs            49G     0   49G   0% /run/user/0
tmpfs            49G     0   49G   0% /run/user/1000
/dev/xvdb       440G   73M  418G   1% /mnt

起動時の自動マウント

/etc/rc.local
# echo "mkfs -t ext4 /dev/xvdb" >> /etc/rc.local
# more /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
mkfs -t ext4 /dev/xvdb
mount -a
0
0
0

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
0
0