LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-10-2014, 05:45 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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.

Last edited by stf92; 10-10-2014 at 05:47 AM.
 
Old 10-10-2014, 06:38 AM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

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 View Post
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.

[X] Doc CPU
 
1 members found this post helpful.
Old 10-10-2014, 06:53 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks for that. So, suppose this is my disk:

Code:
Partition Table for /dev/sda

         ---Starting----      ----Ending-----    Start     Number of
 # Flags Head Sect  Cyl   ID  Head Sect  Cyl     Sector    Sectors
-- ----- ---- ---- ----- ---- ---- ---- ----- ----------- -----------
 1  0x80    1    1     0 0x83  254   63  2431          63    39070017
 2  0x00   26   27  2432 0x07  217   13  2444    39071744      204800
 3  0x00  217   14  2444 0x07  144   32  6256    39276544    61235200
 4  0x00  144   33  6256 0x0F   80   15 60801   100511744   876261376
 5  0x00  177    2  6256 0x83  112   52 18236        2048   192454656
In order to move part 1 to part 5 I would issue
Code:
dd if=/dev/sda1 of=/dev/sda5 bs=some_number count=39070017
Regarding some_number, fdisk gives
Code:
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x4cf30742
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.

Last edited by stf92; 10-10-2014 at 07:03 AM.
 
Old 10-10-2014, 07:25 AM   #4
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by stf92 View Post
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.

[X] Doc CPU
 
Old 10-10-2014, 07:31 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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.
 
Old 10-10-2014, 08:18 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
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.
 
Old 10-10-2014, 09:01 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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?

Last edited by stf92; 10-10-2014 at 09:23 AM.
 
Old 10-10-2014, 09:57 AM   #8
thirdm
Member
 
Registered: May 2013
Location: Massachusetts
Distribution: Slackware, NetBSD, Debian, 9front
Posts: 326

Rep: Reputation: Disabled
Wikipedia seems helpful on this question:

Quote:
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.
https://en.wikipedia.org/wiki/Extend...e_ref-fn_2_4-0

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).
 
Old 10-10-2014, 10:18 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I now see how it is. This is the output of parted's command 'print free', where 's' stands for sectors (512 bytes):
Code:
Model: ATA ST500DM002-1BD14 (scsi)
Disk /dev/sda: 976773168s
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start       End         Size        Type      File system  Flags
 1      63s         39070079s   39070017s   primary   ext2         boot
        39070080s   39071743s   1664s                 Free Space
 2      39071744s   39276543s   204800s     primary   ntfs
 3      39276544s   100511743s  61235200s   primary   ntfs
 4      100511744s  976773167s  876261424s  extended               lba
 5      100513792s  292968447s  192454656s  logical   ext2
 6      292970496s  332050431s  39079936s   logical
        332050432s  976773167s  644722736s            Free Space
To see what is at sector 100511744, the extended part beginning, I did:
Code:
# dd if=/dev/sda of=ext bs=512 skip=100511744 count=4096
# hexdump -C ext

00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 fe  |...............þ|
000001c0  ff ff 83 fe ff ff 00 08  00 00 00 a0 78 0b 00 fe  |ÿÿ.þÿÿ.....*x..þ|
000001d0  ff ff 05 fe ff ff 00 a8  78 0b 00 58 54 02 00 00  |ÿÿ.þÿÿ.¨x..XT...|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............Uª|
00000200  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|
*
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.
 
Old 10-11-2014, 12:15 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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.
 
  


Reply



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
Master boot Record ? mohitfarswan Linux - Newbie 2 10-06-2014 02:02 AM
how to see master boot record kaushalsingh Linux - Newbie 3 12-04-2009 07:17 AM
master boot record goldeneagle1234 Linux - Newbie 2 11-09-2008 08:58 AM
Master Boot Record hvywght Linux - Newbie 14 04-20-2008 07:30 PM
Master Boot Record linuxuser05 Linux - General 3 01-11-2004 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:05 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