LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-19-2009, 04:34 PM   #1
dsollen
Member
 
Registered: Jun 2009
Posts: 56

Rep: Reputation: 15
cloning linux partition to different laptop, invalid partition table


I'm trying to clone a Linux install to a different laptop. It's made a little complicated by two facts:

1) The 'new' laptop I'm trying to copy my Linux installation to is actually older and has a smaller hard drive then the computer I’m copying from

2) The computer I'm copying from has both a windows and Linux installation; I only care about the Linux partition.

I did some research and found an article here http://www.roer.com/node/503. To my surprise I even understood what the commands were doing.

I figured I would copy only the Linux partition from my primary computer to the laptop, sense the laptop doesn’t have a large enough hard drive to copy everything. So I used the DD commands to copy SDA3 (main Linux partition) from my main computer to SDA2 of my laptop. When I came back a few hours later I was surprise to find my laptop trying to reboot itself (I never turned it off). It would keep starting to reboot, failing, and restarting itself. Not too surprising sense its boot partition wasn't changed so it's trying to boot into centos when I copied a redhat partition to it.

The problem is that when I used a redhat boot disk the rescue mode was unable to find a Linux partition to mount. /dev/sda2 exists, but trying to mount it gets the complaint "No such file or directory”.

“fdisk –l” lists sda1 (the boot sector) and sda2. Sda2 is the correct size and reports Linux LVM for its system. But “fdisk -l /dev/sda2” gives the error message "Disk /dev/sda2 doesn’t contain a valid partition table"

So what has happened? Did I not clone the drive correctly, or was an error caused due to the boot sector not being copied yet (the laptops boot sector is smaller then my old computers, so I can’t copy from old computer to laptop)? Can I salvage the laptops partition table somehow, or do I have to repeat the cloning process? And if I do have to re-clone my computer can anyone tell me what I did wrong the first time so it works this time?

I don't care if I copy just the Linux partition or both windows and Linux. Even though my main computer has a larger hard drive I'm only using about half of its available space so it should be possible to copy both partitions if I could ignore the unused sections of the harddrive.

And allow me to offer a preemptive thank you for your answers

Edit: I used DD to copy a tiny part of the Linux partition from my laptop so I could look at it. Most of it is illegible binary of course, but I scrolled through till I found some text right near the beginning:

