LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-09-2016, 11:54 AM   #1
granfran
Member
 
Registered: Jun 2015
Posts: 33

Rep: Reputation: Disabled
Cloning OS Partition


I am trying to clone my OS partitions and having problems.

I have a USB device with approximately 7 G used for linux OS and the rest unused. I am trying to clone the OS partitions so that I can have bootable clone of the OS. When I use the dd command, it reports that the partition is full, even though it is not. Below is the command I am running

Code:
root@debian:/# dd if=/dev/sda5 of=/dev/sdc5 conv=noerror,sync

dd: writing to /dev/sdc5: No space left on device
20481+0 records in
20480+0 records out
10485760 bytes (10 MB) copied, 0.0445032 s, 236 MB/s

Code:
Disk /dev/sda: 119.3 GiB, 128043712512 bytes, 250085376 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
Disklabel type: dos
Disk identifier: 0x55eaxxxx

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *          64   851967   851904  416M 17 Hidden HPFS/NTFS
/dev/sda2         854014 15632383 14778370    7G  5 Extended
/dev/sda5         854016 14925823 14071808  6.7G 83 Linux
/dev/sda6       14927872 15632383   704512  344M 82 Linux swap / Solaris

Code:
Disk /dev/sdc: 14.9 GiB, 16013852672 bytes, 31277056 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
Disklabel type: dos
Disk identifier: 0x55ea6695

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sdc1  *        64   851967   851904  416M 17 Hidden HPFS/NTFS
/dev/sdc2       854014 15632383 14778370    7G  5 Extended
/dev/sdc5       856064 14929000 14072937  6.7G 83 Linux
Thanks in advance for help.

Last edited by granfran; 10-09-2016 at 11:55 AM.
 
Old 10-09-2016, 06:41 PM   #2
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
Looking at /dev/sdc you have windows, an extended partition and Linux all on that device.
How many gig's is the usb flash drive?

Maybe give Clonezilla a try. Sorry I can't help you with dd, I've never used it.
http://clonezilla.org/
 
Old 10-09-2016, 06:50 PM   #3
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
sdc has 14.9 gig capacity. The NTFS partition was created by the bootable USB creator tool that I used to make a Linux Live install from USB. I tried clonezilla, but the destination device is not bootable. I assume this is because when doing a partition clone (as opposed to a full disk clone), clonezilla does not seem to be able to clone the MBR.
 
Old 10-09-2016, 07:15 PM   #4
Ztcoracat
LQ Guru
 
Registered: Dec 2011
Distribution: Slackware, MX 18
Posts: 9,484
Blog Entries: 15

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
I looked up the man page for dd and your cmd is correct.

Your sdc2 and your sdc5 is already taking up 13.7 G's of space on that device.
Even if you removed the Windows partition you would only have 1.2 G's left.

I wonder if it's hitting a bad sector on the flash drive causing it to say it's full when it's not?

-::-Maybe try another usb device and see if you still get "no space left on device"-::-

http://www.linuxquestions.org/questi...em-4175584311/

Last edited by Ztcoracat; 10-09-2016 at 07:44 PM.
 
Old 10-09-2016, 10:23 PM   #5
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Not sure I follow. Sdc5 is a new 6.7 G partition created with fdisk. Shouldn't the dd command allow copying up to 6.7 G of data on sdc5?
 
Old 10-09-2016, 10:43 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Quote:
Originally Posted by granfran View Post
Not sure I follow. Sdc5 is a new 6.7 G partition created with fdisk. Shouldn't the dd command allow copying up to 6.7 G of data on sdc5?
Welll... usually. Note that the number 6.7G are rounded off. Sizes slightly less than the source partition will also show up as 6.7G.

It is ALSO possible (unlikely though) that dd copied the last block to the destination, and saw that the output is full - but has not checked the input for more data yet.

More likely, the last block just didn't get written.

You can verify the sizes by looking at /proc/partitions. If the two values match I would expect this to work. If they DON'T match (which I expect) then the destination partition is a bit too small.
 
Old 10-09-2016, 10:55 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,568

Rep: Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093
Quote:
Originally Posted by jpollard View Post
Welll... usually. Note that the number 6.7G are rounded off. Sizes slightly less than the source partition will also show up as 6.7G.
If you look at the number of sectors, you will see that sdc5 is actually slightly larger than sda5.

Quote:
Originally Posted by granfran View Post
Not sure I follow. Sdc5 is a new 6.7 G partition created with fdisk. Shouldn't the dd command allow copying up to 6.7 G of data on sdc5?
Did you perhaps get that "The kernel still uses the old table" warning from fdisk? What does /proc/partitions show as the partition sizes?
 
Old 10-09-2016, 11:23 PM   #8
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
Did you perhaps get that "The kernel still uses the old table" warning from fdisk? What does /proc/partitions show as the partition sizes?
No, I did not get this message. Here are the relevant partition sizes from /proc/partitions :


8 1 425952 sda1
8 5 7035904 sda5
8 6 352256 sda6

8 33 425952 sdc1
8 34 1 sdc2
8 37 7036468 sdc5
 
Old 10-09-2016, 11:25 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Yup. Which is why I suggested looking at /proc/partitions for what the size is.

And the shown size SHOULD have worked. And we go back to a device error. Specially since it only copied about 10MB worth of data.

Last edited by jpollard; 10-09-2016 at 11:30 PM.
 
Old 10-10-2016, 12:03 AM   #10
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Yup. Which is why I suggested looking at /proc/partitions for what the size is.

And the shown size SHOULD have worked. And we go back to a device error. Specially since it only copied about 10MB worth of data.
I may have figured out the problem (but not the solution). Previously, I cloned the MBR from sda to sdc, attempting to clone the partitions. Now, when I run fsck, it reports "bad magic number...".

Is there a better way to clone the partitions including the boot record (without cloning the entire drive) ?
 
Old 10-10-2016, 08:17 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
The problem is that the MBR is first 446 bytes long. Following that is the partition table.

NOTE: grub2 doesn't install well on partitions (not meaning that it can't be done or will not work). The MBR is expected in block 0 of the device. Grub legacy didn't have a problem with this.

I use tar to make backups of partitions. It only copies used data, and allows the choice of fileystem type for restoring. You do have to re-install the boot code/MBR afterwards.

Cloning partitions works best if the partition is dismounted or mounted read only.
 
Old 10-10-2016, 08:22 AM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,568

Rep: Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093
Quote:
Originally Posted by granfran View Post
I may have figured out the problem (but not the solution). Previously, I cloned the MBR from sda to sdc, attempting to clone the partitions. Now, when I run fsck, it reports "bad magic number...".

Is there a better way to clone the partitions including the boot record (without cloning the entire drive) ?
Copying the MBR just gets you the primary partitions. The layout of the logical partitions within the extended partition is stored within the extended partition itself.

You can use sfdisk to clone the entire partition structure.
Code:
sfdisk -d /dev/sdX | sfdisk /dev/sdY
Note that sfdisk does not copy the MBR exactly. It substitutes a new, random disk identifier (32-bit word at offset 0x1b8). MS Windows will see it as a different disk and refuse to boot from it.
 
Old 10-10-2016, 09:28 AM   #13
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
You can use sfdisk to clone the entire partition structure.
Code:
sfdisk -d /dev/sdX | sfdisk /dev/sdY
Note that sfdisk does not copy the MBR exactly. It substitutes a new, random disk identifier (32-bit word at offset 0x1b8). MS Windows will see it as a different disk and refuse to boot from it.
Thanks. So, after running sfdisk, would running dd to copy the first 446 bytes make it bootable ?
 
Old 10-10-2016, 10:07 AM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,568

Rep: Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093Reputation: 2093
Quote:
Originally Posted by granfran View Post
Thanks. So, after running sfdisk, would running dd to copy the first 446 bytes make it bootable ?
It will make the disk identifier match what the cloned Windows installation has in its Boot Configuration Database. Without that match, Windows can't identify its own disk and will refuse to boot.

Many boot loaders (including GRUB) can live in the "unused" space between the MBR and the start of the first partition. If you haven't copied that area, you might not have a bootable disk. AFAIK, the standard Windows boot loader does not use that area.
 
Old 10-10-2016, 10:16 AM   #15
granfran
Member
 
Registered: Jun 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
Many boot loaders (including GRUB) can live in the "unused" space between the MBR and the start of the first partition. If you haven't copied that area, you might not have a bootable disk. AFAIK, the standard Windows boot loader does not use that area.

I am trying to boot to linux-not Windows, but not sure why the first partition is NTFS (I used a Live pendrive utility to make the source disk bootable). How would I correctly clone the space between the MBR and start of the 1st partition to make the clone bootable? Thanks
 
  


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
[SOLVED] (Fedora) Cloning boot partition dereism Linux - Newbie 5 02-21-2013 07:25 AM
cloning linux partition to different laptop, invalid partition table dsollen Linux - Software 8 11-23-2009 08:50 PM
Cloning an active partition? kmand Linux - Software 2 11-22-2007 11:59 AM
Partition cloning using dd greenberet Linux - Software 2 04-06-2007 06:20 AM
Moving/cloning partition LeftyAce Debian 17 01-13-2006 03:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:24 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
Open Source Consulting | Domain Registration