PowerRC's Blog

Posted by:
PowerRC

该同志还没添加个人介绍

2,233

A bash script to part and format HDs in quantity

I need to test a JBOD box today with 45 harddrives , obviously I am not going to part and format these harddrive one by one , so I write a script.

What this script would do:
1.Using GPT to label/relabel the HD.
2.Parting the whole drive into one partition.
3.Formatting the partition into Xfs.
4.Mounting the partition into /mnt with the same name.

Since some drivers were finished before I run this script , so I use a list to specify which drives I need to operate.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
#Used to initialize tons of disks
partnum=1
for disk in sdb sdc sdd sde
do
{
parted /dev/$disk <<ESXU
mklabel gpt
mkpart primary 4096s 100%
quit
ESXU
mkfs.xfs /dev/$disk$partnum -f
mkdir /mnt/$disk$partnum
mount /dev/$disk$partnum /mnt/$disk$partnum
}&
done;

At the end , don't forget to edit the /etc/fstab , put in drives info accordingly , or the system won't mount them during booting.

版权申明

若文中未注明,则本文由 PowerRC 原创,转载请注明出处。

分享

Leave a Reply

*

code

back up ↑