1f08c3bdfSopenharmony_ci#!/usr/bin/perl -w 2f08c3bdfSopenharmony_ci# 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2000 4f08c3bdfSopenharmony_ci# 5f08c3bdfSopenharmony_ci# This program is free software; you can redistribute it and/or modify 6f08c3bdfSopenharmony_ci# it under the terms of the GNU General Public License as published by 7f08c3bdfSopenharmony_ci# the Free Software Foundation; either version 2 of the License, or 8f08c3bdfSopenharmony_ci# (at your option) any later version. 9f08c3bdfSopenharmony_ci# 10f08c3bdfSopenharmony_ci# This program is distributed in the hope that it will be useful, 11f08c3bdfSopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of 12f08c3bdfSopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13f08c3bdfSopenharmony_ci# the GNU General Public License for more details. 14f08c3bdfSopenharmony_ci# 15f08c3bdfSopenharmony_ci# You should have received a copy of the GNU General Public License 16f08c3bdfSopenharmony_ci# along with this program; if not, write to the Free Software 17f08c3bdfSopenharmony_ci# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18f08c3bdfSopenharmony_ci# 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci# 21f08c3bdfSopenharmony_ci# FILE(s) : maimparts 22f08c3bdfSopenharmony_ci# DESCRIPTION : Takes the disk device name (ex: hda) and number of iterations 23f08c3bdfSopenharmony_ci# to run thru and then rips the drive into a defined number of 24f08c3bdfSopenharmony_ci# partitions ($parts). This sets up the device for partbeat 25f08c3bdfSopenharmony_ci# and backbeat which are called after setup occurs. 26f08c3bdfSopenharmony_ci# 27f08c3bdfSopenharmony_ci# WARNING!!! : The device you specify on the command line (hda/sda/etc) will be 28f08c3bdfSopenharmony_ci# blown away...smoking any important data, programs, OS, etc. 29f08c3bdfSopenharmony_ci# Don't specify a device name that you don't want to wipe out. 30f08c3bdfSopenharmony_ci# YOU HAVE BEEN WARNED! 31f08c3bdfSopenharmony_ci# 32f08c3bdfSopenharmony_ci# AUTHOR : Jeff Martin (martinjn@us.ibm.com) 33f08c3bdfSopenharmony_ci# HISTORY : 34f08c3bdfSopenharmony_ci# 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci# target is device to split into partions 37f08c3bdfSopenharmony_ci$target=$ARGV[0]; 38f08c3bdfSopenharmony_ci$iterations=$ARGV[1]; 39f08c3bdfSopenharmony_ci# part is the number of partitions to split the drive into (max is 4) 40f08c3bdfSopenharmony_ci$parts=3; 41f08c3bdfSopenharmony_ci# fsid is the partition id or type (83 is linux native) 42f08c3bdfSopenharmony_ci$fstype=$ARGV[2]; 43f08c3bdfSopenharmony_ci$fsid=0x83; 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ciif (!$ARGV[0]) { 46f08c3bdfSopenharmony_ci print "Usage: maimparts [target device ie: hda or sda] [iterations]\n"; 47f08c3bdfSopenharmony_ci exit; 48f08c3bdfSopenharmony_ci } 49f08c3bdfSopenharmony_ci# run sfdisk to display device geometry and rip out info 50f08c3bdfSopenharmony_ci# (specifically cylinders) 51f08c3bdfSopenharmony_ci$Geom = `/sbin/sfdisk -g /dev/$target`; 52f08c3bdfSopenharmony_cichomp $Geom; 53f08c3bdfSopenharmony_ci($Junk,$Temp1) = split(/\: /,$Geom,2); 54f08c3bdfSopenharmony_ci($Cyl,$Heads,$Sec) = split(/\, /,$Temp1,3); 55f08c3bdfSopenharmony_ci($Cyl,$Junk) = split(/ /,$Cyl,2); 56f08c3bdfSopenharmony_ci($Heads,$Junk) = split(/ /,$Heads,2); 57f08c3bdfSopenharmony_ci($Sec,$Junk) = split(/ /,$Sec,2); 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci# determine partition size to create (force int so we don't 60f08c3bdfSopenharmony_ci# try to use 1/2 a cylinder!) 61f08c3bdfSopenharmony_ci$psize = int($Cyl/$parts); 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_ci# create a config file in /tmp for sfdisk creation run 64f08c3bdfSopenharmony_ciopen(CONFIG,">/tmp/part.cfg") || 65f08c3bdfSopenharmony_ci die "Couldn't create /tmp/part.cfg\n"; 66f08c3bdfSopenharmony_cifor($i=1;$i<=$parts;$i++) { 67f08c3bdfSopenharmony_ci printf(CONFIG ",%d,%x\n",$psize,$fsid); # write the lines in cfg 68f08c3bdfSopenharmony_ci } 69f08c3bdfSopenharmony_ciclose(CONFIG); 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci# create the partitions! 72f08c3bdfSopenharmony_ci`sfdisk --force /dev/$target < /tmp/part.cfg`; 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci#run partbeat on the partitions 75f08c3bdfSopenharmony_cifor ($k=1;$k<=$parts;$k++) { 76f08c3bdfSopenharmony_ci $part[$k] = sprintf("%s%d",$target,$k); 77f08c3bdfSopenharmony_ci $tmp = `./partbeat /dev/$target$k $iterations $fstype`; 78f08c3bdfSopenharmony_ci print $tmp; 79f08c3bdfSopenharmony_ci } 80f08c3bdfSopenharmony_ci$tmp = `./backbeat /dev/$part[1] /dev/$part[2] /dev/$part[3]`; 81f08c3bdfSopenharmony_ciprint $tmp; 82