zoukankan      html  css  js  c++  java
  • RHEL7磁盘分区挂载和格式化

    安装大数据平台,每台机器需要挂载10个磁盘,用JBOD模式,操作系统为RHEL7.2。

    写了两个脚本,format_disk.sh和mount_disk.sh实现磁盘自动分区格式化以及挂载,修改fstab。

    format_disk.sh

    #!/bin/bash
    disks=(sdb sdc sdd sde sdf sdg sdh sdi sdj sdk)
    for ((i=0;i<${#disks[*]};i++))
    do
      mounted=`mount|grep "/mnt/${disks[i]}"`
      if [ "$mounted" ] ; then
        echo "umount /mnt/${disks[i]}"
        umount /mnt/${disks[i]}
      fi
      echo "make partition /dev/${disks[i]}"
      parted -s /dev/${disks[i]} mklabel gpt
      parted -s /dev/${disks[i]} mkpart primary xfs 0% 100%
      echo "format disk /dev/${disks[i]}"
      mkfs.xfs -f -L ${disks[i]} /dev/${disks[i]}
    done
    echo -n "reboot?"
    read ANS
    case $ANS in
    y|Y|yes|Yes)
      echo "run mount_disk.sh after rebooting"
      reboot
      ;;
    n|N|no|No)
      exit 0
      ;;
    esac

    mount_disk.sh

    #!/bin/bash
    rm -f fstab
    cp /etc/fstab . -f
    cat fstab
    >fstab.new
    sed -e '//mnt/sd/d' fstab > fstab.new
    cat fstab.new
    disks=(sdb sdc sdd sde sdf sdg sdh sdi sdj sdk)
    for ((i=0;i<${#disks[*]};i++))
    do
      mounted=`mount|grep "/mnt/${disks[i]}"`
      if [ "$mounted" ] ; then
        echo "umount /mnt/${disks[i]}"
        umount /mnt/${disks[i]}
      fi
      if [ ! -d "/mnt/${disks[i]}" ]; then
        mkdir /mnt/${disks[i]}
      fi
      UUID=`lsblk -f /dev/${disks[i]}|grep "^${disks[i]} " |awk '{print $4}'`
      if [ "$UUID" ]; then
        echo "write partition to fstab.new"
        echo "UUID=${UUID} /mnt/${disks[i]}    xfs         defaults 0 0" >> fstab.new
      fi
    done
    cat fstab.new
    echo -n "use this for /etc/fstab?"
    read ANS
    case $ANS in
    y|Y|yes|Yes)
      cp fstab.new /etc/fstab -f
      mount -a
      mount
      ;;
    n|N|no|No)
      exit 0
      ;;
    esac
  • 相关阅读:
    树上点对统计poj1741(树的点分治)
    hdu5115(区间dp)
    bestcoder Round#52 1001(最短路+状压dp)
    lightoj1038(期望dp)
    模线性方程组
    hdu2089 数位dp
    poj2955括号匹配 区间DP
    poj1417 带权并查集 + 背包 + 记录路径
    poj1984 带权并查集(向量处理)
    zoj3261 并查集离线处理
  • 原文地址:https://www.cnblogs.com/Donal/p/5226430.html
Copyright © 2011-2022 走看看