[SOLVED] parted 2.3: moving a partition in a disk with master boot record
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
parted 2.3: moving a partition in a disk with master boot record
Hi: I have the root partition in sda1 and would like to move it to a logical partition. To simplify, lets assume the target partition is primary too. Assume I issue the command
move 1 400GB 420GB
What shall it exactly do? Parted knows where partition 1 starts and ends. So it would move the 1st sector to offset 400GB with respect to sector 0, or some sector whose offset is nearly 400GB, the 2nd sector to 400GB + 4096 and so on. But does it also modify the partition table accordingly? If so, how does parted know the new partition is primary? Perhaps it does nothing but move the sectors. In which case I then issue a
mkpart primary 400GB 420GB or, in my case,
mkpart logical 400GB 420GB (I already have an extended partition created).
Is this the way I should do it? Another question: what happens to the original partition. I take it it will appear as free space for cfdisk.
to be honest, I don't have answers to your particular questions.
But I'm wondering. I'm wondering why you do it that complicated.
Quote:
Originally Posted by stf92
Hi: I have the root partition in sda1 and would like to move it to a logical partition.
I see. And the easiest way I can think of is to use your favorite partitioning tool (parted, gparted, fdisk) and create the new partition, then use 'dd' to duplicate the data from the original partition into the new one.
You'll have to update GRUB then (or whatever bootloader you're using) to be able to boot from the new partition.
Should I write bs=512 or bs=4096? I think it's bs=512, because 39070017*512 =aprox 20GB, which the space I have allocated for partition 1.
yes, you're right. Physically, your HDD may be formatted to a sector size of 4k (probably is). It's obvious that the performance is best if read or write operations exactly fit the physical sector boundaries.
But partitioning and most file systems assume a logical sector size of 512 bytes, and so in this context the block size is usually 512 bytes.
To be honest, I still would like to use parted. Parted is smarter than dd. With dd I could very well do a mess of it all. The only thing is I don't know how exactly to use it. There's is a lot about parted on the internet but nowhere have I found an exact procedure to move partitions.
To make things less complicated why not just create the new partition, format it, mount it and then copy the data. Using the -rp options will perform recursive copy and keep the same permissions. Update the bootloader as required.
There are ways to change the partition table to change partition numbers or convert primary to logical without actually moving data but not recommended for the newbie.
I understand. After, copying 9GB can't take too long. By the way, where in the disk is listed the starting sector of partition 5. It can't be in the MBR, nor in any of the partitions. So perhaps in some place in track 0?
EDIT: it seems that the extended boot record (EBR), which contains the data about the location of a logical partition, is located at the beginning of the extended partition. I wonder, when a partitioning program gives the start of a logical partition, is it the location of the EBR or the location of the partition data? Example: if fdisk says
Code:
Device Boot Start End Blocks Id System
/dev/sda1 * 63 39070079 19535008+ 83 Linux
Partition 1 does not start on physical sector boundary.
/dev/sda2 39071744 39276543 102400 7 HPFS/NTFS/exFAT
/dev/sda3 39276544 100511743 30617600 7 HPFS/NTFS/exFAT
/dev/sda4 100511744 976773167 438130712 f W95 Ext'd (LBA)
/dev/sda5 100513792 292968447 96227328 83 Linux
/dev/sda6 292970496 332050431 19539968 83 Linux
is 292970496 the offset of the EBR of partition 6 or the EBR of the data in partition 6?
The EBR is located on the very first sector of an otherwise unused area which is equal to the number of sectors per track; normally, 63 sectors. In this regard, each logical partition mimicks the layout of a hard disk's structure for its first primary partition, since the MBR is located on the very first sector of the disk, the first sector of Track 0 (normally followed by 62 unused sectors) and then the boot sector of its first primary partition.
So I interpret that (along with the top part of the article) to mean that your 292970496 is the sector offset of the EBR for partition 6, not the beginning of the file system you write there. But there's other information in the article you could use to verify. In the table entitled, "Common Structure of Extended Boot Records," it says the byte offsets 1FE - 1FF within the EBR have the signature 0x55AA in big endian order (55 then AA).
At 1c6 is part 5 offset, 0800 (2048 dec). Now, 100511744 + 2048= 100513792, which is exactly the number given by 'print free' in the entry for partition 5. Also the sizes can be seen to agree. So, the offset given by parted is not that of the EBR but that of the partition itself.
In case anyone cares, the job of copying an entire partition to another one is best done with parted in the following way: type 'parted -a optimal'. Suppose you want to copy partition 1 to partition 6. All you have to do is type 'cp /dev/sda 1 6', assuming the disk is /dev/sda.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.