LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-11-2016, 07:34 AM   #1
bfzhou
Member
 
Registered: Feb 2008
Posts: 45

Rep: Reputation: 0
Cool 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.
 
Old 02-11-2016, 07:37 AM   #2
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,959

Rep: Reputation: Disabled
You do not need to worry about this, just boot from another media, mount the source and destination and use cp -a.
 
Old 02-11-2016, 07:44 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,540

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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.
 
Old 02-11-2016, 01:24 PM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,627

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
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.
 
Old 02-11-2016, 02:44 PM   #5
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 5,959

Rep: Reputation: Disabled
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.
 
Old 02-11-2016, 06:37 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,733

Rep: Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752Reputation: 1752
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.
 
Old 02-16-2016, 12:47 PM   #7
bfzhou
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
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.
 
Old 03-16-2016, 01:18 AM   #8
bfzhou
Member
 
Registered: Feb 2008
Posts: 45

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by malekmustaq View Post
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
 
Old 03-16-2016, 11:00 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,154
Blog Entries: 4

Rep: Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717Reputation: 2717
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.
 
Old 03-16-2016, 11:59 AM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
Quote:
Originally Posted by malekmustaq View Post
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.
 
  


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
Copy a script in /bin/ directory during installation. gaurav_s Linux - Software 4 12-20-2015 11:53 AM
[SOLVED] How do I copy root the file system of an internal hdd to a usb hdd completelinuxnube Slackware 8 08-06-2012 02:22 PM
if any utility available for copy one HDD to two more HDD simultaneously? mdfakkeer Linux - General 3 02-07-2010 06:07 AM
Anyone know of a readily available hdd to hdd copy utility? lumix Linux - Software 1 03-29-2007 11:57 AM
Can't copy to another hdd tct1501 Linux - General 2 02-10-2005 01:33 PM


All times are GMT -5. The time now is 01:39 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration