LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Migrating a live filesystem with rsync? (http://www.linuxquestions.org/questions/linux-general-1/migrating-a-live-filesystem-with-rsync-510069/)

ricbax 12-13-2006 11:37 AM

Migrating a live filesystem with rsync?
 
I want to move a live personal mail server's file system from a smaller hard drive to a larger hard drive. Can I do this with Rsync? Any pros and cons? Links to tutorials would be great, or if you really have the time to explain that would be great too.

TIA,
ricbax
:Pengy:

homey 12-13-2006 12:38 PM

Rsync along with find works very nicely for this.
For example: Copying my / partition which is on /dev/sda2 to another location such as /dev/sdb2 while actually booted into this system.

mkfs.ext3 /dev/sdb2
mkdir -p /mnt/backup/dest
mount /dev/sdb2 /mnt/backup/dest
Code:

(cd / ; find . -xdev -print0 | rsync -xavz . /mnt/backup/dest)
You can repeat similar for all partitions but, you don't need to copy any swaps. Just create the swap parition and format it.
For example:
/sbin/mkswap /dev/sdb3

You will need to tell grub to use the new drive. For example:
grub-install /dev/sdb

When you remove the first drive and boot into the new drive, you may just get a grub prompt like this...
grub>

That's ok, just tell grub where to look for your boot information. On my box, I don't have a separate /boot partition so, I would just do this...
grub > root (hd0,1)
grub > setup (hd0)
grub > reboot

That should get you started.

ricbax 12-14-2006 11:42 PM

What if the the drive being backed up /dev/hda is located in Logical Volume Manager (LVM)?

Quote:

mkfs.ext3 /dev/sdb2
mkdir -p /mnt/backup/dest
mount /dev/sdb2
Can you please clarify this for me more, I fail to see the distinction between /dev/sda1 and /dev/sdb2

homey 12-15-2006 11:24 AM

I don't know much about LVM, haven't used it.
Here are a couple of tutes which may help you.

http://forums.fedoraforum.org/showthread.php?t=41706
http://www.ibiblio.org/pub/Linux/doc...LVM-HOWTO.html

ricbax 12-15-2006 05:14 PM

Quote:

grub-install /dev/sdb
After executing this command I get the following error:

/dev/sdb does not have any corresponding BIOS drive.

ricbax 12-16-2006 04:46 PM

Quote:

Originally Posted by ricbax
After executing this command I get the following error:

/dev/sdb does not have any corresponding BIOS drive.

The command below stopped the error message above:

Code:

grub-install --recheck /dev/sdb

Ok so every thing was copied to /dev/sdb ... grub now knows the drive exists. However, when I disconnect the old /dev/sda and reboot, /dev/sdb defaults to /dev/sda.

So when it boots now it hangs just before the GRUB Loader. I know you say to do the following:

Quote:

That's ok, just tell grub where to look for your boot information. On my box, I don't have a separate /boot partition so, I would just do this...
grub > root (hd0,1)
grub > setup (hd0)
grub > reboot
I however do have a /boot partition. So how do I fix it so it boots?

homey 12-16-2006 05:54 PM

I'm sorry that someone with experience in LVM doesn't jump in here to help.
My system doesn't use a /boot partition and I have a storage partition up front. That's why my grub uses root (hd1,1) when loaded on sdb and root (hd0,1) when loaded on sda .

At anyrate, your /boot partition is likely /dev/sda1 . In grub speak, that is root (hd0,0)

Also, if you created a new /boot partition, if the /etc/fstab uses a LABEL=boot or similar then, you need to use the e2label command to give the boot partition a unique label.
For example:
e2label /dev/sda1 /boot
The /etc/fstab might look like this...
Code:

LABEL=/boot            /boot                  ext3    defaults        1 2
The grub.conf actually uses the /boot partition as root.
So, you might try this command.

grub > root (hd0,0)
grub > setup (hd0)
grub > reboot

homey 12-17-2006 03:39 AM

Ok, I thought may I'd give it a try and loaded up FC6 on a 40gig drive using LVM .
Then, I moved it to a 80gig drive.

You may be tempted to use a thingy called pvmove but, I wouldn't recommend that unless you have a special insite on how to use it or your are into some sort of self abuse.
About half an hour for a empty swap partition ( and still not done ) convinced me to try something else.

I did some modifications to the notes at http://forums.fedoraforum.org/showthread.php?t=41706 and here is what I came up with and it worked for me.

The original 40gig drive is sda
/dev/sda1 ----> /boot
/dev/sda2 ----> VolGroup00
Inside VolGroup00 is Log_Swap and LogVol00

On the new drive, I created a different Volume Group so it wouldn't conflict with the existing one.
/dev/sdb1 ----> /boot2
/dev/sdb2 ----> VolGroup01
Inside VolGroup01 is Log_Swap and LogVol00


# Partition new hard drive
fdisk /dev/sdb

The setup for the partitions should be:

primary partition 1 (/boot) - this is a standard linux partition (id 83). I made it 100MB, you can pick whatever.

primary partition 2 (for LVM) - the rest of the disk space. Regardless of how you want your partitions set up, this is the rest of the disk space. You can change the type to 8e (lvm) if you want, although I think that is only required if you are using LVM1.

# Format /boot
mkfs.ext3 /dev/sdb1
e2label /dev/sdb1 /boot2

# Setup lvm
pvcreate /dev/sdb2
vgcreate VolGroup01 /dev/sdb2
vgchange -a y VolGroup01

# Add logical volumes to it.

lvcreate -L 600 -n Log_Swap VolGroup01

(repeat as needed for other partitions)

# Then, a root volume filling the rest of the disk:

vgdisplay VolGroup01 | grep "Total PE"

# A single line should be displayed: "Total PE" and then a number.
# Use this number in the next command:
# Use a lower case L ( l ) this time.
lvcreate -l (Whatever Total PE was) -n LogVol00 VolGroup01

#Note: If that pops an error about the size, use the number which it gives you.

# The logical volumes are created as: /dev/(volume group name)/(logical volume name)
# Now format the other partitions you created.

mkswap /dev/VolGroup01/Log_Swap
mkfs.ext3 /dev/VolGroup01/LogVol00

# Mount the new partitions

mkdir /mnt/new_boot /mnt/new_root
mount /dev/sdb1 /mnt/new_boot
mount /dev/VolGroup01/LogVol00 /mnt/new_root

# Copy over your existing files using rsync or cp
rsync -xav / /mnt/new_root
rsync -xav /boot/* /mnt/new_boot
# cp -xav / /mnt/new_root
# cp -xav /boot/* /mnt/new_boot

# Edit the /mnt/new_root/etc/fstab
Code:

/dev/VolGroup01/LogVol00 /                      ext3    defaults        1 1
LABEL=/boot2            /boot                  ext3    defaults        1 2
/dev/VolGroup01/Log_Swap swap                  swap    defaults        0 0

# The LABEL= comes from using the e2label on partitions.

# Edit the /mnt/new_boot/grub/grub.conf to add the the new image:
# In this case, root (hd0,0) is where the /boot folder is located.
Code:

splashimage=(hd0,0)/grub/splash.xpm.gz
title Fedora Core (2.6.18-1.2849.fc6)LVM
  root (hd0,0)
  kernel /vmlinuz-2.6.18-1.2849.fc6 ro root=/dev/VolGroup01/LogVol00 rhgb quiet
  initrd /initrd-2.6.18-1.2849.fc6.img

# Install grub on the new drive.
grub-install /dev/sdb

# Remove the original drive and make sure the bios properly detects the new drive.

# NOTE: The new system may not boot until you reinstall initrd as follows.
# Bootup with CD#1 into linux rescue and mount the LVM system

# Chroot to new drive
chroot /mnt/sysimage
cd boot
# Use the initrd numbers which you have on your system.
mkinitrd -v -f initrd-2.6.18-1.2849.fc6.img 2.6.18-1.2849.fc6

# This would be a good time to make sure grub is setup for this drive.
grub
grub> root (hd0,0)
grub> setup (hd0)

exit
exit

ricbax 12-17-2006 08:29 PM

This looks fantastic ... I thank you for taking the time to do this and posting it. I have been fiddling all weekend trying to get this to work.

I will give this a try over the next couple of days and let you know how it goes.

Thanks again!!

homey 12-17-2006 10:38 PM

You're welcome! I hope it works for you.

My next project just may be to try install several distros on individual lv 's inside one LG . It should work pretty similar to my grub-multi-boot cdrom from awhile back.
Each distro uses the /boot and has a copy of it's vmlinuz and initrd ( with unique names ) in the /boot.

/dev/sda1 ----> /boot
/dev/sda2 ----> VolGroup00
Inside VolGroup00 ----->
/dev/VolGroup00/Log_Swap
/dev/VolGroup00/fc6_rt
/dev/VolGroup00/next_dist_rt
/dev/VolGroup00/another_dist_rt
/dev/VolGroup00/yet_another_dist_rt

ricbax 12-18-2006 09:11 PM

I followed your instructions this evening and everything is now moved to the new drive and it works & boots splendidly.

There are however some tiny omissions in your excellent instructions.

1) It does not explain how to set the /boot2 partition to an active state (I used Knoppix and QTparted)
but after I realized fdisk -a /dev/sdb1 should do the same?

2)When you are talking about editing fstab and grub.conf ... these files have to be edited on the mounts for the new drive "/mnt/new_boot" and the references to the old drive have to be commented out or deleted.
  • vi /mnt/new_boot/etc/fstab
  • vi /mnt/new_boot/boot/grub/grub.conf

Once again thank you! I hope many benefit from this.

homey 12-18-2006 10:59 PM

Great! glad it worked for you.

Sometimes I get so used to doing things that I forget to explain what I did. :)

Anyway, I'm glad you were able to figure things out.

Edit:
vi /mnt/new_boot/etc/fstab

the fstab to be edited is on /mnt/new_root


All times are GMT -5. The time now is 01:06 AM.