LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   logical partition to a primary one (https://www.linuxquestions.org/questions/linux-newbie-8/logical-partition-to-a-primary-one-88322/)

britcoms9 09-02-2003 05:25 AM

logical partition to a primary one
 
How do I convert a logical (extended) partitition to a primary one, without loosing all my data ?

I not to get Windows running again.

fdisk -l

DEVICE BOOT Id System

/dev/hd1 * f Win95 Ext'd (LBA)
/dev/hd2 82 Linux Swap
/dev/hd3 83 Linux
/dev/hd5 7 HPFS/NTFS
/dev/hd6 7 HPFS/NTFS
/dev/hd7 7 HPFS/NTFS

fancypiper 09-02-2003 09:33 AM

Are you wanting the disk space back for Windows? If so, you will lose all information on the Linux partitions.

# How do I uninstall Linux completely and keep/use Windows only?
How to Remove Linux and Install Windows 2000
How to Remove Linux and Install Windows XP
You can remove lilo from the mbr with
/sbin/lilo -u
You can remove grub or lilo from the mbr by booting with a Windows 98 boot floppy (at the prompt, type fdisk /mbr), or by using the Windows XP Recovery Console or the Windows 2000 Recovery Console

quatsch 09-02-2003 09:38 AM

fancypiper: the trouble is that britcoms9 has windows installed on a logical partition and hence cannot boot it (I'm curious as to how windows got to be on a logical partition in the first place, but that's another story). What he needs, if possible, is to convert a logical partition to a primary one.

fancypiper 09-02-2003 10:05 AM

I don't know of any way to do that. I would think that would be impossible as the logical partitions are part of the extended partition.

Back up your important data, zero out the drive and re-partition and re-install is the only way I am aware of.

Someone didn't follow the standard advise of putting windows on the first primary partition of a drive. :(

# Partitioning
Linux Partition HOWTO
Rute - Partitions, File Systems, Formatting, Mounting

bobpaul 01-20-2008 06:46 PM

Quote:

Originally Posted by fancypiper (Post 458052)
I don't know of any way to do that. I would think that would be impossible as the logical partitions are part of the extended partition.

I know this is a really old thread, but it came up on Google every time I tried to search for solutions to this problem.

One can use parted or its GUIs (qtparted or gparted) to resize, shrink, and move partitions. Unfortunately, unlike Partition Magic, neither qtparted nor gparted off the option to convert a partition. Also, at this time parted can't change the start point of some partitions (reiserfs, ntfs, etc.)

As an example, here's the problem I had:
(it's important to use the -u option as sectors are far more accurate than cylinders.)

Code:

sudo fdisk -l -u /dev/sda

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x3a8ad18e

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1              63    16370234    8185086    7  HPFS/NTFS
/dev/sda2        16370235    47825504    15727635    7  HPFS/NTFS
/dev/sda3        47825505    70894844    11534670  83  Linux
/dev/sda4        70894845  156296384    42700770    f  W95 Ext'd (LBA)
/dev/sda5        70894971  152231939    40668484+  83  Linux
/dev/sda6      152232003  156296384    2032191  82  Linux swap

What I want to do is convert sda3 to a logical partition by moving the start point of the extended partition (sda4).

To do this, I first have to either shrink sda2 slightly or shrink and move the start point of sda3 slightly. One needs to do this as the start point of the extended partition cannot be the same as the start point of a logical partition inside. While no information is written at the start of an extended partition, we still need a small buffer. I chose to shrink sda3 by 10MB and move the start point. This resulted in the following:

Code:

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1              63    16370234    8185086    7  HPFS/NTFS
/dev/sda2        16370235    47825504    15727635    7  HPFS/NTFS
/dev/sda3        47841570    70894844    11526637+  83  Linux
/dev/sda4        70894845  156296384    42700770    f  W95 Ext'd (LBA)
/dev/sda5        70894971  152231939    40668484+  83  Linux
/dev/sda6      152232003  156296384    2032191  82  Linux swap

I now have a gap between the end of sda2 and the start of sda3. This will let me start an extended partition in this space.

I'll now open up fdisk (fdisk -u /dev/sda) and delete all partitions 2 through 6. This is safe because I'm only deleting the record of where the partition is located and not the data contained in the partition. As long as I use the exact same start and stop points when I create new partitions, all the data will still be there. Here's my new partition map:

Code:

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1              63    16370234    8185086    7  HPFS/NTFS
/dev/sda2        16370235    47825504    15727635    7  HPFS/NTFS
/dev/sda3        47825505  156301487    54237991+  5  Extended
/dev/sda5        47841570    70894844    11526637+  83  Linux
/dev/sda6        70894971  152231939    40668484+  83  Linux
/dev/sda7      152232003  156296384    2032191  82  Linux Swap


REMEMBER: when using fdisk, no changes are made until you issue the w command to write the changes. If you think you made a mistake, press Ctrl+C or use q to quit without saving the changes.

When creating logical partition 5 (what used to be called sda3). You'll notice there's now some space between the the start of the Extended partition and the first logical partition (what used to be /dev/sda3). There's also some space between the new sda5 and sda6 (which used to be sda5) that was previously taken up by the extended partition. We can recover this space later by running gparted again.

After resizing and moving what's now sda5 (and was origionally sda3) in gparted, I was left with:
Code:

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1              63    16370234    8185086    7  HPFS/NTFS
/dev/sda2        16370235    47825504    15727635    7  HPFS/NTFS
/dev/sda3        47825505  156301487    54237991+  5  Extended
/dev/sda5        47825568    70894844    11534638+  83  Linux
/dev/sda6        70894971  152231939    40668484+  83  Linux
/dev/sda7      152232003  156296384    2032191  82  Linux Swap

Your problem is actually easier.

For your problem, you would have wanted to do something similar. You have an extended partition that fills the entire drive. What you need is for the extended partition to stop at the end of partition partition 3 so that your 3 NTFS partitions are primary instead of logical.

Use fdisk -u -l to find the start and stop points of all of your partitions. Open 'fdisk -u /dev/hda' and delete all of your partitions. Now, create an extended partition that starts where the old hda1 did, but ends where the old hd3 did. Now create locical partitions with for hd2 and hd3 with the same start and end points as before. Finally, create primary partitions for hda5, hda6, and hda7 using the same start and stop as you previously had.

Try mounting your new partitions. If it doesn't work, simply open 'fdisk -u' again, delete all of your partitions, and recreate them exactly as 'fdisk -u -l' showed you earlier. This will at least restore you to where you were at the start.

Remember to always have a printout of 'fdisk -l -u' save somewhere before you start messing with partitions.


All times are GMT -5. The time now is 06:47 AM.