Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] cloning multi-partitioned system to larger HDD
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
angry_arctic_avian
n00b
n00b


Joined: 24 Oct 2009
Posts: 59

PostPosted: Wed Feb 27, 2013 9:14 pm    Post subject: [Solved] cloning multi-partitioned system to larger HDD Reply with quote

I am trying to clone my almost entire Gentoo install onto a larger hard drive. I followed a partitioning scheme similar to what was suggested by the installation guide from the website. My installation is currently is divded onto two 40GB hard drives, with /home occupying the slave drive. I wish to clone only the first hard drive onto a 160GB drive. This is how /dev/sda is partitioned:

Code:

fdisk -l /dev/sda

Disk /dev/sda: 41.2 GB, 41174138880 bytes
255 heads, 63 sectors/track, 5005 cylinders, total 80418240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8e3bad33

    Device   Boot        Start                  End              Blocks      Id       System
/dev/sda1      *              63            144584              72261      83      Linux
/dev/sda2              144585         3309389           1582402+   82      Linux swap / Solaris
/dev/sda3            3309390       52484354         24587482+   83      Linux
/dev/sda4          52484355       80405324         13960485       5      Extended
/dev/sda5          52484418       53223344             369463+   83      Linux
/dev/sda6          53223408       74204234         10490413+   83      Linux
/dev/sda7          74204298       80405324           3100513+   83      Linux


Sorry for the format of that ouput, as that was typed and not copied and pasted. / resides on /dev/sda3, /tmp resides on /dev/sda5, /usr resides on /dev/sda6 and /var is on /dev/sda7. I have been researching this issue for a bit now, and have read much on using dd, parted, resize2fs and Clonezilla. I have successfully used dd to copy an Windows XP installation for a friend. Of course their OS was divided up like mine is.

Right now, I want to try to clone and resize the partitions using command-line tools on a LiveCD, before giving up and trying to use Clonezilla. Though, I am currently uncertain about a few things, hence why I am typing this post. I have read that just outright dd'ing one drive to the other would make it only possible to resize the last partition. I wish to resize sda3(/) and each logical partition within the extended one. /boot and swap will remain the same. I guess my questions would be as followed:
1. Would it be possible to dd each partition individually and resize them before moving onto the next?

2. Would I have to pre-partition the target drive before cloning?

3. My First attempt to copy the MBR to the target drive

Code:

dd if=/dev/sda of=/dev/sdb bs=512 count=1
fdisk -l /dev/sdb


showed only sdb1, sdb2, sdb3, sdb4. Would I first have to create this partition table with fdisk, and then only copy the first 446 bytes of the MBR with dd in order to recognize these logical partitions?

4. Would I have to do anything different with resizing an extended partion and its logical partitions?

Sorry for the multiple questions in this one post. This road block has left me with only ideas of what to do, and I am trying to get some feed back as to whether or not I am on the right track. I kind of regret making my partition scheme like this, especially when /usr and /var started filling up. It is the first of my two Gentoo installations, and I felt like experimenting at the time.


Last edited by angry_arctic_avian on Thu Mar 07, 2013 7:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
Quincy
Apprentice
Apprentice


Joined: 02 Jun 2005
Posts: 201
Location: Germany

PostPosted: Wed Feb 27, 2013 9:43 pm    Post subject: Reply with quote

If the system is fully only Linux it is quite easy:

- Boot from a live CD (Important! It does not work when the system itself is running)
- Partition the target drive as you like
- Create file systems on the new drive
-,Mount old and new partitions and copy data using "cp -a"
- Finally get your boot manager running as you did when installing from within a chroot

I think this will circumvent all your problems/questions because it is fully flexible.
Back to top
View user's profile Send private message
robdd
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jan 2005
Posts: 142
Location: Sydney Australia

PostPosted: Sun Mar 03, 2013 8:13 am    Post subject: Reply with quote

Hi aaavian,

