Centos下验证磁盘4K是否对齐脚本

2016年7月22日14:51:14 评论 7,254

上一篇文章分享磁盘4K对齐的脚本->传送门。但是不一定扇区是从4的倍数开始就一定是有4k对齐的,这里还要考虑Sector size。

下面分享一个验证4K是否对齐脚本,脚本运行的结果是整数即有4K对齐。

#!/bin/bash

disks="`parted -l | egrep ^"Disk /dev/" | awk '{print $2}' | tr -d :`"

for i in $disks
do
    sectorSize=`parted $i unit s print | awk -F[:/] '/^Sector/{print $NF}' | tr -d "B"`
    sectorNum=`parted $i unit s print | egrep -A 1 "Start" | awk '{if($2 !~ "Start") print $2}' | tr -d s`
    echo -n $i ; echo -ne "\t"; echo "scale=2;$sectorNum * $sectorSize / 4096" | bc
done
weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

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