Last active
March 30, 2017 02:21
-
-
Save furlongm/292aefa930f40dc03f21693d1fc19f35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
osds=$(echo /dev/sd{a..p}) | |
partition_no=1 | |
if [ "${1}" == "--yes-really-do-it" ] ; then | |
make_modifications=true | |
fi | |
run_or_print() { | |
echo "${1}" | |
if [ "${make_modifications}" == "true" ] ; then | |
echo "${1}" | bash | |
fi | |
} | |
for osd in ${osds} ; do | |
dev=${osd}${partition_no} | |
part_size_sectors=$(blockdev --getsz ${dev}) | |
sector_size=$(blockdev --getss ${dev}) | |
part_size_bytes=$(( part_size_sectors * sector_size )) | |
xfs_bsize=$(xfs_db -r -c "sb" -c "print blocksize" ${dev} | awk {'print $3'}) | |
xfs_blocks=$(xfs_db -r -c "sb" -c "print dblocks" ${dev} | awk {'print $3'}) | |
fs_size_bytes=$(( xfs_bsize * xfs_blocks )) | |
divisor=$(( xfs_bsize / sector_size )) | |
unused_sectors=$(( part_size_sectors % divisor )) | |
unused_bytes_from_sectors=$(( unused_sectors * sector_size )) | |
unused_bytes_from_bytes=$(( part_size_bytes - fs_size_bytes )) | |
start_sector=$(sgdisk -i ${partition_no} ${osd} | grep ^First | sed -e "s/First sector: //" -e "s/ (.*//") | |
new_partition_end_sector=$(( part_size_sectors - unused_sectors + start_sector - 1 )) | |
partition_uuid=$(blkid ${dev} -s UUID -o value) | |
mount_point=$(lsblk ${dev} -o MOUNTPOINT -n) | |
if [ "${mount_point}" != "" ] ; then | |
osd_id=$(echo ${mount_point} | sed -e "s/\/var\/lib\/ceph\/osd\/ceph-//") | |
else | |
osd_id="Not mounted" | |
fi | |
echo "${dev}" | |
echo "OSD ID : ${osd_id}" | |
echo "Partition size in sectors : ${part_size_sectors}" | |
echo "Sector size : ${sector_size}" | |
echo "Partition size in bytes : ${part_size_bytes}" | |
echo "XFS block size : ${xfs_bsize}" | |
echo "# of XFS blocks : ${xfs_blocks}" | |
echo "XFS filsystem size : ${fs_size_bytes}" | |
echo "Unused sectors : ${unused_sectors}" | |
echo "Unused bytes (unused sector count * sector size) : ${unused_bytes_from_sectors}" | |
echo "Unused bytes (partition size - filesystem size) : ${unused_bytes_from_bytes}" | |
if [ ${unused_bytes_from_sectors} -ne ${unused_bytes_from_bytes} ] ; then | |
echo "Unused byte counts *DO NOT* match, not proceeding." | |
continue | |
elif [ ${unused_sectors} -eq 0 ] ; then | |
echo "Partition seems to be aligned correctly :-)" | |
continue | |
fi | |
echo "Filesystem is not correctly aligned to partition boundary :-(" | |
if [ "${mount_point}" != "" ] ; then | |
run_or_print "systemctl stop ceph-osd@${osd_id}" | |
run_or_print "umount ${dev}" | |
fi | |
run_or_print "sgdisk --delete=1 -- ${osd}" | |
run_or_print "sgdisk --new=${partition_no}:${start_sector}:${new_partition_end_sector} --change-name=${partition_no}:\"ceph data\" --partition-guid=${partition_no}:${partition_uuid} --typecode=${partition_no}:89c57f98-2fe5-4dc0-89c1-f3ad0ceff2be -- ${osd}" | |
run_or_print "partprobe ${osd}" | |
run_or_print "xfs_repair ${dev}" | |
run_or_print "sgdisk --typecode=${partition_no}:4fbd7e29-9d25-41b8-afd0-062c0ceff05d -- ${osd}" | |
echo "=====" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment