LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to clean up partition table (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-clean-up-partition-table-517350/)

noranthon 01-08-2007 01:58 AM

How to clean up partition table
 
One way and another, I've ended up with a very untidy arrangement of partitions:
Code:

# sfdisk -l /dev/sda

Disk /dev/sda: 14593 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

  Device Boot Start    End  #cyls    #blocks  Id  System
/dev/sda1  *      0      -      0          0    0  Empty
/dev/sda2          0+  4359    4360-  35021668+  5  Extended
/dev/sda3          0      -      0          0    0  Empty
/dev/sda4          0      -      0          0    0  Empty
/dev/sda5          0+  2634    2635-  21165574+  83  Linux
/dev/sda6      2635+  2773    139-  1116486  82  Linux swap / Solaris
/dev/sda7      2774+  2912    139-  1116486  83  Linux
/dev/sda8      2913+  3570    658-  5285353+  83  Linux
/dev/sda9      3571+  4359    789-  6337611  83  Linux

Partitions 1, 3 and 4 are only of historical value. I was not even aware of Partition 2 until fairly late in the piece - it was a byproduct of creating partition 1.

I have found recently that deleting partitions causes havoc even with those supposedly left untouched, possibly because of the existence of sda2. I'd like to find some safe way of regularising the situation.

Does anyone have any suggestions (other than nuking the lot and starting again)?

aus9 01-08-2007 05:58 AM

backup your partitions that you want to keep I suggest to partimage....burn the images.....most live cds have it eg knoppix....rip...etc

2) yep delete the lot...using a live cd such as knoppix and use knoppix ...qtparted to create a new table or cfdisk or fdisk or sfdisk

3) do some reading on partitions if you like but I will give you 2 extremes

extreme 1...one swap partition one system partition (/) and one data partition

excellent for dvd burners and partimage...only 2 images to burn or restore from....or individually burn data folders to cdr

exteme 2 one swap one /boot and others /home /usr and /

excellent for burning to cdr if you have no dvd burner

4) after creating your new partitions either all primary total of 3 or
3 primary one extended which has 2 logicals

use the live cd to restore the images....they must however go into equal or greater partition sizes and you are stuck with the folder structure of whatever you had....so a clean install may be your long term best option?

titopoquito 01-08-2007 05:59 AM

I don't know how to clean up this, but as I see it beware deleting sda2. I think it's the extended partition where sda5 up til sda9 are stored in. And as far as I know deleting sda3 and sda4 will not change the numbers of these logical partitions (sda5 and upward).

sn68 01-08-2007 06:33 AM

DO NOT DELETE SDA2!
It is an extented partition which in layman terms is like a container which holds all partitions other than primary
Apart from this, I wouldn't advice deleting anything, merging may be a better idea

saikee 01-08-2007 06:38 AM

Looks pretty tidy to me. The partition is healthy.

The only potential problem is there is no parimary partition. That is all. You only need a primary partition if you need to install a MS system, a BSD or a Solaris.

Linux reserves sda1 to sda4 as the 4 primaries regardless they are used or not. The first logical partition created always take the 5th position. Logical partitions must be contained inside an extended partition. The creation of the extended partition is always at the expense of giving up one primary partition. In a PC there can only be one extended partition in any hard disk. It is "the" PC standard.

You always have 4 loactions in the partition table for each hard disk to specifying the 4 primaries. You must have done something to cause the sda1 location to filled up even no cylinder was assigned for storage. Hence in the creation of logical partition Linux must use the 2nd location sda2. An extended partition has no internal storage. It is just a border defining the begining and ending cylinder locations of all the logical partitions.

You disk has 14593 cylinders right? and the sda2 only uses up 4359 of them. Therefore you disk is only 4359/14592=29.87% full.

Therefore if you proceed to create more partitions they can only be the primaries of sda1, sda3 and sda4 or logical partitions from sda10 to sda15. You can delete sda1, sda3 and sda4 now to allow the next primary partition created as the primary sda1 which will automatically start at the 4360th cylinder. Once you put a primary partition to abutting sda9 then you will have no possibility of any more logical partition because the extended partition border become fixed.

Deletion of primary partitions have no consequence to the Linux distro that doesn't use them. Only the deletion of a logical partition can cause problem because all logical partitions must be continuous a chain with one logical partition carries the hard disk address of the next one down.