The tool I would use is dump/restore - it's originally an old Unix tool to dump and restore to tape because that was the way things were backed up when I was a lad. But it's perfect for copying Linux partitions because it knows about dev and proc and won't try to copy them as regular files.

So here's how I would do it:

1) Emerge dump (latest version I'm using is app-arch/dump-0.4.44-r1)- that also loads restore.

2) Use fdisk to create the partitions on the new 160Gb drive. It may cause problems if you've already dd'd the partition table from a different size disc, so clear the first few dozen sectors by dd'ing from /dev/zero (dd if=/dev/zero of=/dev/sdX bs=1M, then kill it with Ctrl-C after a short delay) and write a new one with fdisk. Linux doesn't care if partitions are primary or extended, so just decide what layout you want.

3) You can do the copies while you're current system is running, but best to go to single-user mode where almost nothing else is running (as root type "shutdown now", and wait until it says you're in single user mode).

4) Prepare each partition on the new disc by doing a mkfs.ext3 (or ext2 or ext4 - I don't think restore supports other filesystem types, but good old ext3 works for me every time). Then mount each new partition on your current system at a suitable mount point, e.g. /mnt/new_part (you'll have to make a directory in /mnt with the name you want to use, or use an existing sub-directory in /mnt). Probably better to do one partition at a time, and keep notes of where you are. Less chance os screwing up that way. And you should certainly make sure you have backups of all your valuable data.

5) Copy across each partition. You can either dump to a file on a backup disc first (which is good if you want to keep backups anyway), or you can copy directly by piping the output of dump straight into restore.

Let's say you want to copy from /dev/sda1 mounted on / to /dev/sdc1 mounted on /mnt/new_part - you type

Code:

cd /mnt/new_part
dump -0 -f - / | restore -rvf -


Leave out the "v" if it's a big partition, otherwise the listing of files will slow down the actual copy. For other partitions you have to specify the current mount point to dump, e.g. if you do sda2 next and it's mounted on /usr you'll need to specify "/usr" instead of "/".

6) The tricky part is getting your new /etc/fstab right - if you moved partitions around you'll have to edit fstab to make sure each new partition is allocated to the correct mount point. And don't forget you can check your work before re-plugging the disc drives - if you edit the "new" fstab to show the current disc name (e.g. change all the references from "old" sda to "new" sdc) you can use grub to boot off sdc amd make sure everything copied OK.

Also, don't forget that as a short term expedient you can always move directories across partitions using tar and soft links. For example, if you load some sotware packages that live in /opt and your / (root) partition is nearly full while you have lot's of room in a separate /home partition you can tar up /opt (best in single-user mode again), untar it to /home/opt, and then "cd /;rm -rf /opt;ln -s /home/opt opt".

Any questions - don't hesitate to ask.

Regards,

Rob.

The only
_________________
Rob Diamond
Gentoo Hack, hack, hacker
Sydney, Australia
Back to top
View user's profile Send private message
angry_arctic_avian
n00b
n00b


Joined: 24 Oct 2009
Posts: 59

PostPosted: Thu Mar 07, 2013 7:14 pm    Post subject: Reply with quote

Thanks robdd and Quincy for the replies. Sorry it took so long to write back, due to work, illness, and the 136 package update I had put off due to starting this hard drive move.

I ended doing pretty much what Quincy suggested, although I used rsync instead of cp to make the copy. I did the partition table in a similar layout like the source hard drive, and copied the /boot, / and the logical partions to their correlating partition on the target drive. So far, I haven't encountered any problems after booting into the new disk. Thanks again for taking the time to reply.
Back to top
View user's profile Send private message
Quincy
Apprentice
Apprentice


Joined: 02 Jun 2005
Posts: 201
Location: Germany

PostPosted: Thu Mar 07, 2013 10:33 pm    Post subject: Reply with quote

Yes rsync was also an option, I'm using that pretty much for backups.
Good that it worked so well :-)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum