Skip to main content

linux - Repartitioning two disks without a loss of data

I am interning at a software company and I have hit somewhat of a brick wall. Here is the deal:



The Problem: We have some boxes around here that were incorrectly partitioned for 2 x 500 GB drives. The actual drives are 2 x 1 TB drives. These are essentially machines with only half of their available disk space being used. I am tasked with writing a script to re-partition these drives.




Solution Thus Far: I have a script that disables all process and reboots, and then another script that fixes the partitions. The problem is that there is a loss of data.



What I'm Looking For: I need a solution that does this but saves all the data. My first though would be to just grow the partitions to their appropriate size, but I'm not sure if that is possible. The other solution is to copy all data onto Disk2, partition Disk1, move data back to Disk1, and finally partition Disk2. The problem is that I am pretty new to Linux and I don't really know how to do it. I have access to the fdisk utility and the parted utility.



They are all of type ext3.



EDIT: 11/3/11



Okay. So I have approximately 1GB of unused, unallocated space on both disks. I want to do as follows:





  • Create a new extended partition on SDB of size 1GB, called sdb99 for reference here

  • Copy sda5 sda6 sda7 to the new SDB partition sdb99


    • Can I just copy "/" from each of these to some folder in this new partition?

    • Do I need to put a filesystem on this new partition to copy any files on there?

    • If I just copy "/", will that preserve the whole directory structure?

    • Is it a simple task to move files between disks like this?



  • Delete sda5 sda6 sda7 and then re-create them with twice size


    • Do I actually need to delete these? I don't think that I can grow 3 contiguous partitions, and even if I could, the filesystem won't grow...right?


  • Copy back the data from sdb99 to the new sda5 sda6 sda7 partitions


    • This should be as simple as moving the contents of those directories containing all the "/"'s back, right?



  • Copy sdb5 sdb6 sdb7 into the new sda5 sda6 sda7 into separate folders.


    • There should be enough space because of the now doubled space available...I hope


  • Delete and re-partition SDB

  • Move the files from sdb5 sdb6 sdb7 back onto SDB




Does anyone see any glaring problems, have any pointers, warnings, suggestions, etc.?



Thanks everyone. Again, this needs to be scripted. Thanks.



EDIT 2
Here is the actual script...



#!/bin/bash

LOG=./repartition.log


date > $LOG 2>&1

echo "Ok, let's get started." >> $LOG 2>&1

# Resize logical partitons
parted -s /dev/sda resize 4 45GB 2000GB >> $LOG 2>&1
parted -s /dev/sdb resize 4 90GB 2000GB >> $LOG 2>&1

# Create the temporary file systems on disk 2

mke2fs -j /dev/sdb8 >> $LOG 2>&1

# Copy sda6 sda7 sda8 to sdb8
cp -r -L -p /dev/sda6 /dev/sdb8/home/sda6 >> $LOG 2>&1
cp -r -L -p /dev/sda7 /dev/sdb8/home/sda7 >> $LOG 2>&1
cp -r -L -p /dev/sda8 /dev/sdb8/home/sda8 >> $LOG 2>&1

# Remove NBD partitions on disk 1
parted -s /dev/sda rm 8 >> $LOG 2>&1
parted -s /dev/sda rm 7 >> $LOG 2>&1

parted -s /dev/sda rm 6 >> $LOG 2>&1

# Create NBD partitons on disk 1
parted -s /dev/sda mkpart logical 70GB 713GB >> $LOG 2>&1
parted -s /dev/sda mkpart logical 713GB 1356GB >> $LOG 2>&1
parted -s /dev/sda mkpart logical 1356GB 2000GB >> $LOG 2>&1

# Create the file systems on disk 1
mke2fs -j /dev/sda6 >> $LOG 2>&1
mke2fs -j /dev/sda7 >> $LOG 2>&1

mke2fs -j /dev/sda8 >> $LOG 2>&1

# Copy sda6 sda7 sda8 back to sda
cp -r -L -p /dev/sdb8/home/sda6 /dev/sda6 >> $LOG 2>&1
cp -r -L -p /dev/sdb8/home/sda7 /dev/sda7 >> $LOG 2>&1
cp -r -L -p /dev/sdb8/home/sda8 /dev/sda8 >> $LOG 2>&1

# Copy sdb5 sdb6 sdb7 to sda6 sda7 sda8
cp -r -L -p /dev/sdb5 /dev/sda6/home/sdb5 >> $LOG 2>&1
cp -r -L -p /dev/sdb6 /dev/sda7/home/sdb6 >> $LOG 2>&1

cp -r -L -p /dev/sdb7 /dev/sda8/home/sdb7 >> $LOG 2>&1

# Remove NBD partitions on disk 2
parted -s /dev/sdb rm 8 >> $LOG 2>&1
parted -s /dev/sdb rm 7 >> $LOG 2>&1
parted -s /dev/sdb rm 6 >> $LOG 2>&1
parted -s /dev/sdb rm 5 >> $LOG 2>&1

# Create NBD partitons on disk 2
parted -s /dev/sdb mkpart logical 90GB 726GB >> $LOG 2>&1

parted -s /dev/sdb mkpart logical 726GB 1362GB >> $LOG 2>&1
parted -s /dev/sdb mkpart logical 1362GB 2000GB >> $LOG 2>&1

# Create the file systems on disk 2
mke2fs -j /dev/sdb5 >> $LOG 2>&1
mke2fs -j /dev/sdb6 >> $LOG 2>&1
mke2fs -j /dev/sdb7 >> $LOG 2>&1

# Copy sdb5 sdb6 sdb7 back to sdb
cp -r -L -p /dev/sda8/home/sdb7 /dev/sdb7 >> $LOG 2>&1

cp -r -L -p /dev/sda7/home/sdb6 /dev/sdb6 >> $LOG 2>&1
cp -r -L -p /dev/sda6/home/sdb5 /dev/sdb5 >> $LOG 2>&1


rm /etc/init.d/fix_partitions >> $LOG 2>&1
rm /etc/init.d/local/99fix_partitions >> $LOG 2>&1
mv /etc/init.d/local/gca_init.off /etc/init.d/local/99gca_init >> $LOG 2>&1

echo "All set. Please reboot. Have a nice day." >> $LOG 2>&1


date >> $LOG 2>&1
reboot >> $LOG 2>&1

Comments

Popular posts from this blog

linux - Awstats - outputting stats for merged Access_logs only producing stats for one server's log

I've been attempting this for two weeks and I've accessed countless number of sites on this issue and it seems there is something I'm not getting here and I'm at a lost. I manged to figure out how to merge logs from two servers together. (Taking care to only merge the matching domains together) The logs from the first server span from 15 Dec 2012 to 8 April 2014 The logs from the second server span from 2 Mar 2014 to 9 April 2014 I was able to successfully merge them using the logresolvemerge.pl script simply enermerating each log and > out_putting_it_to_file Looking at the two logs from each server the format seems exactly the same. The problem I'm having is producing the stats page for the logs. The command I've boiled it down to is /usr/share/awstats/tools/awstats_buildstaticpages.pl -configdir=/home/User/Documents/conf/ -config=example.com awstatsprog=/usr/share/awstats/wwwroot/cgi-bin/awstats.pl dir=/home/User/Documents/parced -month=all -year=all...

iLO 3 Firmware Update (HP Proliant DL380 G7)

The iLO web interface allows me to upload a .bin file ( Obtain the firmware image (.bin) file from the Online ROM Flash Component for HP Integrated Lights-Out. ) The iLO web interface redirects me to a page in the HP support website ( http://www.hp.com/go/iLO ) where I am supposed to find this .bin firmware, but no luck for me. The support website is a mess and very slow, badly categorized and generally unusable. Where can I find this .bin file? The only related link I am able to find asks me about my server operating system (what does this have to do with the iLO?!) and lets me download an .iso with no .bin file And also a related question: what is the latest iLO 3 version? (for Proliant DL380 G7, not sure if the iLO is tied to the server model)

hp proliant - Smart Array P822 with HBA Mode?

We get an HP DL360 G8 with an Smart Array P822 controller. On that controller will come a HP StorageWorks D2700 . Does anybody know, that it is possible to run the Smart Array P822 in HBA mode? I found only information about the P410i, who can run HBA. If this is not supported, what you think about the LSI 9207-8e controller? Will this fit good in that setup? The Hardware we get is used but all original from HP. The StorageWorks has 25 x 900 GB SAS 10K disks. Because the disks are not new I would like to use only 22 for raid6, and the rest for spare (I need to see if the disk count is optimal or not for zfs). It would be nice if I'm not stick to SAS in future. As OS I would like to install debian stretch with zfs 0.71 as file system and software raid. I have see that hp has an page for debian to. I would like to use hba mode because it is recommend, that zfs know at most as possible about the disk, and I'm independent from the raid controller. For us zfs have many benefits, ...