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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
07-10-2010, 12:24 PM
|
#1
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Rep:
|
Need more details on how to clone a larger disk to smaller with cp
I need to clone a 160GB hard drive with Linux Mint 9 (not more than 10GB used) to a 30GB SSD that is partitioned carefully (aligned to cylinder boundaries) and is currently running Ubuntu (which I wish to overwrite with Linux Mint 9).
The SSD has a /boot partition, / and swap. The source (160 GB) does not have a separate boot partition.
Can anyone help me fill in the steps below? /dev/sdc will be the source (160GB) and /dev/sda is the target (with partitions 1,2 and swap on 5).
- make a copy of /etc/fstab from the target drive before proceeding.
- Ready the target partitions. Can I reuse the existing destination partitions on the SSD?
- Ready the filesystems on each of the target partitions. /boot is ext2, / is ext4 and swap is already set up too. As I said, all contain data (Ubuntu) that I wish to overwrite. So what steps are needed here? Do I need to erase anything (files, etc.) before the copy/clone?
- next, use dd to copy MBR (right?) And exclude partition table:
Code:
dd if=/dev/sdc1 of=/dev/sda1 count=1 bs=446
- Mount the source and destination drives:
Code:
mount -t ext4 /dev/sdc1 /mnt/source
mount -t ext2 /dev/sda1 /mnt/boot_target
mount -t ext4 /dev/sda2 /mnt/root_target
- I suppose I can leave the swap partition on the target untouched.
- Copy the files from the source partition to the destination
Code:
cp -a /mnt/source/boot /mnt/boot_target
cp -a /mnt/source/ /mnt/root_target
- then I assume I go to /mnt/root_target and delete the /boot directory, right?
- Change /etc/fstab to reflect the new partitions. I mount by label. Will my partition labels be intact after this?
- Do I have to make any changes to GRUB? Anything else?
|
|
|
|
07-10-2010, 12:39 PM
|
#2
|
|
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,792
|
Quote:
Originally Posted by Mountain
I suppose I can leave the swap partition on the target untouched.
|
You have to do mkswap and swapon -a if you have not done so.
Quote:
Originally Posted by Mountain
Copy the files from the source partition to the destination
|
I would prefer rsync
Code:
rsync -uav /mnt/source/boot/ /mnt/boot_target
Note the trailing slash in the source path! Using rsync in this way all permissions and attributes are preserved.
Sometimes I see the copying of the MBR fail in the way you describe. It doesn't do any harm if you do it, but if it doesn't work, use grub-install --recheck /dev/sda
jlinkels
|
|
|
1 members found this post helpful.
|
07-10-2010, 01:23 PM
|
#3
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
Thank you. In regard to my other questions, can you offer any guidance? Or were all my other assumptions correct? (which would be surprising)
|
|
|
|
07-10-2010, 04:03 PM
|
#4
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
still hoping someone with experience can reply to my questions before I start. I don't want to have to learn the hard way by screwing this up.
My remaining questions are:
- Can I reuse the existing destination partitions on the SSD?
- Do I need to erase anything (files, etc.) before the copy/clone? (e.g. rm -rf /mnt/target)
- when and from what operating system would I run mkswap and swapon -a? Would I have to do this after booting into the newly copied OS?
- Am I doing the right thing to move the source /boot directory into the target boot partition?
- Will my partition labels be intact after this?
- Do I have to make any changes to GRUB? Anything else?
- When and from where would I run grub-install --recheck /dev/sda? After booting into new OS?
Thanks!
Last edited by Mountain; 07-11-2010 at 01:40 AM.
|
|
|
|
07-11-2010, 02:28 PM
|
#5
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
well, I had the choice to wait for a reply (which might not ever come) or push forward and try it. So I pushed forward (while continuing to seek answers in other places, of course).
Unfortunately, on boot I now get the grub_rescue prompt. Not sure where things went wrong...
|
|
|
|
07-11-2010, 03:10 PM
|
#6
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
I got a little further, but I appear to have hit a grub problem. Now, on booting up, I get this message:
ALERT! /dev/disk/by-uuid/xxxx-xxx-xxx-xx does not exist. Dropping to a shell.
The shell prompt is (intramfs)
running blkid shows my "/" partition as expected and my swap partition.
Neither have the UUID referred to in the error message, of course. My /etc/fstab mounts "/" and swap by label.
The offending UUID is listed in grub.cfg. But I'm not sure how to get rid of it.
Doing the dd clone of the whole disk was a lot easier because I didn't have to deal with any of this. But dd takes about 8 hours. If I can solve this problem and make the rsync cloning work, it will only take 7 minutes.
(If anyone wants to help me solve this, I'll post a script when I'm done, fwiw.)
Last edited by Mountain; 07-11-2010 at 03:12 PM.
|
|
|
|
07-11-2010, 03:27 PM
|
#7
|
|
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,792
|
Mounting by UUID nowadays is preferred over labels altough there is nothing wrong with labels.
Find the UUID's of your new disk (blkid) and insert them in your fstab. A line line this should look like:
Code:
UUID=a81275ab-290c-4c7c-9fea-f9d0a888cdeb / ext3 defaults 0 1
The UUID for the boot partition must be specified in grub.cfg as you noted correctly. Also in fstab for all partitions that you want to mount.
jlinkels
|
|
|
1 members found this post helpful.
|
07-11-2010, 03:35 PM
|
#8
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
Find the UUID's of your new disk (blkid) and insert them in your fstab. A line line this should look like:
|
I need to do the opposite. I need to remove grub2's use of UUID's. How?
grub.cfg on my target filesystem lists a UUID that doesn't exist. That's the problem I need to solve. How do I reinstall grub in a way that prevents it from using the wrong UUID -- or any UUID at all. grub2 has the option to search by label instead of UUID. I just can't figure it out.
Last edited by Mountain; 07-11-2010 at 03:44 PM.
|
|
|
|
07-11-2010, 05:50 PM
|
#9
|
|
Member
Registered: Apr 2010
Distribution: Debian
Posts: 39
Rep:
|
When you boot up and get to the grub menu just press 'e'. Then you can edit it. For now I would suggest forgetting about the UUID and just specify the the disk directly. So you can try to get into your new install.
It should look something like this
menuentry "Debian" {
set root='(hd0,X)'
linux /boot/bzImage-2.6.34 root=/dev/sdaX
}
It will have more but those are the two lines you need to edit. The first you just need to replace the X with the partition number you have have /boot in. For the second replace the X with the partition number you installed / to. Which I think should be 1 & 2 respectively.
If that works then you should get into your new installation. But this is just a temporary fix. You will have to edit the proper config files then run update-grub2 to install it. The config file is in /etc/grub.d/ but the files might differ on different distros. If you just jot down everything you see when you are editing the grub menu down and put it in a file called say 40_custom in the /etc/grub.d/ directory and make it executable (chmod +x 40_custom). Then run update-grub2 it should work.
Last edited by gammahermit; 07-11-2010 at 05:59 PM.
|
|
|
|
07-11-2010, 05:54 PM
|
#10
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
It seems like grub2 and UUIDs are the Achilles heel in the process of using cp or rsync to clone a drive.
The only way I can see to resolve this is to make the filesystem using the old (source) UUID on the new (target) partition. That's not what I really want to do...
|
|
|
|
07-11-2010, 06:20 PM
|
#11
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
Quote:
Originally Posted by gammahermit
When you boot up and get to the grub menu just press 'e'.
|
I can't seem to get a grub menu, even holding down the space bar.
The shell prompt is (intramfs)
|
|
|
|
07-11-2010, 06:22 PM
|
#12
|
|
Member
Registered: Apr 2010
Distribution: Debian
Posts: 39
Rep:
|
You can move the installation to a new disk. I have done it a couple times. I just create a new partition on the new disk and copied the files over. Then edited some files and it worked. So you can do it, but you can run into some trouble on the way. And there is no point copying the firs 446 bytes of the MBR. There is nothing there that needs to be copied over. Just start fresh.
|
|
|
|
07-11-2010, 06:27 PM
|
#13
|
|
Member
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 213
Original Poster
Rep:
|
Quote:
Originally Posted by gammahermit
You can move the installation to a new disk. I have done it a couple times. I just create a new partition on the new disk and copied the files over. Then edited some files and it worked. So you can do it, but you can run into some trouble on the way. And there is no point copying the firs 446 bytes of the MBR. There is nothing there that needs to be copied over. Just start fresh.
|
Thanks, but for the record, this isn't a solution to the problem I posted at the start of this thread. I don't want people to think this solves it for me because I'm not interested in doing a fresh install (in this context).
I'm trying to clone an existing install.
|
|
|
|
07-11-2010, 06:27 PM
|
#14
|
|
Member
Registered: Apr 2010
Distribution: Debian
Posts: 39
Rep:
|
Try pressing ESC right when grub starts up. That should allow you to see the menu.
|
|
|
|
07-11-2010, 06:39 PM
|
#15
|
|
Member
Registered: Apr 2010
Distribution: Debian
Posts: 39
Rep:
|
I wasn't saying do a fresh Install. But just setup the new hard drive from scratch. Setup the partitions put a filesystem on them. Then copy all the files over to it.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:39 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|