Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Other Operating Systems

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 17th December 2013, 3:48 PM   #1
Oblong Cheese Thread Starter
Member
 
Oblong Cheese's Avatar
 
Join Date: Aug 2001
Location: Brisbane
Posts: 10,288
Default Correct method to clone a disk using dd

Hi all,

My scenario is as follows: I am upgrading my HTPC by installing an SSD for the operating system and moving all media files to my NAS.

So, I currently have Mythbuntu installed on a 750Gb disk. I want to move that install onto an SSD of 60Gb in size.

My approach is as follows:
  1. Move existing media files off filesystem and resize to <60Gb
  2. Connect new SSD and boot into LiveCD environment
  3. Copy partition: dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror
  4. Copy boot sector: dd if=/dev/sda of=/dev/sdb bs=512 count=1
  5. Finished!

My approach does not work. What I end up with (sometimes) is even though the partition sda1 is exactly 50Gb in size, the full 60Gb of the SSD is used, and I do not have an sdb1 partition at all - instead, I simply have /dev/sdb, which can be mounted and read as a filesystem, but gparted can't understand it (cannot see space used on it, and I assume also cannot safely resize it). Also it is not bootable.

I have learnt since trying this morning that the Linux kernel caches the state of partition tables on disks, so I will need to force a re-read after step four by
Code:
partprobe /dev/sdb
(which probably explains why subsequent dd commands result in an error about the disk being full)

Is this all I need? Or am I approaching this completely incorrectly? I have previously dd'd whole disks, but that was when increasing in size, which allowed me to copy the entire drive sector by sector.
__________________
My Website | My Computers | Grado Labs Alessandro MS-1, Shure SRH-840, Topping TP30

Last edited by Oblong Cheese; 17th December 2013 at 3:51 PM.
Oblong Cheese is offline   Reply With Quote

Join OCAU to remove this ad!
Old 17th December 2013, 4:13 PM   #2
shift
Member
 
shift's Avatar
 
Join Date: Jul 2001
Location: Hillcrest, Logan
Posts: 2,901
Default

More likely to work if you swap the order of step 3 and step 4. You seem to be using the partition before you've created it.

Whenever I've done it, I create new partitions and copy file-wise rather than use dd, then manually reinstall the bootloader.
__________________
"The best thing about the internet is you can make up anything." - Gandhi
"Mit der Dummheit kämpfen Götter selbst vergebens" (Against stupidity the gods themselves struggle in vain.) - Friedrich Schiller
shift is offline   Reply With Quote
Old 18th December 2013, 9:13 AM   #3
samarium
Member
 
Join Date: Jun 2007
Posts: 470
Default

Copying the boot sector using dd also copies the primary partition table. Not a good idea given the disks are different.

I usually use a method similar to above by shift.
samarium is offline   Reply With Quote
Old 18th December 2013, 10:39 AM   #4
^catalyst
Member
 
^catalyst's Avatar
 
Join Date: Jun 2001
Location: melbourne
Posts: 10,831
Default

Good time to export all your configs and do a nice clean install
^catalyst is offline   Reply With Quote
Old 18th December 2013, 11:35 AM   #5
w0ng
Member
 
Join Date: Dec 2006
Posts: 45
Default

  1. Move existing media files off filesystem and resize to <60Gb
  2. Connect new SSD and boot into LiveCD environment
  3. Copy all partitions and bootloader:
    Code:
    dd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror
  4. Update fstab entries to point to SSD
  5. Update bootloader to point to SSD
  6. Finished!
w0ng is offline   Reply With Quote
Old 18th December 2013, 11:39 AM   #6
Oblong Cheese Thread Starter
Member
 
Oblong Cheese's Avatar
 
Join Date: Aug 2001
Location: Brisbane
Posts: 10,288
Default

Thanks guys for your input, I finally got it sorted.

What I ended up doing:
  1. Create new partition table on SSD
  2. Create new /dev/sdb1 partition of exact required size
  3. dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror
  4. Install SSD into system, boot Ubuntu LiveCD and repair it with Boot Repair
  5. Finished!

My problem when playing around before was that, as mentioned above, dd'ing the first 512 bytes was also dd'ing the MBR, which doesn't work.
__________________
My Website | My Computers | Grado Labs Alessandro MS-1, Shure SRH-840, Topping TP30
Oblong Cheese is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

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 On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!