标签:linux磁盘批量分区部署格式化和挂载 linux分区脚本 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 ~
本文出自 “散人” 博客,请务必保留此出处http://zouqingyun.blog.51cto.com/782246/1689231
标签:linux磁盘批量分区部署格式化和挂载 linux分区脚本 linux挂载脚本
原文地址:http://zouqingyun.blog.51cto.com/782246/1689231