Centos 磁盘4K对齐脚本

4K对齐对磁盘性能有什么影响这边不单独讲解,有权威网站已经给出测试结果。感兴趣的可以去看->传送门

#!/bin/bash

# Format all FOUND datadisks.

declare -a Disk_Name

#筛出有几块磁盘,如/dev/sda

Disk_Name=(`fdisk -l 2> /dev/null | grep '^Disk /dev' | awk '{print $2}' | tr -d ':' | sort -k1.1,1.1`)

Disk_Count="`fdisk -l 2> /dev/null | grep '^Disk /dev' | awk '{print $2}' | tr -d ':' | wc -l`"

for ((i=1;i<$Disk_Count;i++))

do

#根据磁盘数量创建文件夹,用户挂载磁盘

mkdir /cache$i

echo "LABEL=/cache$i /cache$i ext4 defaults 0 0" >> /etc/fstab

parted ${Disk_Name[$i]} -s mklabel gpt

#配置磁盘4k对齐

parted ${Disk_Name[$i]} -s mkpart primary 2048s 100%

Disk_Partition_Name="`fdisk -l 2>/dev/null | grep ^${Disk_Name[$i]} | awk '{print $1}'`"

#计算出磁盘大小

Disk_Size="`parted -s ${Disk_Name[$i]} print | grep "^Disk" | grep "/dev" | awk '{print $3}' | sed 's/GB//g'`"

#当磁盘大于1800g时

if [ ${Disk_Size%.*} -gt 1800 ]; then

inodes调整为200000000

mkfs.ext4 -N 200000000 -L "/cache$i" "${Disk_Partition_Name}" 2>&1 &

else

mkfs.ext4 -N 20000000 -L "/cache$i" "${Disk_Partition_Name}" 2>&1 &

fi

sleep 10

done

wait

#挂载磁盘

mount -a

echo -e '\nCongratulation: all disks have been format and mount!!!'

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: