Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [SOLVED] convert a logical partition to a primary one?

  1. #1
    Join Date
    Jul 2008
    Beans
    52

    [SOLVED] convert a logical partition to a primary one?

    I totally switched to Ubuntu some days ago, after made some changes to my hard disk. at the moment its state is as follows:




    Now there's a problem: one partition is still a extended one for nothing. i want to convert it to a primary. in this situation, i want sda1 and sda5 to become one and there is no extended, all partitions would be primary.

    so what should i do?

  2. #2
    Join Date
    Mar 2008
    Beans
    1,755

    Re: convert a logical partition to a primary one?

    Backup all data

    Delete the extended partition and then attempt to resize partition sda1 to use the space that deleting the extended partition created.

  3. #3
    Join Date
    Dec 2006
    Beans
    1,807
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: convert a logical partition to a primary one?

    You may find what you need here.

    http://gparted.sourceforge.net/documentation.php

    But as far as i know you will have to delete the partition and then the extended partition to make it a primary partition.

  4. #4
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: convert a logical partition to a primary one?

    It's possible to manually change a logical partition into a primary one via the command line, but I'm just curious why do you want to do that? What is wrong with leaving sda5 as a logical partition? If you really want to try it, then first please post:
    Code:
    sudo fdisk -lu
    sudo sfdisk -d /dev/sda
    Last edited by caljohnsmith; December 11th, 2008 at 09:43 PM.

  5. #5
    Join Date
    Jul 2008
    Beans
    52

    Re: convert a logical partition to a primary one?

    Quote Originally Posted by caljohnsmith View Post
    It's possible to manually change a logical partition into a primary one via the command line, but I'm just curious why do you want to do that? What is wrong with leaving sda5 as a logical partition?
    I just want to see what a Linux OS can do? It's amazing to know that this task can be completed in command line, cause i once thought i had to borrow a drive and copy all the data to it.

    Code:
    $ sudo fdisk -lu
    
    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: 0xaca3aca3
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1        30732345   155268224    62267940    f  W95 Ext'd (LBA)
    /dev/sda2       155268225   156296384      514080   82  Linux swap / Solaris
    /dev/sda3              63    30732344    15366141   83  Linux
    /dev/sda5        30732408   155268224    62267908+  83  Linux
    
    Partition table entries are not in disk order
    Code:
    sudo sfdisk -d /dev/sda
    
    # partition table of /dev/sda
    unit: sectors
    
    /dev/sda1 : start= 30732345, size=124535880, Id= f
    /dev/sda2 : start=155268225, size=  1028160, Id=82
    /dev/sda3 : start=       63, size= 30732282, Id=83
    /dev/sda4 : start=        0, size=        0, Id= 0
    /dev/sda5 : start= 30732408, size=124535817, Id=83

  6. #6
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: convert a logical partition to a primary one?

    To convert from a logical partition into a primary one is fortunately easy, assuming one doesn't try to exceed the max limit of 4 primary partitions; it is only if you want to convert from a primary partition into a logical partition that it takes more work. So anyway, all I did was change your partition table as follows in the attached "partition_table.txt" file:
    Code:
    # partition table of /dev/sda
    unit: sectors
    
    /dev/sda1 : start= 30732408, size=124535817, Id=83
    /dev/sda2 : start=155268225, size=  1028160, Id=82
    /dev/sda3 : start=       63, size= 30732282, Id=83
    /dev/sda4 : start=        0, size=        0, Id= 0
    So basically I just deleted your sda1 extended partition and replaced it with the sda5 logical partition, so sda5 will become the sda1 primary partition. As always, be sure to back up any important files on the HDD before doing the following partition changes. To write the above partition table to your HDD, just download the "partition_table.txt" file to your desktop and do:
    Code:
    sudo sfdisk --force /dev/sda < ~/Desktop/partition_table.txt
    And your sda5 logical partition will now be sda1 primary partition. You can check immediately after the above command by doing:
    Code:
    sudo fdisk -l
    To see your new partition table. Also you should be able to mount sda1 and view its contents:
    Code:
    sudo mount /dev/sda1 /mnt
    nautilus /mnt &
    Anyway, let me know how that goes.
    Attached Files Attached Files
    Last edited by caljohnsmith; December 12th, 2008 at 12:20 AM.

  7. #7
    Join Date
    Jul 2008
    Beans
    52

    Re: convert a logical partition to a primary one?

    Hi caljohnsmith,
    this is the outcome of the command
    Code:
    $ sudo sfdisk --force /dev/sda < ~/Desktop/partition_table.txt
    Checking that no-one is using this disk right now ...
    BLKRRPART: Device or resource busy
    
    This disk is currently in use - repartitioning is probably a bad idea.
    Umount all file systems, and swapoff all swap partitions on this disk.
    Use the --no-reread flag to suppress this check.
    
    Disk /dev/sda: 9729 cylinders, 255 heads, 63 sectors/track
    Old situation:
    Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
    
       Device Boot Start     End   #cyls    #blocks   Id  System
    /dev/sda1       1913    9664    7752   62267940    f  W95 Ext'd (LBA)
    /dev/sda2       9665    9728      64     514080   82  Linux swap / Solaris
    /dev/sda3          0+   1912    1913-  15366141   83  Linux
    /dev/sda4          0       -       0          0    0  Empty
    /dev/sda5       1913+   9664    7752-  62267908+  83  Linux
    New situation:
    Units = sectors of 512 bytes, counting from 0
    
       Device Boot    Start       End   #sectors  Id  System
    /dev/sda1      30732408 155268224  124535817  83  Linux
    /dev/sda2     155268225 156296384    1028160  82  Linux swap / Solaris
    /dev/sda3            63  30732344   30732282  83  Linux
    /dev/sda4             0         -          0   0  Empty
    Warning: partition 1 does not start at a cylinder boundary
    Successfully wrote the new partition table
    
    Re-reading the partition table ...
    BLKRRPART: Device or resource busy
    The command to re-read the partition table failed
    Reboot your system now, before using mkfs
    
    If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
    to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
    (See fdisk(8).)
    I'm really worried now. After running the command, i see the disk via GParted and this is its status:

    It seems all data was deleted!!!
    unfortunately, i didn't backup anything (actually, i don't have an external disk). if the data cannot recovered, i go crazy!

  8. #8
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: convert a logical partition to a primary one?

    OK, go ahead and reboot your Live CD, open a terminal again, and post the output of:
    Code:
    sudo fdisk -lu
    sudo mount /dev/sda1 /mnt
    ls -l /mnt
    Note "-l" is a lowercase L, not a one. We can work from there.

  9. #9
    Join Date
    Jul 2007
    Location
    Melbourne, Australia
    Beans
    3,475
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: convert a logical partition to a primary one?

    Unfortunately on this occasion caljonsmith made an error (which I can promise you, is rare) - when deleting or changing a logical to a primary partition, anything with in the logical partition is wiped. You could try testdisk to restore you data. It will probably re-write the logical partition to do this. If you manage the retrieval of your data, you will have to copy the data elsewhere whilst removing the logical partition. Get testdisk live cd from the link or you can use ubuntu if it's still functional
    sudo apt-get install testdisk
    then to start testdisk
    sudo testdisk
    There are instructions on the testdisk site and also here. Good luck
    Windows is the best virus detector on the market!
    Ubuntu attracts Human Beings - Windows attracts viruses and worms

  10. #10
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: convert a logical partition to a primary one?

    Quote Originally Posted by bumanie View Post
    Unfortunately on this occasion caljonsmith made an error (which I can promise you, is rare) - when deleting or changing a logical to a primary partition, anything with in the logical partition is wiped.
    Bumanie, that's not true about the operation that we did with sfdisk; sfdisk only changes the MBR (Master Boot Record) and the EBRs (Extended Boot Records) with the partition changes, and his operation was such that no EBRs had to be created, which is the risky process. His data has not been wiped. If we need to, we can reverse the process and reinstate his previous partition table; that is one reason why I had him post the "sfdisk -d" so that essentially we have an online backup of his previous partition table. As long as he doesn't do anything to write to the drive, we can rewrite his original partition table back to the drive if we need to. But first I want to see if it was successful, because I don't see reason yet to be alarmed.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •