LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-13-2006, 10:37 AM   #1
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Rep: Reputation: 15
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
 
Old 12-13-2006, 11:38 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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.

Last edited by homey; 12-15-2006 at 12:34 PM.
 
Old 12-14-2006, 10:42 PM   #3
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
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

Last edited by ricbax; 12-15-2006 at 08:35 AM.
 
Old 12-15-2006, 10:24 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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
 
Old 12-15-2006, 04:14 PM   #5
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
grub-install /dev/sdb
After executing this command I get the following error:

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

Last edited by ricbax; 12-15-2006 at 04:15 PM.
 
Old 12-16-2006, 03:46 PM   #6
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
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?

Last edited by ricbax; 12-16-2006 at 03:48 PM.
 
Old 12-16-2006, 04:54 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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
 
Old 12-17-2006, 02:39 AM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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

Last edited by homey; 12-18-2006 at 10:39 PM.
 
Old 12-17-2006, 07:29 PM   #9
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
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!!
 
Old 12-17-2006, 09:38 PM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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
 
Old 12-18-2006, 08:11 PM   #11
ricbax
LQ Newbie
 
Registered: Dec 2003
Location: Canada
Distribution: Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
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.
 
Old 12-18-2006, 09:59 PM   #12
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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

Last edited by homey; 12-18-2006 at 10:01 PM.
 
  


Reply

Tags
migration, rsync


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rsync server vs rsync over ssh humbletech99 Linux - Networking 1 10-18-2006 12:10 PM
Rsync Entire Filesystem? sutley Linux - Newbie 4 10-04-2006 06:29 PM
DISCUSSION: Virtual Filesystem: Building a Linux Filesystem from an Ordinary File mchirico LinuxAnswers Discussion 0 10-28-2004 10:35 PM
Encrypted Root Filesystem HOWTO and /dev filesystem tmillard Linux From Scratch 0 10-18-2004 03:58 PM
Windows Rsync Upload to Linux Rsync - permissions inspleak Linux - Software 0 10-12-2004 02:49 PM


All times are GMT -5. The time now is 05:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration