shell脚本快速创建格式化磁盘

文章目录

  • 一、通过管理员选择创建、格式化、挂载新添加的磁盘脚本
  • 二、自动创建、格式化、挂载新添加的磁盘脚本

一、通过管理员选择创建、格式化、挂载新添加的磁盘脚本

#! /bin/bash
echo "=============================="
PS3="chose which disk you want to create:"
select W in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit
do
        case $W in
        sda)
            fdisk -l /dev/sda
            break;;
        sd[b-z])
             echo "n
                     p



                        w" | fdisk /dev/$W
        mkfs.xfs -i size=512 /dev/${W}"1" &>/dev/null
        mkdir -p /data/${W}"1" &>/dev/null
        echo -e "/dev/${W}"1" /data/${W}"1" xfs  defaults 0 0\n" >> /etc/fstab
        mount -a &>/dev/null
        break;;
        quit)
        break;;
        *)
        echo "wrong disk,plwase check again";;
        esac
done

二、自动创建、格式化、挂载新添加的磁盘脚本

#!/bin/bash
for V in $(ls /dev/sd[b-z])
do
  echo -e "n\np\n\n\n\nw\n" |fdisk $V
  mkfs.xfs -i size=512 ${V}1 &>/dev/null
  sleep 1
  M=$(echo "$V" |awk -F "/" '{print $3}')
  mkdir -p /data/${M}1 &>/dev/null
  echo -e "${V}1 /data/${M}1 xfs defaults 0 0\n" >>/etc/fstab
  mount -a &>/dev/null
done

你可能感兴趣的:(linux,shell,磁盘)