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
Post a Comment