How can I move a single partition to another empty drive?











up vote
2
down vote

favorite












I've got a partition P1 (which contains my Linux OS) on a drive A.



I've just gotten a completely new drive B (that is larger than partition P1 AND the entire drive A).



I'd like to copy across the partition from drive A to drive B, and possible resize it later on.



Can this be done with dd? I could easily create a new parition table on drive B, and just cp the files across - but this seems like it might be slightly slower due to the filesystem overhead.





Output of `parted --list`:


It would be the partition 4 that I want to copy to another drive.



Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 1049kB 1031kB BIOS boot partition bios_grub
2 1049kB 1074MB 1073MB fat32 EFI System boot, esp
3 1075MB 183GB 181GB ext4 Linux filesystem
4 183GB 250GB 67.5GB ext4 Basic data partition


Please ignore any reference to the boot drive / functionality (which I'll worry about later on) - keeps this question concise.










share|improve this question
























  • Favour returned! Question upvoted! ;-)
    – Fabby
    Nov 21 at 21:45















up vote
2
down vote

favorite












I've got a partition P1 (which contains my Linux OS) on a drive A.



I've just gotten a completely new drive B (that is larger than partition P1 AND the entire drive A).



I'd like to copy across the partition from drive A to drive B, and possible resize it later on.



Can this be done with dd? I could easily create a new parition table on drive B, and just cp the files across - but this seems like it might be slightly slower due to the filesystem overhead.





Output of `parted --list`:


It would be the partition 4 that I want to copy to another drive.



Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 1049kB 1031kB BIOS boot partition bios_grub
2 1049kB 1074MB 1073MB fat32 EFI System boot, esp
3 1075MB 183GB 181GB ext4 Linux filesystem
4 183GB 250GB 67.5GB ext4 Basic data partition


Please ignore any reference to the boot drive / functionality (which I'll worry about later on) - keeps this question concise.










share|improve this question
























  • Favour returned! Question upvoted! ;-)
    – Fabby
    Nov 21 at 21:45













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I've got a partition P1 (which contains my Linux OS) on a drive A.



I've just gotten a completely new drive B (that is larger than partition P1 AND the entire drive A).



I'd like to copy across the partition from drive A to drive B, and possible resize it later on.



Can this be done with dd? I could easily create a new parition table on drive B, and just cp the files across - but this seems like it might be slightly slower due to the filesystem overhead.





Output of `parted --list`:


It would be the partition 4 that I want to copy to another drive.



Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 1049kB 1031kB BIOS boot partition bios_grub
2 1049kB 1074MB 1073MB fat32 EFI System boot, esp
3 1075MB 183GB 181GB ext4 Linux filesystem
4 183GB 250GB 67.5GB ext4 Basic data partition


Please ignore any reference to the boot drive / functionality (which I'll worry about later on) - keeps this question concise.










share|improve this question















I've got a partition P1 (which contains my Linux OS) on a drive A.



I've just gotten a completely new drive B (that is larger than partition P1 AND the entire drive A).



I'd like to copy across the partition from drive A to drive B, and possible resize it later on.



Can this be done with dd? I could easily create a new parition table on drive B, and just cp the files across - but this seems like it might be slightly slower due to the filesystem overhead.





Output of `parted --list`:


It would be the partition 4 that I want to copy to another drive.



Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 1049kB 1031kB BIOS boot partition bios_grub
2 1049kB 1074MB 1073MB fat32 EFI System boot, esp
3 1075MB 183GB 181GB ext4 Linux filesystem
4 183GB 250GB 67.5GB ext4 Basic data partition


Please ignore any reference to the boot drive / functionality (which I'll worry about later on) - keeps this question concise.







partition dd move-partition






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 21:17

























asked Nov 21 at 19:46









Chris Stryczynski

469317




469317












  • Favour returned! Question upvoted! ;-)
    – Fabby
    Nov 21 at 21:45


















  • Favour returned! Question upvoted! ;-)
    – Fabby
    Nov 21 at 21:45
















Favour returned! Question upvoted! ;-)
– Fabby
Nov 21 at 21:45




Favour returned! Question upvoted! ;-)
– Fabby
Nov 21 at 21:45










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Yes ,that's what dd is for. Assuming:





  • sxb is the drive to copy from


  • sxc is the drive to copy to


  • sxb4 is the fourth partition on the second drive that you want to copy from


  • sxc1 is the partition you've created to be of equal size to sxb4


do :



    parted /dev/sxc
GNU Parted 3.2
Using /dev/sxc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 0.0 67.5GB
(parted) quit

dd if=/dev/sxb4 of=/dev/sxc1 bs=16M


As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:



e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random


if sxbis an old drive and you expect it to have read errors, use ddrescue instead.



Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...






share|improve this answer























  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
    – Chris Stryczynski
    Nov 21 at 21:03








  • 1




    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
    – Fabby
    Nov 21 at 21:11












  • Many thanks, I've updated it now.
    – Chris Stryczynski
    Nov 21 at 21:18






  • 1




    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
    – Fabby
    Nov 21 at 21:41










  • I've just done it! Thanks for pointing me in the right direction though.
    – Chris Stryczynski
    Nov 21 at 21:44











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',
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%2f483288%2fhow-can-i-move-a-single-partition-to-another-empty-drive%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








up vote
2
down vote



accepted










Yes ,that's what dd is for. Assuming:





  • sxb is the drive to copy from


  • sxc is the drive to copy to


  • sxb4 is the fourth partition on the second drive that you want to copy from


  • sxc1 is the partition you've created to be of equal size to sxb4


do :



    parted /dev/sxc