For example if you delete sda7 then Linux will automatically treat the space vacated by sda7 as "dead" and makes sda6 change the address of the next logical partition to the sda8 location. At the same time sda9 takes the name of sda8 and the previous sda8 becomes sda7. You lose sda9 immediately and the Linux will have aproblem to find its old sda7, sda8 and sda9. This phenomenon is visible if you use the cfdisk program for partitioning work. Experiment with it as no change to the partition table is implemented until you highlight "write" and then press the "return" key.

You can if you wish to relocate the entire sda2 to the bottom of the hard disk leaving the front end empty. This is possible with the latest version of Gparted 3.3 which is also available in Parted Magic. However technically there is nothing you need to worry. You can proceed to add as many as logical partition you like, all the way up to sda15.

Have it been a Pata you can go up to hda63.

noranthon 01-09-2007 02:03 AM

Thanks to everyone who has replied. I had forgotten about LQ's method of notification and was thinking there had been no replies.

saikee's post gives me an understanding of how I got into difficulty. My problems began when I deleted the previous sda1 and sda5 (a swap) with a view to reorganising that space.

I forget the order in which I committed my subsequent transgressions but I ended up with an OS on sda8 that I could not use. The boot loader did not work and I had to install an OS on sda9 so that I could install another boot loader and repair sda8.

I'm not entirely happy with the result. The OS on sda8 is not functioning as well as it was and I don't know what else to do to improve it. The three new problems I'm having are (1) OpenOffice is napping part way through launching, (2) the flash player plugin is causing the web browser to crash at certain locations and (3) locale settings are not being imported into Xfce. I doubt that those problems can be fixed without a major overhaul of the system itself.

A new version of PCLinuxOS is expected this month and I also want to try the latest Vector. I anticipate continuing to try other distros as well, so I want a fairly robust foundation for those installations.

I've read something at some time about the desirability of creating a partition (not too large) for the master boot record. Is there some merit in creating a small (say, 20MB) sda1 just for that (no mount point)?

Quote:

Originally Posted by saikee
You must have done something to cause the sda1 location to filled up even no cylinder was assigned for storage.

sdas 1, 3 and 4 originally contained separate OSs. I believe I deleted 3 and 4 in a vain attempt to extricate myself from the difficulties caused by deleting 1 and 5. I eventually deleted sda6 because I could not get access to it and thought it might be part of the reason for my new problems.

I initially misunderstood that I could delete any partition (except 2, because I could not see it with the tool I was using), without compromising any of the others. How wrong can you be? :Pengy:

saikee 01-09-2007 02:47 AM

You can save any of the partitions as long as you haven't altered or format the partitions.

You can "force-enter" into any Linux with another one, even with a Live CD, and get inside it by the "chroot" command.

Two areas of the original Linux (now unbootable) can be amended to suit the new layout

(1) The boot loader configuration file, which is /etc/lilo.conf or /boot/grub/menu.lst, must be amended with the "root" partition of the Linux specifying the new root location.

(2) The system file /etc/fstab has a list of files that the Linux must mount on a boot up. Amend the list inside to suit the new layout.

Thereafter you just restore its boot loader.

I frequently move Linux from partition to partition, hard disk to hard disk and even from computer to computer. You can certainly get the Linux back to the usable form. Equally you can start afresh.

If you like the challenge of the former, let us known.

noranthon 01-09-2007 05:35 PM

Thanks, saikee. I followed the procedure you mention. I used the PCLOS livecd and a new install on sda9 to change fstab on sda8.

That got me into sda8 but it was awry. That was complicated by the fact that, just before logging out previously, I had elected to try xdm instead of kdm. Anyway, I've got sda8 working sufficiently but, as I say, there are problems which did not exist previously.

I'm glad to know that I've got the choice of keeping the existing arrangement but the more I think about it, the more comfortable I feel with starting afresh. I particularly like the idea of dedicating sda1 to the master boot record.

saikee 01-09-2007 05:42 PM

The Master boot record is the first 512 bytes of the hard disk. This is NOT sda1.

You don't need a place for the MBR, just learn how to restore the boot loaders there (Last link of my signature refers).

You may consider install every Linux in a single partition from now on as it is easier to boot, maintain, resize and migrate. Best is to do all the partitioning before and tell the installer to mount the Linux "/" with the specified partition. All /boot, /home, /usr .... will be just the subdirectories to /.

A 10Gb partition is big enough for 99.99% distros. Majority of mine are in 5Gb partitions.

noranthon 01-10-2007 07:18 PM

I must admit, I am a little puzzled by the MBR. sfdisk tells me that it is located in /dev/sda1. Is that a fiction?

saikee 01-11-2007 04:16 AM

noranthon,

To be fair we are both correct.

Physically the first 512 bytes of partition sda1 is the MBR. This is a 100% bomb proof statement if you run only one system too and it is in sda1.

However if you run multi operating system and to boot them your MBR has to form a linkage to the operating system that carries out the multi-booting function for you. Therefore the MBR is taken for the whole disk.

As an example, say you have XP in sda1 with boot loader NTLDR, Slackware in sda2 using Lilo and PCLinuxOS in sda3 using Grub. Each bootloader has Part A (the first 512 bytes) and Part B (the part that actually boots the system). A boot loader reside in the boot sector which is always reserved regardless if it is used or not but a few filing systems the break the rule.

If you let XP boot the rest then Part A of NTLDR will assume the MBR position.

For PCLiniux's Grub to multi boot Part A of Grub must be installed in the MBR even though its master resides in sda3. Basically the Part A (the MBR position) of sda1 is overwritten by the Part A from sda3.

Similar story for Slackware if Lilo were to boot all three system.

Generally if you talk about the MBR in a multi-system environment you have to be talking about the system that controls the booting for you and it is rare but possible that it is "sourced" in sda1.

To prove if the above is a load of rubbish

Next time you boot up a Linux with Grub, say PCLinuxOS, press Grub to get a Grub prompt and type these two lines
Code:

root (hd0)
root (hd0,0)

You will find Grub report the first as using the "whole" disk, as (hd0) means sda in your case.

and response to the second statement would be "filing system unknown" as your sda1 is empty.

The fact that you can operate booting successfully with an empty sda1 is an indication that you are using the MBR for the whole of the hard disk and not for sda1.

The other angle that may help you to understand the MBR is if you have several hard disks then theoretically you have many MBRs but only the one at the front of the booting queue matters. You can let disk sdc be the first booting disk and then the first sector of 512 bytes of sdc1 partition will control your booting and that MBR can be "sorced" from any disk you choose.

The third point that may be helpful to the appreciation is you can delete sda1 completely without affecting your current system. If you haven't got sda1 but the system still boots then the MBR must not be affected by the existence of sda1.

Hope the about is clear. You are right in bringing it up as it is confusing and many Linux users wouldn't have a clue about the difference. Don't think I know that much about it either but the above is my "obervation" and "experienece" after booting 145 systems in the box.

noranthon 01-12-2007 12:29 AM

Thanks for the explanation. One thing I have discovered is that so much of the information on the web is several years out of date.

I started having more trouble so reinstalled ahead of the weekend. I decided to make the first 3 partitions containers for distro installations. I'll use the first to govern the boot loader for the whole system and use chainloader + 1 for the other distros.

saikee 01-12-2007 02:21 AM

Actually you can be flexible with which distro to take over the MBR as every one can.

To make a distro residing in say hda7 to take over the MBR in grub is
Code:

grub-install /dev/hda
To make it chainloadable is
Code:

grub-install /dev/hda6
If the distro has Lilo instead of Grub the equivalent is
Code:

lilo -b /dev/hda
Code:

lilo -b /dev/hda6
Therefore you can play tunes with the boot loaders. Have some fun let Lilo have a go at the MBR too.

To make a Lilo chainload a Linux from from partition say hda9 is just
Code:

other=/dev/hda9
label=Linux_in_hda9

in Grub it is just
Code:

title Linux in hda9
root (hd0,8)
chainloader +1

Give a bit of thought to it and you will find it a child play.

mblames 01-12-2007 03:04 AM

Make Image from your partition can be a better idea, and also back up your default partition table with 'dd'.
Make image with systemrescuecd OS (live CD), this OS helps a lot. It has partimage and many things. And also easy to use.

So, u just back up your partition table before u do somthing wrong, and end up somewhere u dont want to. And back up all your partition. So, u can restore it.

noranthon 01-13-2007 10:04 PM

I can recommend GParted. It makes the distro tools I've seen look clumsy.

I didn't have the partitions totally backed up because PCLinuxOS's version of mondoarchive cannot write to DVD and I had not decided on an alternative. That's another fertile area for discussion.

If you find systemrescuecd easy, mblames, you must have done a lot of study to get to that point. All admin stuff is a chore and a bore to me. Dump looks pretty simple so I'm going to try that. :twocents:


All times are GMT -5. The time now is 06:26 PM.