How to clone an entire disk to a larger disk and then offload?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3














What I have done is clone a small 32GB flash module that had three partitions. I happened to have a 32GB USB lying around, so I thought it might just work; it did not. It seems 32GB from Toshiba is a bit different than 32GB from Sandisk.



Anyway, so then took to a 2TB external drive and did the exact same thing. Specifically, I did the following:



dd if=/dev/sdX of=/dev/sdY bs=100M



aside Does the final block come across as a partial copy or is it dropped if EOF is reached first?



So as to essentially clone the entire flash module -- partition table and all. The 32GB -> 2TB was easy enough since the dd utility properly halted after reading through the end of the final (third) partition.



So, what I want to do now is just create a simple binary blob containing the entire flash image. My 2TB drive is now identically partitioned with respect to the original drive: sdx1, sdx2, sdx3. So, once again I just took to dd with the following:



dd if=/dev/sdx of=firmware.bin bs=100M



Doing so will not only copy the first 32GB I am interested in, but it will also continue on through and clone the entire 2TB drive, or so it did when I tried it. I can find the exact byte-length of the partitions of interest by the following:



$ lsblk -b
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc 8:32 0 2000398933504 0 disk
├─sdc1 8:33 0 134217728 0 part
├─sdc2 8:34 0 2147483648 0 part
└─sdc3 8:35 0 29734297600 0 part


A definite way to solve this would be to set the blocksize of dd to one byte and then set the number of blocks to read as the sum of the three sizes above:



dd if=/dev/sdc of=firmware.bin bs=1 count=32015998976



But I can't image how long that would actually take.



EDIT: A quick test of curiosity of the above showed a solid ~150KB/s transfer rate.




tl;dr How can I exclusively copy the first three partitions of a disk that is much larger than the sum of the partition sizes?










share|improve this question























  • Any reason why not to make the block size 32015998976 and the count 1?
    – Anthon
    Mar 18 '16 at 16:48










  • @Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
    – sherrellbc
    Mar 18 '16 at 16:50











  • If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
    – Anthon
    Mar 18 '16 at 16:53










  • @Anthon, that was the next step if this question did not produce any simple solutions.
    – sherrellbc
    Mar 18 '16 at 16:56










  • If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
    – Anthon
    Mar 18 '16 at 16:58















3














What I have done is clone a small 32GB flash module that had three partitions. I happened to have a 32GB USB lying around, so I thought it might just work; it did not. It seems 32GB from Toshiba is a bit different than 32GB from Sandisk.



Anyway, so then took to a 2TB external drive and did the exact same thing. Specifically, I did the following:



dd if=/dev/sdX of=/dev/sdY bs=100M



aside Does the final block come across as a partial copy or is it dropped if EOF is reached first?



So as to essentially clone the entire flash module -- partition table and all. The 32GB -> 2TB was easy enough since the dd utility properly halted after reading through the end of the final (third) partition.



So, what I want to do now is just create a simple binary blob containing the entire flash image. My 2TB drive is now identically partitioned with respect to the original drive: sdx1, sdx2, sdx3. So, once again I just took to dd with the following:



dd if=/dev/sdx of=firmware.bin bs=100M



Doing so will not only copy the first 32GB I am interested in, but it will also continue on through and clone the entire 2TB drive, or so it did when I tried it. I can find the exact byte-length of the partitions of interest by the following:



$ lsblk -b
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc 8:32 0 2000398933504 0 disk
├─sdc1 8:33 0 134217728 0 part
├─sdc2 8:34 0 2147483648 0 part
└─sdc3 8:35 0 29734297600 0 part


A definite way to solve this would be to set the blocksize of dd to one byte and then set the number of blocks to read as the sum of the three sizes above:



dd if=/dev/sdc of=firmware.bin bs=1 count=32015998976



But I can't image how long that would actually take.



EDIT: A quick test of curiosity of the above showed a solid ~150KB/s transfer rate.




tl;dr How can I exclusively copy the first three partitions of a disk that is much larger than the sum of the partition sizes?










share|improve this question























  • Any reason why not to make the block size 32015998976 and the count 1?
    – Anthon
    Mar 18 '16 at 16:48










  • @Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
    – sherrellbc
    Mar 18 '16 at 16:50











  • If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
    – Anthon
    Mar 18 '16 at 16:53










  • @Anthon, that was the next step if this question did not produce any simple solutions.
    – sherrellbc
    Mar 18 '16 at 16:56










  • If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
    – Anthon
    Mar 18 '16 at 16:58













