LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   copy installation from one HDD to another, which directory NOT to copy? (https://www.linuxquestions.org/questions/linux-newbie-8/copy-installation-from-one-hdd-to-another-which-directory-not-to-copy-4175571978/)

bfzhou 02-11-2016 07:34 AM

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?

thanks for sharing your insight.

Emerson 02-11-2016 07:37 AM

You do not need to worry about this, just boot from another media, mount the source and destination and use cp -a.

syg00 02-11-2016 07:44 AM

However you may need to be careful with fstab and the boot-loader. I always reinstall the loader - just ain't worth the potential grief not to.

malekmustaq 02-11-2016 01:24 PM

Quote:

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
Quote:

dd if=mybootsector.img of=/dev/sda
Done. Reboot.

Good luck. Hope that helps.

Emerson 02-11-2016 02:44 PM

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.

michaelk 02-11-2016 06:37 PM

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.

bfzhou 02-16-2016 12:47 PM

thanks so much for all the insight!

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.

bfzhou 03-16-2016 01:18 AM

Quote:

Originally Posted by malekmustaq (Post 5498723)
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.

Many thanks for all the insights!

Ben

sundialsvcs 03-16-2016 11:00 AM

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.

TobiSGD 03-16-2016 11:59 AM

Quote:

Originally Posted by malekmustaq (Post 5498723)
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.


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