一、實(shí)現(xiàn)磁盤分區(qū)的
只支持分配主分區(qū)和標(biāo)準(zhǔn)的linux文件系統(tǒng)(ext4/xfs)的分區(qū)
#!?/bin/bash #?Function:對硬盤進(jìn)行分區(qū),得到一個(gè)標(biāo)準(zhǔn)的linux文件系統(tǒng)(ext4/xfs)的主分區(qū) cat?/proc/partitions?>?old read?-p?"請輸入你要分區(qū)的硬盤(寫絕對路徑,如:/dev/sda):"?A if?[?-e?$A?];then ??echo?"true" else ??echo?"該設(shè)備不存在!!" ??exit fi read?-p?"請輸入你要?jiǎng)?chuàng)建的磁盤分區(qū)類型(這里只能是主分區(qū),默認(rèn)按回車即可):"?B read?-p?"請輸入分區(qū)數(shù)字,范圍1-4,默認(rèn)從1開始,默認(rèn)按回車即可:"?C read?-p?"請輸入扇區(qū)起始表號,默認(rèn)按回車即可:"?D read?-p?"請輸入你要分區(qū)的分區(qū)大小(格式:如?+5G ):"?E fdisk?$A?<?new F=`diff?new?old?|?grep?"<"?|?awk?'{print?$5}'` echo?"-------------------------------" echo?$F echo?"你想對新分區(qū)設(shè)定什么類型的文件系統(tǒng)?有以下選項(xiàng):" echo?"A:ext4文件系統(tǒng)" echo?"B:xfs文件系統(tǒng)" read?-p?"請輸入你的選擇:"?G case?$G?in ????????a|A) ???????????mkfs.ext4?/dev/$F ???????????echo?"該分區(qū)將被掛載在?"/mnt/$F"?下"? ???????????m=`ls?/mnt/|grep?$F?|?wc?-l` ???????????if?[?$m?-eq?0?];then ????????????mkdir?/mnt/$F ???????????fi ???????????n=`cat?/etc/fstab?|?grep?/dev/$F|?wc?-l` ???????????if?[?$n?-eq?0?];then ??????????????echo?"/dev/$F?????/mnt/$F?????ext4?????????defaults??????????0??????0"?>>?/etc/fstab ???????????else ??????????????sed?-i?'/^/dev/$F/c/dev/$F?????/mnt/$F?????ext4?????????defaults??????????0??????0'?/etc/fstab ???????????fi ???????????mount?-a ???????????df?-Th ;; ????????b|B) ???????????mkfs.xfs?-f?/dev/$F ???????????echo?"該分區(qū)將被掛載在?"/mnt/$F"?下"? ???????????m=`ls?/mnt/|grep?$F?|?wc?-l` ???????????if?[?$m?-eq?0?];then ??????????????mkdir?/mnt/$F ???????????fi ???????????n=`cat?/etc/fstab?|?grep?/dev/$F?|?wc?-l` ???????????if?[?$n?-eq?0?];then ??????????????echo?"/dev/$F?????/mnt/$F??????xfs???????defaults??????????0??????0"?>>?/etc/fstab ???????????else ??????????????sed?-i?'/^/dev/$F/c/dev/$F?????/mnt/$F?????xfs?????????defaults??????????0??????0'?/etc/fstab ???????????fi ???????????mount?-a ???????????df?-Th ;; ????????*) ???????????echo?"你的輸入有誤!!" esac
二、使用一整塊硬盤創(chuàng)建邏輯卷
#!/bin/bash #?Function:使用一整塊硬盤創(chuàng)建LVM邏輯卷 read?-p?"請輸入你要做成邏輯卷的硬盤(寫絕對路徑,如:/dev/sda):"?path if?[?-e?$path?];then ??echo?"true" else ??echo?"該設(shè)備不存在!!" ??exit fi pvcreate?$path echo?"該硬盤已做成物理卷!" vgcreate?myvg?$path echo?"該物理卷已加入卷組?myvg?中" vgs free=`vgs|?awk?'$1~/myvg/{print}'|awk?'{print?$6}'` echo?"該物理卷剩余的空間大小為:$free?" read?-p?"請輸入你要?jiǎng)?chuàng)建邏輯卷的大小(如:1G):"?repy2 lvcreate?-L?$repy2?-n?mylv?myvg echo?"已成功創(chuàng)建邏輯卷mylv" echo?"------------------------" lvs echo?"------------------------" echo?"你想對新分區(qū)設(shè)定什么類型的文件系統(tǒng)?有以下選項(xiàng):" echo?"A:ext4文件系統(tǒng)" echo?"B:xfs文件系統(tǒng)" read?-p?"請輸入你的選擇:"?repy3 case?$repy3?in ????????a|A) ???????????mkfs.ext4?/dev/myvg/mylv ???????????echo?"該分區(qū)將被掛載在?"/mnt/mylv"?下"? ???????????m=`ls?/mnt/|grep?mylv?|?wc?-l` ???????????if?[?$m?-eq?0?];then ????????????mkdir?/mnt/mylv ???????????fi ???????????echo?"/dev/myvg/mylv?????/mnt/mylv?????ext4?????????defaults??????????0??????0"?>>?/etc/fstab ???????????mount?-a ???????????df?-Th ;; ????????b|B) ???????????mkfs.xfs?-f?/dev/myvg/mylv ???????????echo?"該分區(qū)將被掛載在?"/mnt/mylv"?下"? ???????????m=`ls?/mnt/|grep?mylv?|?wc?-l` ???????????if?[?$m?-eq?0?];then ??????????????mkdir?/mnt/mylv ???????????fi ???????????echo?"/dev/myvg/mylv?????/mnt/mylv??????xfs???????defaults??????????0??????0"?>>?/etc/fstab ???????????mount?-a ???????????df?-Th ;; ????????*) ???????????echo?"你的輸入有誤!!" esac
三、將一塊硬盤分區(qū),然后分區(qū)設(shè)置為虛擬卷
#!?/bin/bash #?Author:謝公子 #?Date:2018-10-13 #?Function:新建一個(gè)分區(qū),并做成邏輯卷 cat?/proc/partitions?>?old read?-p?"請輸入你要分區(qū)的硬盤(寫絕對路徑,如:/dev/sda):"?A if?[?-e?$A?];then ??echo?"true" else ??echo?"該設(shè)備不存在!!" ??exit fi read?-p?"請輸入你要?jiǎng)?chuàng)建的磁盤分區(qū)類型(這里只能是主分區(qū),默認(rèn)按回車即可):"?B read?-p?"請輸入分區(qū)數(shù)字,范圍1-4,默認(rèn)從1開始,默認(rèn)按回車即可:"?C read?-p?"請輸入扇區(qū)起始表號,默認(rèn)按回車即可:"?D read?-p?"請輸入你要分區(qū)的分區(qū)大小(格式:如?+5G ):"?E read?-p?"請輸入你要?jiǎng)澐譃檫壿嬀淼姆謪^(qū)盤符(默認(rèn)回車即可):"?Z fdisk?$A?<?new F=`diff?new?old?|?grep?"<"?|?awk?'{print?$5}'` echo?"-------------------------------" echo?$F pvcreate?/dev/$F echo?"該硬盤已做成物理卷!" n=`vgs?|?grep?myvg?|wc?-l` if?[?$n?-eq?0?];then ???vgcreate?myvg?/dev/$F ???echo?"該物理卷已加入卷組myvg中" else ???vgextend?myvg?/dev/$F ???echo??"該物理卷已加入卷組myvg中" ???vgs ???free=`vgs|?awk?'$1~/myvg/{print}'|awk?'{print?$7}'` ???echo?"該卷組剩余的空間大小為:$free?" ???lvs ???exit fi vgs free=`vgs|?awk?'$1~/myvg/{print}'|awk?'{print?$6}'` echo?"該卷組剩余的空間大小為:$free?" read?-p?"請輸入你要?jiǎng)?chuàng)建邏輯卷的大小(如:1G):"?repy2 lvcreate?-L?$repy2?-n?mylv?myvg echo?"已成功創(chuàng)建邏輯卷mylv" echo?"------------------------" lvs echo?"------------------------" echo?"你想對新分區(qū)設(shè)定什么類型的文件系統(tǒng)?有以下選項(xiàng):" echo?"A:ext4文件系統(tǒng)" echo?"B:xfs文件系統(tǒng)" read?-p?"請輸入你的選擇:"?G case?$G?in ????????a|A) ???????????mkfs.ext4?/dev/myvg/mylv ???????????echo?"該分區(qū)將被掛載在?"/mnt/$F"?下"? ???????????m=`ls?/mnt/|grep?$F?|?wc?-l` ???????????if?[?$m?-eq?0?];then ????????????mkdir?/mnt/$F ???????????fi ???????????echo?"/dev/myvg/mylv?????/mnt/$F?????ext4?????????defaults??????????0??????0"?>>?/etc/fstab ???????????mount?-a ???????????df?-Th ;; ????????b|B) ???????????mkfs.xfs?-f?/dev/myvg/mylv ???????????echo?"該分區(qū)將被掛載在?"/mnt/$F"?下"? ???????????m=`ls?/mnt/|grep?$F?|?wc?-l` ???????????if?[?$m?-eq?0?];then ??????????????mkdir?/mnt/$F ???????????fi ???????????echo?"/dev/myvg/mylv?????/mnt/$F??????xfs???????defaults??????????0??????0"?>>?/etc/fstab ???????????mount?-a ???????????df?-Th ;; ????????*) ???????????echo?"你的輸入有誤!!" esac
編輯:黃飛
?
評論
查看更多