3












3








3







What I have done is clone a small 32GB flash module that had three partitions. I happened to have a 32GB USB lying around, so I thought it might just work; it did not. It seems 32GB from Toshiba is a bit different than 32GB from Sandisk.



Anyway, so then took to a 2TB external drive and did the exact same thing. Specifically, I did the following:



dd if=/dev/sdX of=/dev/sdY bs=100M



aside Does the final block come across as a partial copy or is it dropped if EOF is reached first?



So as to essentially clone the entire flash module -- partition table and all. The 32GB -> 2TB was easy enough since the dd utility properly halted after reading through the end of the final (third) partition.



So, what I want to do now is just create a simple binary blob containing the entire flash image. My 2TB drive is now identically partitioned with respect to the original drive: sdx1, sdx2, sdx3. So, once again I just took to dd with the following:



dd if=/dev/sdx of=firmware.bin bs=100M



Doing so will not only copy the first 32GB I am interested in, but it will also continue on through and clone the entire 2TB drive, or so it did when I tried it. I can find the exact byte-length of the partitions of interest by the following:



$ lsblk -b
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc 8:32 0 2000398933504 0 disk
├─sdc1 8:33 0 134217728 0 part
├─sdc2 8:34 0 2147483648 0 part
└─sdc3 8:35 0 29734297600 0 part


A definite way to solve this would be to set the blocksize of dd to one byte and then set the number of blocks to read as the sum of the three sizes above:



dd if=/dev/sdc of=firmware.bin bs=1 count=32015998976



But I can't image how long that would actually take.



EDIT: A quick test of curiosity of the above showed a solid ~150KB/s transfer rate.




tl;dr How can I exclusively copy the first three partitions of a disk that is much larger than the sum of the partition sizes?










share|improve this question















What I have done is clone a small 32GB flash module that had three partitions. I happened to have a 32GB USB lying around, so I thought it might just work; it did not. It seems 32GB from Toshiba is a bit different than 32GB from Sandisk.



Anyway, so then took to a 2TB external drive and did the exact same thing. Specifically, I did the following:



dd if=/dev/sdX of=/dev/sdY bs=100M



aside Does the final block come across as a partial copy or is it dropped if EOF is reached first?



So as to essentially clone the entire flash module -- partition table and all. The 32GB -> 2TB was easy enough since the dd utility properly halted after reading through the end of the final (third) partition.



So, what I want to do now is just create a simple binary blob containing the entire flash image. My 2TB drive is now identically partitioned with respect to the original drive: sdx1, sdx2, sdx3. So, once again I just took to dd with the following:



dd if=/dev/sdx of=firmware.bin bs=100M



Doing so will not only copy the first 32GB I am interested in, but it will also continue on through and clone the entire 2TB drive, or so it did when I tried it. I can find the exact byte-length of the partitions of interest by the following:



$ lsblk -b
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdc 8:32 0 2000398933504 0 disk
├─sdc1 8:33 0 134217728 0 part
├─sdc2 8:34 0 2147483648 0 part
└─sdc3 8:35 0 29734297600 0 part


A definite way to solve this would be to set the blocksize of dd to one byte and then set the number of blocks to read as the sum of the three sizes above:



dd if=/dev/sdc of=firmware.bin bs=1 count=32015998976



But I can't image how long that would actually take.



EDIT: A quick test of curiosity of the above showed a solid ~150KB/s transfer rate.




tl;dr How can I exclusively copy the first three partitions of a disk that is much larger than the sum of the partition sizes?







dd file-copy cloning disk-image






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 20 '18 at 7:24









Rui F Ribeiro

39k1479130




39k1479130










asked Mar 18 '16 at 16:33









sherrellbc

84331527




