cloning linux partition to different laptop, invalid partition table
Linux - SoftwareThis 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.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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:
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
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.
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.
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?
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
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:
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...
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
Booting 'Red Hat Enterprise Linux Client (2.6.18-92.Eel5)'
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.
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
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.
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.
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
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.
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.