Automate fdisk

[root@RHEL5-VM ~]echo "n
p
1


w
"|fdisk /dev/hdb
[root@RHEL5-VM ~]# fdisk -l

"See the magic......"
With a for loop in place we can partiton and format any number of disks with in few minutes

for i in /dev/sda /dev/sdb /dev/sdc;do
echo "n
p
1


w
"|fdisk $i;mkfs.ext3 $i\1;done



PS:This particular sequence will create a single slice of the disk with maximum space.Try this only in test environments

You can make it more simple....

Add all the fdisk commands in one file...
e.g create a partition.txt with following contents:

Quote:
n
p
1


w


and then run it as follows:

Quote:
# for i in sda sdb sdc sdd ;do echo " *** partitioning disk /dev/$i ****";fdisk /dev/$i < partition.txt;done


This is useful in case of creating the same partitions on many disks, say you need to create single partition on all disks with available space..


Comments

Popular posts from this blog

configure Netbackup email notification on Unix