copy installation from one HDD to another, which directory NOT to copy?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
copy installation from one HDD to another, which directory NOT to copy?
After my old drive with dual boot between OS X Snow Leopard and Fedora17 stopped booting up for a file corruption, I replaced it with a smaller hard drive) and installed Ubuntu.
Finally I managed to save all the data in the old drive. I then installed Ubuntu on it, wiping out the Fedora. The dual boot still work!
Since in between I have got a lot of work accumulated on the new hard drive, especially software installed and worked on, I would like to duplicate the whole system to the older, much larger disk while preserving the dual boot.
I wonder if I perform a directory by directory copy of files with 'cp -a', which directories should and and which should not be copied? Will copying /usr, /opt, and /var enough?
which directories should and and which should not be copied?
Answer: Copy /bin /home/ var/ boot/ etc/ lib/ opt/ root/ sbin/ usr/. No need copying /dev /lost+found /mnt/ proc/ run/ tmp/ media/ the system reads and creates them as they are found and needed or along the processes.
But... bear in mind what syg00 advised you above, saying: "I always reinstall the loader - just ain't worth the potential grief not to." So how and what to reinstall? Prepare it by copying the boot sector:
Quote:
dd if=/dev/sda of=mybootsector.img bs=512 count=1
copy the mybootsector.img to a safe place, two places if you want to have a spare if you accidentally deleted one by mistake. When time of need comes you restore it doing this
I disagree, there is no harm copying /dev /mnt/ proc/ run/ tmp/ media/, some distros may have a static device or two in /dev, not copying it will lead to trouble.
I agree that reinstalling the boot loader is the best choice. Just saving the MBR is not enough.
It depends on how the drive is partitioned i.e. legacy MBR or GPT and grub vs grub2. The MBR boot sector only contains a small part of grub. The core image is typically written to the spot in between the MBR and the first partition since it either starts at 63 or 1024 for alignment. If you want to use the dd command you need to save at least 512 + 31Kib. For GPT partitions it is possible to use a boot partition for the core image.
It worked and I could move all the current content to the larger drive !
However, buoyed by the success, I went one step further by resizing the extended partition hda2, and inserted a 40G space to copy a working Windows installation into it. But this turned out to be a bad idea. Not only does the windows not work, but my Ubuntu bootloader keeps rebooting the system. and it stays so even after deleting the inserted partition /dev/sda3 and resizing extended partition /dev/sda2. It seems I have to do a fresh installation again and then repeat the "cp -a" step before.
.. still learned a lot of good lessons. Will report back when I'm done.
Answer: Copy /bin /home/ var/ boot/ etc/ lib/ opt/ root/ sbin/ usr/. No need copying /dev /lost+found /mnt/ proc/ run/ tmp/ media/ the system reads and creates them as they are found and needed or along the processes.
But... bear in mind what syg00 advised you above, saying: "I always reinstall the loader - just ain't worth the potential grief not to." So how and what to reinstall? Prepare it by copying the boot sector:copy the mybootsector.img to a safe place, two places if you want to have a spare if you accidentally deleted one by mistake. When time of need comes you restore it doing thisDone. Reboot.
Good luck. Hope that helps.
I finally moved to my larger hdd, with only my hacking tosh and Ubuntu. In the cp process, I avoided copying /boot, also didn't restore the boot loader, as doing so made the laptop keep rebooting.
Next step will be to learn how to insert a win partition to enable a triple booting.
One thing that you definitely want to do is to set up Ubuntu to use LVM: Logical Volume Management. This allows you to treat the physical allocation of disk storage space separately from the apparent logical structure. So, you don't have to e.g. "change partition sizes." If you run out of space, you simply allocate a new partition (anywhere), introduce it to LVM, and then add it to the appropriate storage-pool. The somewhat-arcane commands are well described on the Internet.
But... bear in mind what syg00 advised you above, saying: "I always reinstall the loader - just ain't worth the potential grief not to." So how and what to reinstall? Prepare it by copying the boot sector:
Code:
dd if=/dev/sda of=mybootsector.img bs=512 count=1
copy the mybootsector.img to a safe place, two places if you want to have a spare if you accidentally deleted one by mistake. When time of need comes you restore it doing this
Code:
dd if=mybootsector.img of=/dev/sda
Done. Reboot.
Warning: Do not do that! While this will backup and restore the bootloader it will also backup and restore the partition table, which will mess up your system if both disks are not the same size and/or partitions on both disks are not in exactly the same place! If you want to backup/restore the bootloader use a blocksize of 446 bytes instead:
Code:
dd if=/dev/sda of=mybootsector.img bs=446 count=1
Also, keep in mind that this will not work with systems that use UEFI/GPT.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.