GNU Parted 3.2
Using /dev/sxc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 0.0 67.5GB
(parted) quit

dd if=/dev/sxb4 of=/dev/sxc1 bs=16M


As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:



e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random


if sxbis an old drive and you expect it to have read errors, use ddrescue instead.



Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...






share|improve this answer























  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
    – Chris Stryczynski
    Nov 21 at 21:03








  • 1




    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
    – Fabby
    Nov 21 at 21:11












  • Many thanks, I've updated it now.
    – Chris Stryczynski
    Nov 21 at 21:18






  • 1




    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
    – Fabby
    Nov 21 at 21:41










  • I've just done it! Thanks for pointing me in the right direction though.
    – Chris Stryczynski
    Nov 21 at 21:44















up vote
2
down vote



accepted










Yes ,that's what dd is for. Assuming:





  • sxb is the drive to copy from


  • sxc is the drive to copy to


  • sxb4 is the fourth partition on the second drive that you want to copy from


  • sxc1 is the partition you've created to be of equal size to sxb4


do :



    parted /dev/sxc
GNU Parted 3.2
Using /dev/sxc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 0.0 67.5GB
(parted) quit

dd if=/dev/sxb4 of=/dev/sxc1 bs=16M


As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:



e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random


if sxbis an old drive and you expect it to have read errors, use ddrescue instead.



Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...






share|improve this answer























  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
    – Chris Stryczynski
    Nov 21 at 21:03








  • 1




    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
    – Fabby
    Nov 21 at 21:11












  • Many thanks, I've updated it now.
    – Chris Stryczynski
    Nov 21 at 21:18






  • 1




    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
    – Fabby
    Nov 21 at 21:41










  • I've just done it! Thanks for pointing me in the right direction though.
    – Chris Stryczynski
    Nov 21 at 21:44













up vote
2
down vote



accepted







up vote
2
down vote



accepted






Yes ,that's what dd is for. Assuming:





  • sxb is the drive to copy from


  • sxc is the drive to copy to


  • sxb4 is the fourth partition on the second drive that you want to copy from


  • sxc1 is the partition you've created to be of equal size to sxb4


do :



    parted /dev/sxc
GNU Parted 3.2
Using /dev/sxc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 0.0 67.5GB
(parted) quit

dd if=/dev/sxb4 of=/dev/sxc1 bs=16M


As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:



e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random


if sxbis an old drive and you expect it to have read errors, use ddrescue instead.



Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...






share|improve this answer














Yes ,that's what dd is for. Assuming:





  • sxb is the drive to copy from


  • sxc is the drive to copy to


  • sxb4 is the fourth partition on the second drive that you want to copy from


  • sxc1 is the partition you've created to be of equal size to sxb4


do :



    parted /dev/sxc
GNU Parted 3.2
Using /dev/sxc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sxc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 0.0 67.5GB
(parted) quit

dd if=/dev/sxb4 of=/dev/sxc1 bs=16M


As that will duplicate the UUID of the partition, in order to change the UUID of the new partition (make sure the partition is not mounted) run the following:



e2fsck -f /dev/sxc1
tune2fs /dev/sxc1 -U random


if sxbis an old drive and you expect it to have read errors, use ddrescue instead.



Note: as dd is known as disk destroyer, and creating a partition table is dangerous, not putting the exact command in the above as some random idiot on the Internet might see this question and copy-paste the codez without understanding what it does...







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 23:10

























answered Nov 21 at 20:53









Fabby

3,11411127




3,11411127












  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
    – Chris Stryczynski
    Nov 21 at 21:03








  • 1




    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
    – Fabby
    Nov 21 at 21:11












  • Many thanks, I've updated it now.
    – Chris Stryczynski
    Nov 21 at 21:18






  • 1




    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
    – Fabby
    Nov 21 at 21:41










  • I've just done it! Thanks for pointing me in the right direction though.
    – Chris Stryczynski
    Nov 21 at 21:44


















  • Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
    – Chris Stryczynski
    Nov 21 at 21:03








  • 1




    Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
    – Fabby
    Nov 21 at 21:11












  • Many thanks, I've updated it now.
    – Chris Stryczynski
    Nov 21 at 21:18






  • 1




    Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
    – Fabby
    Nov 21 at 21:41










  • I've just done it! Thanks for pointing me in the right direction though.
    – Chris Stryczynski
    Nov 21 at 21:44
















Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
– Chris Stryczynski
Nov 21 at 21:03






Good to hear, I guess the only issue is I'm not sure how to create a partition with the exact same size? Is the 'size' the 'difference' between the start/end blocks of the partition?
– Chris Stryczynski
Nov 21 at 21:03






1




1




Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
– Fabby
Nov 21 at 21:11






Yes, correct. And if you edit your question and provide the output of parted --list and leave another comment, I'll add that bit too. 0:-)
– Fabby
Nov 21 at 21:11














Many thanks, I've updated it now.
– Chris Stryczynski
Nov 21 at 21:18




Many thanks, I've updated it now.
– Chris Stryczynski
Nov 21 at 21:18




1




1




Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
– Fabby
Nov 21 at 21:41




Urgh. Sorry: need it in bytes to be exact... sudo parted /dev/sdb unit B p @ChrisStryczynski
– Fabby
Nov 21 at 21:41












I've just done it! Thanks for pointing me in the right direction though.
– Chris Stryczynski
Nov 21 at 21:44




I've just done it! Thanks for pointing me in the right direction though.
– Chris Stryczynski
Nov 21 at 21:44


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483288%2fhow-can-i-move-a-single-partition-to-another-empty-drive%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

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt