xmzk-自动格式化挂载第二个磁盘到/data目录
1、2个文件都放置于/usr/local/sbin目录下,执行 sh /usr/local/sbin/format.sh即可,内容根据具体情况修改
文件1 fdisk.pt 免交互自动格盘
#!/usr/bin/env expect #该脚本的作用是:免去交互式格盘 spawn fdisk -c -u /dev/xvdb expect "Command (m for help):" send "n\r" expect "primary partition" send "p\r" expect "Partition number (1-4):" send "1\r" expect "First sector" send "\r" expect "Last sector" send "\r" expect "Command (m for help):" send "w\r" interact
主文件 format.sh 格式化、挂载
#!/usr/bin/env bash yum install -y vim expect expect /usr/local/sbin/fdisk.pt mkfs -t ext4 /dev/xvdb1 > /dev/null MOUNT_DIR=/data if [ ! -d "$MOUNT_DIR" ] ;then mkdir $MOUNT_DIR fi Z=$(egrep $MOUNT_DIR /etc/fstab) if [ -z "$Z" ] ;then echo "/dev/xvdb1 /data ext4 defaults 0 0" >> /etc/fstab fi mount /dev/xvdb1 /data