Code:
VolGroup00 {
id="F2MWxh-....-BidcLe"
seqno = 1
status = ["RESIZEABLE", "READ", "WRITE"]
extent_size=65536
max_lv =0
max_pv=0

pysical_volumes {
pv0{
id = "NyiuBh-....-Y5aVdx"
device="/dev/sda3"

status = ["ALLOCATABLE"]
dev_size=117001395
pe_start = 384
pe_count=1785
}
}
So it seems that the DD command did copy everything over to the laptop, which is good to know. I noticed that it says device="/dev/sda3" right in the middle of the code I just posted. The Linux section of my original computer was SDA3 but I copied it to partition SDA2 of my laptop. So is the problem because the boot partition is for the wrong device? I don't suppose if I modified that one line to say SDA2 it would be able to load correctly? (Not that I know how I would modify the line, short of using the DD command again).

Last edited by dsollen; 11-19-2009 at 04:55 PM. Reason: adding more detail
 
Old 11-19-2009, 07:08 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
There is probably a friendlier way to do this, but this is what I'd probably do in your position:

Dump the boot sector to a file boot.sec, and hack it by hand. You'll probably figure out what you need to change by comparing the partition entries on the two drives and reading some howtos. Then dd the boot.sec file you've changed back to the drive with the messed up boot sector.

Alternate idea:
On the target machine, create a partition of the same size and type as the image you're trying to clone. Then dd the image of the source filesystem to that same location on the target. This way the existing boot sector will already contain the correct information for the file-system you're trying to copy. This obviously involves some extra work, though -- first creating a filesystem, then recopying the image over in its place.
 
Old 11-19-2009, 07:21 PM   #3
yancek
Senior Member
 
Registered: Apr 2008
Distribution: PCLinux, Ubuntu, Slackware
Posts: 4,667

Rep: Reputation: 730Reputation: 730Reputation: 730Reputation: 730Reputation: 730Reputation: 730Reputation: 730
Does the laptop you are cloning TO have an operating system?
If so, what is it?
If not, you copied a partition (sda3) from your old drive and that will not include the master boot record which is outside all partitions.
When you use your Red Hat CD, you need to do "mkdir /mnt/linux" to create the mount point for Red Hat to mount sda2. Then, to mount: mount -t ext3 /dev/sda2 /mnt/linux


Your references in /etc/fstab file will be to sda3, from the partition you copied from, so they need to be changed.
Your boot files will also refer to sda3 or, in Grub (hd0,2).
What distribution of Linux are you using?
What were you planning to boot with, Grub? Which Grub do you have?
 
Old 11-19-2009, 08:39 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,067

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Regardless of what the [otherwise excellent] thread on dd in this forum tells you, using dd to clone a installation which on a disk which is not virgin and not identical to you source is a bad idea.

The steps to take are in general:

- make your new system accessible by booting from a live CD or whatever.
- create Linux partition(s) on the new hardware.
- mount the new partition(s) under say /mnt/hda1
- copy the old partitions using rsync while working on the new machine:
Code:
rsync --exclude='/proc' --exclude='/sys' -auv my.old.machine:/ /mnt/hda1
- make the new disk bootable by install grub using grub-install. For this last point dozens of articles were written, I won't repeat that here.

jlinkels
 
Old 11-20-2009, 09:02 AM   #5
dsollen
Member
 
Registered: Jun 2009
Posts: 56

Original Poster
Rep: Reputation: 15
Okay I used jlinkels suggestion; after I figured out how to partition my hardrive correctly I ran rsync. When I boot into rescue mode with the redhat CD it is unable to auto-detect my Linux installation, but I can manually mount sda2 (that's a step in the right direction!).

I ran grub-installer /dev/sda and receive the error "the file /boot/grub/stage1 not read correctly” same thing if I use grub-installer hd0.

I ran grub and tried the “find /boot/grub/stage1” command and get a File not found error, however “find /grub/stage1” returns (hd0,0). I tried this...

Code:
root (hd0,0)
setup (hd0)
Which seemed to work. When I reboot I get the standard message saying it will boot to redhat in 3 seconds (although its a purely text message, no redhat background I’m use to seeing). If I let it try to boot redhat it fails. If I hit enter at that screen I can choice to boot redhat or 'other'. I didn't copy the windows partition so I don't know what ‘other’ option would be, it fails to boot also.

when it tries to boot I receive the following message
Code:
Booting 'Red Hat Enterprise Linux Client (2.6.18-92.Eel5)'
root (hd0,1)
 Filesystem type unkown, partition type 0x8e
kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

Error 17: Cannt mount selected partition
Anyways I'm still playing with grub. I'll let you know if I figure anything else out

edit: oh quick note. when I ran the "root (hd0,0)" command it reports "Filesystem type is ext2fs, partition type 0x83". The ext2fs part didn't seem right, but I'm not really sure. Is it possible I didn't partition the sda2 correctly? I deleted and repartitioned sda2 and ran mkfs on it, I didn't do anything to sda1.

Last edited by dsollen; 11-20-2009 at 09:11 AM.
 
Old 11-20-2009, 10:52 AM   #6
dsollen
Member
 
Registered: Jun 2009
Posts: 56

Original Poster
Rep: Reputation: 15
and yet another update, I've made some progress at least.

first I found one thing that was interesting. I got accidently got a bit recrusive and tried mounting the /dev/sda2 folder when it was already mounted and set as root, and was surprised to get a error message reporting /dev/sda2 was mounted to /boot. I checked /ect/mtab and sure enough /boot maps to /dev/sda2 (the boot sector on my old computer). The /boot folder looks like a boot partition, but /dev/sda2 was is the primary linux partition on my laptop. I figured the problem is due to my copying the boot folder from my old computer instead of actually mounting /dev/sda1. I changed mtab to map /boot to /dev/sda1 and I deleated all the old stuff in /boot and properly mounted /dev/sda1 in it. I then re-ran the grub-installer and this time it gave me a more promissing message. I figure grub was modifying the /boot folder from my old computer rather then /dev/sda1 all this time.

right before doing that I had mounted /dev/sda1 and modified the grub/menu.lst file. I changed root (hd0,1) to root(hd0,0).

I don't know which of the changes did it but now I'm get farther in the bootup process. The first few steps are fine, then I start getting error messages
Code:
unable to access resume device (/dev/VolGroup00/LogVol01)
mount: could not find filesystem '/dev/root'
setuproot: moving /dev failed: no such file or directory
setuproot: error mounting /proc: No such file or directory
""                         /sys  ""
switchroot: mount failed: No such file or diretory
Kernel panic - not syncing: attempted to kill init!
I'm suspecting that the complaints about /dev /sys and /proc are due to my mtab file having wrong data, sort of like it had the wrong values for /boot. From what I can tell /proc is trying to mount /dev/proc which dosn't exist, but that seems odd. I suppose my next step will be to figure out what those three folders are used for (still a newbie here!) and fix their values in mtab and see if that has any effect.
 
Old 11-20-2009, 10:57 AM   #7
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 201Reputation: 201Reputation: 201
FSArchiver allows support for imaging a partition and restoring it to a different partition size and even a different file system type. It's available on the systemrescuecd as well. It's a live cd so you can use it to image your boot and root partitions. It's a simple one line command to image/restore. Really nice tool.
 
Old 11-23-2009, 08:41 AM   #8
dsollen
Member
 
Registered: Jun 2009
Posts: 56

Original Poster
Rep: Reputation: 15
Thank you for your reply. I tried fsarchiver but it is causing me trouble too. It seems to be confused by my logical volumes...maybe. On my computer architecture I have 3 partitions, with the third partitions containing two sub partitions

sda1=windows
sda2=/boot
sda3=Linux LVM:
__ volgroup00=root partition
__ volgroup01=swap

I can't backup /dev/sda3 because "can't detect and mount file system of partition /dev/sda3". I assume that's because it is a Linux LVM? I can back up logical volume 00 but not 01(presumably because it's swap).

So the question is what do I have to back up? Would just saving sda2 and volgroup00 do it? Do you know if the program is smart enough to put the computer together from just that? Or would I need the windows partition to make the boot partition make sense? Would sda1, sda2, and volgorup00 be enough? My main concern is I don't understand how logical volumes work so I don't know where all their metadata is contained…


I also ran into another problem that I know should be easy to fix but I'm too much of a newbie to know how. I don't have space to save the backup (I’m using the live cd). I (don't think) I can save it to sda3 because I'm trying to back sda3 up, I figure I'll either get an error or a recursive process that eats up all my space. I don't have any other partitions and I doubt my 2 gb thumb drive will be large enough to save the file. I tried using a named pipe to pipe the archive file over the network as it was created (like I did with the dd), but that doesn’t seem to work. Whenever I give the fsarchiver my named pipe as an argument it tries saving to /pipe.fsa rather then sending its output through the pipe. I know logical volumes can be resized so I guess I could create a third logical partition just to contain my archive file but I'm already doing alot of things I only sort of understand and I really don't want to add another step that I could mess up to the process.


Incidentally just to see what would happen I tried a full DD of sda to another computer with a larger hardrive. Even that gives me almost the exact same errors as I was getting with the laptop. Is cloning a computer really this hard or am I just technically incompetent?

oh I should mention I'm pretty sure the logical volumes are the reason I can't get the laptop to work. fstab shows / as LogVol00 but no VolGroup shows in /dev. in fact on the laptop I can mount /dev/sda3, which I can't do on the original computer. I'm guessing the DD command somehow messed up the metadata for the logical volume so it's being treated as normal partition instead. In fact come to think of it I wonder what would happen if I changed grub and fstab to reference sda3 as if it was a regular partition and ignore the swap volume. Proubly wouldn't work but might be interesting to se what does heppen.

Last edited by dsollen; 11-23-2009 at 08:51 AM.
 
Old 11-23-2009, 08:50 PM   #9
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 201Reputation: 201Reputation: 201
I won't pretend to have ever tried any of this...........I use fsarchiver to image / /home partitions on each system once I have all the bits and pieces just the way I want them, and I've only used it to restore back to the original machine.........in other words no lvm's and no cloning to date, but a little exploring found http://www.sysresccd.org/Sysresccd-L...ckups-with-LVM and what appears to be a good explanation of how to backup an lvm using fsarchiver and it would follow then restore it.

I'm pretty sure also that with teh sysresccd you can
A.) mount any optical drives you might have, or
B.) use smb to simply write the .fsa file to another machine.

I personally sacrifice a small partition to install sysresccd to the harddrive and store my backups there as well, but I'm sure I'm probably using a simpler configuration.
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
raid 5 invalid partition table wjtaylor Linux - Server 12 09-08-2009 05:15 AM
Invalid partition table on one computer, not on another dcroxton Linux - Hardware 6 06-24-2007 06:35 AM
Help --> Invalid Partition Table? doody Linux - Newbie 8 09-01-2004 01:33 AM
Invalid Partition Table xiojqwnko Slackware 2 04-04-2004 05:27 PM
invalid partition table MunterMan Linux - Software 3 11-26-2003 02:45 PM


All times are GMT -5. The time now is 02:27 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