84331527











  • Any reason why not to make the block size 32015998976 and the count 1?
    – Anthon
    Mar 18 '16 at 16:48










  • @Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
    – sherrellbc
    Mar 18 '16 at 16:50











  • If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
    – Anthon
    Mar 18 '16 at 16:53










  • @Anthon, that was the next step if this question did not produce any simple solutions.
    – sherrellbc
    Mar 18 '16 at 16:56










  • If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
    – Anthon
    Mar 18 '16 at 16:58
















  • Any reason why not to make the block size 32015998976 and the count 1?
    – Anthon
    Mar 18 '16 at 16:48










  • @Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
    – sherrellbc
    Mar 18 '16 at 16:50











  • If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
    – Anthon
    Mar 18 '16 at 16:53










  • @Anthon, that was the next step if this question did not produce any simple solutions.
    – sherrellbc
    Mar 18 '16 at 16:56










  • If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
    – Anthon
    Mar 18 '16 at 16:58















Any reason why not to make the block size 32015998976 and the count 1?
– Anthon
Mar 18 '16 at 16:48




Any reason why not to make the block size 32015998976 and the count 1?
– Anthon
Mar 18 '16 at 16:48












@Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
– sherrellbc
Mar 18 '16 at 16:50





@Anthon, that working depends on it 'dd' first reads a block into memory before writing it, which the documentation seems to allude to. I certainly don't have 32GB of RAM to spare.
– sherrellbc
Mar 18 '16 at 16:50













If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
– Anthon
Mar 18 '16 at 16:53




If you are not into buying more memory, 32015998976 can be nicely factored into 2^13x13x300631. Surely you can come up with a combination of block size and count that will fit in memory and is more efficient.
– Anthon
Mar 18 '16 at 16:53












@Anthon, that was the next step if this question did not produce any simple solutions.
– sherrellbc
Mar 18 '16 at 16:56




@Anthon, that was the next step if this question did not produce any simple solutions.
– sherrellbc
Mar 18 '16 at 16:56












If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
– Anthon
Mar 18 '16 at 16:58




If you still have the original flash, wouldn't it be more easy to format the harddrive, mount it and then dd the flash to a file on the drive, possible one partition at a time?
– Anthon
Mar 18 '16 at 16:58










1 Answer
1






active

oldest

votes


















2














Just copy the partitions that you need and the MBR if you need it too.



The MBR is stored in the the first 512 bytes of the disk.



dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1


Copy each partition



dd if=/dev/sdX1 of=/path/to/partition1.img bs=512

dd if=/dev/sdX2 of=/path/to/partition2.img bs=512

dd if=/dev/sdX3 of=/path/to/partition3.img bs=512





share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f270715%2fhow-to-clone-an-entire-disk-to-a-larger-disk-and-then-offload%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Just copy the partitions that you need and the MBR if you need it too.



    The MBR is stored in the the first 512 bytes of the disk.



    dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1


    Copy each partition



    dd if=/dev/sdX1 of=/path/to/partition1.img bs=512

    dd if=/dev/sdX2 of=/path/to/partition2.img bs=512

    dd if=/dev/sdX3 of=/path/to/partition3.img bs=512





    share|improve this answer



























      2














      Just copy the partitions that you need and the MBR if you need it too.



      The MBR is stored in the the first 512 bytes of the disk.



      dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1


      Copy each partition



      dd if=/dev/sdX1 of=/path/to/partition1.img bs=512

      dd if=/dev/sdX2 of=/path/to/partition2.img bs=512

      dd if=/dev/sdX3 of=/path/to/partition3.img bs=512





      share|improve this answer

























        2












        2








        2






        Just copy the partitions that you need and the MBR if you need it too.



        The MBR is stored in the the first 512 bytes of the disk.



        dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1


        Copy each partition



        dd if=/dev/sdX1 of=/path/to/partition1.img bs=512

        dd if=/dev/sdX2 of=/path/to/partition2.img bs=512

        dd if=/dev/sdX3 of=/path/to/partition3.img bs=512





        share|improve this answer














        Just copy the partitions that you need and the MBR if you need it too.



        The MBR is stored in the the first 512 bytes of the disk.



        dd if=/dev/sdX of=/path/to/mbr_file.img bs=512 count=1


        Copy each partition



        dd if=/dev/sdX1 of=/path/to/partition1.img bs=512

        dd if=/dev/sdX2 of=/path/to/partition2.img bs=512

        dd if=/dev/sdX3 of=/path/to/partition3.img bs=512






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 18 '16 at 20:34

























        answered Mar 18 '16 at 20:29









        jc__

        1,408517




        1,408517



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f270715%2fhow-to-clone-an-entire-disk-to-a-larger-disk-and-then-offload%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?