2012-05-16 2 views
4

Amazon provides instance store (EC2 인스턴스 용). 자신의 AMI를 사용하면 자동으로 포맷되거나 마운트되지 않습니다. 수동으로 포맷하고 마운트해야합니다.사용 가능한 모든 인스턴스 저장소 장치를 포맷하고 마운트하는 스크립트

사용 가능한 장치는 listed here이며 인스턴스 유형에 따라 다릅니다. 예를 들어, m1.small에는 c1.xlarge와는 다른 사용 가능한 인스턴스 저장 장치가 있습니다.

나는

  1. 인스턴스 유형이 무엇인지 감지 스크립트를 찾고 있어요. 아마도 사용하여 curl -s http://169.254.169.254/latest/meta-data/instance-type
  2. 해당 인스턴스 유형에 사용할 수 있지만 아직 포맷/마운트되지 않은 모든 장치를 포맷하고 마운트합니다.

가능한가? 끝냈어? 그것을 가지고?

답변

5

그래서 여기에 제가 작성한 내용이 있습니다.

#!/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 
1
#!/bin/bash 
#SETUP RAID0 
checkAllDevices() 
{ 
    devicemount=/ephemeral 
    logicalname=/dev/md0 
    deviceslist=('/dev/xvdb' '/dev/xvdc' '/dev/xvdd' '/dev/xvde') 
    for device in ${deviceslist[@]}; do 
     if ([ -b $device ]) then 
      aDevices=("${aDevices[@]}" $device) 
     fi 
    done 
    if [ "${#aDevices[@]}" -gt '1' ];then 
     yes | mdadm --create $logicalname --level=0 -c256 --raid-devices=${#aDevices[@]} ${aDevices[@]} 
     echo \'DEVICE ${aDevices[@]}\' > /etc/mdadm.conf 
     mdadm --detail --scan >> /etc/mdadm.conf 
     blockdev --setra 65536 $logicalname 
     mkfs.xfs -f $logicalname > /dev/null 
     mkdir -p $devicemount 
     mount -t xfs -o noatime $logicalname $devicemount 
     if [ ! -f /etc/fstab.backup ]; then 
      cp -rP /etc/fstab /etc/fstab.backup 
      echo "$logicalname $devicemount xfs defaults 0 0" >> /etc/fstab 
     fi   
    else 
     echo "Required more than one devices" 
    fi 
} 

#MAIN FUNCTION 
aDevices=() 
checkAllDevices