2021-05-12 14:32:11
Linux磁碟批次分割區格式化和掛載指令碼
昨天接到一個任務,十台機器,需要分割區和掛載,每台機器有6塊碟符,如果一台一台手工操作,效率不高,我在弄完一台,嘗試寫了個指令碼,來實現批次部署!以下是指令碼運用
[root@Hadoop6 ~]# vim parted.sh
#!/bin/bash
#
#
yum install -y parted
sleep 1s
yum install -y vim
sleep 1s
#####################################################################
touch /root/test1
i=0
b=1
for disk in `fdisk -l | grep "/dev/vd*" | awk '{if($2~/vd/ && $2!="/dev/vda:" && $2!="/dev/vdb:") print substr($2,0,8)}'`
do
parted $disk << EXIT
mklabel gpt
mkpart primary 0 -1
ignore
quit
EXIT
mkfs.ext4 $disk$b
echo "/n/n****************$disk_was Fdisked!Waithing For 10 second****/n/n"
sleep 1s
uuid=`blkid $disk$b | awk '{print $2}'|awk -F""" '{print $2}'`
mkdir /data${i}
cat << EXIT > /root/test1
UUID=$uuid /data${i} ext4 defaults 1 2
EXIT
cat /root/test1 >> /etc/fstab
i=$(($i + 1))
done
######################################################################
mount -a
--------------------------------------分割線 --------------------------------------
[root@hadoop6 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg0-lv_root 12179756 2680964 8880092 24% /
tmpfs 16439788 0 16439788 0% /dev/shm
/dev/vda1 198337 28603 159494 16% /boot
/dev/vdc1 4227572676 198680 4012625684 1% /data0
/dev/vdd1 4227572676 198680 4012625684 1% /data1
/dev/vde1 4227572676 198680 4012625684 1% /data2
/dev/vdf1 4227572676 198680 4012625684 1% /data3
/dev/vdg1 4227572676 198680 4012625684 1% /data4
/dev/vdh1 4227572676 198680 4012625684 1% /data5
--------------------------------------分割線 --------------------------------------
[root@hadoop6 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Mar 5 14:32:01 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg0-lv_root / ext4 defaults 1 1
UUID=0a17f48d-f99b-4498-82a5-a0874f25f1e7 /boot ext4 defaults 1 2
/dev/vdb1 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
UUID=9ff86747-384f-4a37-adab-1ac5abd98dff /data0 ext4 defaults 1 2
UUID=bd6103cf-9774-4e31-87bb-33df4fbea47e /data1 ext4 defaults 1 2
UUID=81a1b153-279f-454c-b23c-07744203b65a /data2 ext4 defaults 1 2
UUID=ae66663e-0879-4622-bb68-94bb045f9719 /data3 ext4 defaults 1 2
UUID=aab4c3f0-344a-4309-8ec0-c87017b5179d /data4 ext4 defaults 1 2
UUID=0d4a6b2f-99dd-4a87-9d48-6090c3863ba3 /data5 ext4 defaults 1 2
~
Linux下磁碟批次化自動分割區掛載指令碼實現 http://www.linuxidc.com/Linux/2013-07/87099.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-08/122401.htm
相關文章