格式化和挂载所有可用实例存储设备的脚本 [英] Script to Format and Mount all available instance store devices

查看:92
本文介绍了格式化和挂载所有可用实例存储设备的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Amazon 提供EC2实例的实例存储。如果您使用自己的AMI,则不会自动格式化或安装这些AMI。您需要手动格式化并挂载它们。

Amazon provides instance store for EC2 instances. If you use your own AMI, these are not formatted or mounted automatically for you. You need to manually format and mount them.

可用设备为在此处列出,并根据实例类型而有所不同。例如,一个m1.small与c1.xlarge将具有不同的可用实例存储设备。

The available devices are listed here and vary based on type of instance. For example an m1.small will have different available instance store devices than c1.xlarge.

我正在寻找一个


  1. 检测实例类型是什么。也许通过使用
    curl -s http://169.254.169.254/latest/meta-data/instance-type

  2. 格式化并挂载该实例类型可用但尚未格式化/挂载的所有设备。

可能吗?完成了?

推荐答案

所以,这就是我为此构建的。

So, here is what I built for this.

#!/bin/bash

# This script formats and mounts all available Instance Store devices

##### Variables
devices=( )

##### Functions

function add_device
{
    devices=( "${devices[@]}" $1 )
}

function check_device
{
    if [ -e /dev/$1 ]; then
        add_device $1
    fi
}

function check_devices
{
    check_device sda2
    check_device sda3
    check_device sdb
    check_device sdc
    check_device sdd
    check_device sde
}

function print_devices
{
    for device in "${devices[@]}"
    do
        echo Found device $device
    done
}

function do_mount
{
    echo Mounting device $1 on $2
fdisk $1 << EOF
n
p
1



w
EOF
# format!
mkfs -t xfs -f $1

mkdir $2
mount $1 $2

echo "$1   $2      xfs     defaults          0 0" >> /etc/fstab

}

function mount_devices
{
    for (( i = 0 ; i < ${#devices[@]} ; i++ ))
    do
        mountTarget=/mnt
        if [ $i -gt 0 ]; then
            mountTarget=/mnt$(($i+1))
        fi
        do_mount /dev/${devices[$i]} $mountTarget
    done
}


##### Main

check_devices
print_devices
mount_devices

这篇关于格式化和挂载所有可用实例存储设备的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