Sunday, October 22, 2006

Partition Man

Jerry McAllister (jerrymc at msu dot edu), a prolific poster on the FreeBSD questions list, wrote an impressive response to some questions about how to parition a hard drive for a shared WinXP / FreeBSD install. I thought it was too good to just pass away into the torrent that is freebsd.questions, so I asked for and got permission to reprint it here. Pay particular attention to his careful description of partitions vs. slices.






> The only thing that keeps me back is the installation: I got a
> almost 10 (even not more) manuals about FreeBSD and none, absolutely
> none, does not specify the very common possibility of having a disk
> already with 2 partitions in Windows, not to mention even further
> possibilities as having 2 disks, from which one having 2 partitions.


I guess this is what I do not understand. Most books on FreeBSD that I have seen, including the FreeBSD handbook (available online at the FreeBSD website and is essential reading) have two possibilities. The first is installing on a disk that is completely given to FreeBSD and the second is dividing the disk between Some other OS (usually MS-Win of some flavor) and FreeBSD. None that I have seen say two partitions in Windows being required (just allowed if desired).



> For instance I have 2 computers, each with 2 SATA disks: on the first, the
> master, Windows 2000 or XP, and on the other, on the first partition, the
> other Windows flavor, respectively XP and 2000, the second partition, in
> both cases, being left for data. Both systems are in dual boot; I decided
> to have ready (and use) both Windows flavors after a couple of very bad
> experiences of crashings; thus, in case of crush, at least on of the 2 OS
> would be still working allowing me to access the data.


Well, you have to make room for FreeBSD somewhere. FreeBSD does not run from a Windows slice. It requires its own slice. Note, the term "slice" which generally corresponds to what the MS-Win world calls a "primary partition" BSD Unix uses the term 'partition' to refer to a subdivision of a slice. That can at first be confusing, because sometimes people forget and use both terms interchangeably and they are definitely not the same thing.



Just a little summary:



In the MS and also the BSD world a disk can be divided in to four primary divisions which in the BSD world are called slices. In each world there are ways of further dividing the slices in to sub-units. In the BSD world those are called partitions. In the MS world, they have something called extended partitions, (but they are not the same).



You need to have at least one slice (primary partition is MS speak) to install FreeBSD. That slice will be designated as a FreeBSD type and MS-Win will no longer be able to talk to it. Although FreeBSD, which is smarter, will be able to talk to most of the other MS-Win slices. (I don't know if it can talk to an extended partition yet or not)



That FreeBSD slice can be all of a disk or just part of it and be one of the primary slices which are number 1..4. If a single disk has more than one OS, and one of those is some MS-Win thing, then it is normally better to leave the MS-Win stuff as first on the disk. FreeBSD doesn't care, but MS-Win might screw up otherwise. If you are going to use a whole disk for FreeBSD, then it doesn't matter.



> Now I decided to install the FreeBSD on the second partition of the
> second disk (in each case more than 100 GB) and I cannot find in any
> manual how, or even if or not, this second partition, of the second
> disk will appear in Sysinstall Program; normally, it would appear as
> a "da2" specification, but will it be recognized by FreeBSD as "a disk",
> that is, a 3rd disk ?


OK. I think you are saying that, on each disk, you have set up two MS-Win partitions. I am presuming by that you mean primary partitions and not some extended thing. You are planning on installing FreeBSD in the second primary partition, which FreeBSD would call slice 2 on disk 1. That is easily do-able.



I think SATA disks show up as ad_n. SCSI disks are da_n where 'n' is the disk number starting from 0. In that case your first disk would look like ad0 to FreeBSD and the second would be ad1. If there are two slices on each disk, they would be ad0s1 and ad0s2 on the first disk and ad1s1 and ad1s2 on the second disk. It sounds like you want to put FreeBSD on ad1s2.



If I am wrong on this identifier, then it will just be da0 and da1 as with SCSI disks. Just switch the a & d characters in all the commands.



> And if not, do I have to format, allocating the necessary space, in
> FreeBSD (Unix) system files ? This because this second partition of
> the second disk is already formatted in NTFS of Windows ... In this
> case, do I have to put exactly the measure of the partition (done in
> Windows) for formating in FreeBSD?


First, the slice will have to be converted to FreeBSD type. It does not have to be reformatted though as long as the system is able to see it as a primary slice. I think that the FreeBSD fdisk and disklabel that are used in sysinstall will take care of it. [Ed note: Almost certainly the case]



But if not, or if you are worried that they won't, then boot the CD and select to choose the fixit item from the install menu (past the boot selection menu) and then run fdisk on each disk. If you run fdisk without any other flags, it will just come back and give you information about the drive.



So, once you get the fixit disk prompt type:


$ fdisk ad0

$ fdisk ad1



and see what it tells you. It will list information for each primary slice. 1..4 and unfortunately, it is one place in FreeBSD that mucks up the terminology and calls them partitions instead of slices - I think because the fdisk routine was adapted from MS at some time in ancient history.



The two lines that say

The data for partition n is:

SYSID nn (OXnnn)......



are the meaningful ones because it tells you what each slice has on it as far as FreeBSD will know.



Your main MS-Win slice (primary partition) will probably either show up as either partition 1 or partition 2. There may be some diagnostic piece put on it by the hardware vendor that uses up slice 1 so MS starts in slice 2, but never tells you. But, FreeBSD will tell you.



Then, that second slice will show up as either partition 2 or partition 3 depending again on if there is a 'hidden' diagnostic slice on it. It should say that it is of type (0x07) NTFS and a bunch of other things if it is that second installation of MS stuff that you want to overwrite with FreeBSD.



If there is nothing else on the drive, then slice 4 and maybe slice 3 will show up with nothing on them, just the 'partition' identifier.



If you are worried about that slice being clean and ready for FreeBSD you can blast it by writing a few blocks of zeros on it using dd. Lets say it turns out to be partition 3 on the second drive (ad1) Do the command:
dd if=/dev/zero of=/dev/da1s3 bs=512 count=32
Be careful with this because if you do it to the wrong place you will wipe out something you don't want to mess with. I really think you should not need to do this anyway.



So, anyway, sysinstall will give you a list of slices that exist with space in them and are thus available for installing FreeBSD. If you want to install in the 'second' slice of that second disk, it will be ad1s2 or maybe ad1s3 if there is a 'hidden' diagnostic partition.



>I ask this because in a forum I
> noticed that somebody had some problems after leaving a little space
> between his 2 partitions of the disk (the first with Windows, the
> second of Linux).


I think the problem from that posting (if I remember correctly) was that he had a little space between slices, but not enough to install FreeBSD the way he wanted to and was wondering how to find more space. He wanted to use a utility called growfs, but that only allows it to grow if there is enough space right next to a partition, within a slice. So, he was stuck with rearranging his disk or adding one to get enough space. It is not the same as your situation. If you intend to use all of that 100GB in the 'second' slice on the second disk, you don't have to do anything extra - other than the remote possibility of having to wipe the tables on that slice using dd as I mentioned above.



> And a last thing, even more worrying: the booting and the MBR; do I have
> to leave the MBR untouched or to install the FreeBSD boot manager in MBR?
> In a Linux manual it is clearly specified, in the chapter about dual boot
> with Windows, that in this last case - if the Linux boot manager is
> installed in MBR - than Windows OS (XP or 2000) will not boot anymore ...
> So, leave the MBR untouched when installing FreeBSD or not ?


The FreeBSD MBR can boot the MS-Win systems. It works fine. I have three systems sitting right here in my office that do it with XP and W2000.



You have to tell it to install the FreeBSD MBR on both disks, not just the one where you are putting FreeBSD. That is because the MS-Win MBR is too weak to boot anything besides MS-Win. So, the way boot works in this case is:



The BIOS goes through its boot order looking for bootable media. That order is usually something like: floppy, CDrom, first hard disk Presuming you do not have a floppy or boot CD, then it reads the MBR from the first (and only the first) hard disk. The MBR then looks for bootable slices on its own drive and lists those and then looks for other hard drives that have an MBR and lists those. The bootable slices are listed as F1..F4 and any other disks with an MBR as F5..Fn, so if there are two bootable slices on the first disk (ad0) and an MBR and more bootable slices on the second disk (ad1) then it might look something like this:


    F1  MS-DOS
F2 ????
F5


Then, if you choose F5, it will transfer control to the MBR from the next disk and that one will look up the bootable slices it has. Say you had two bootable slices on that disk, with the second one being FreeBSD, it might look something like:
    F1  MS-DOS
F2 FreeBSD



You can choose F2 and FreeBSD will boot or F1 to boot whatever OS is in the MS-DOS slice.



I don't know if the sysinstall will install the MBR in both places. You might have to do that by hand in the fixit mode after things are done. Use 'fdisk -B ad0' and 'fdisk -B ad1' for this.



The '????' above comes because FreeBSD uses an honest MBR which occupies only one 512 byte disk sector as it is supposed to. That means it doesn't have much room for extra stuff. They crammed in recognizable labels for the identifiers that were know at the time it was first created, and then make all the rest be ????, including those that came on the scene after the FreeBSD MBR was created. Some other MBRs cheat and use more space under the assumption that it will not really be used by the system. That is true in most cases, but is not guaranteed. It gives them the ability to put out more fancy labels, etc at the [small] risk of something not working.



By the way, it goes by the file system type (numerical code) in the slice partition table. So, anything that uses a FAT32 or FAT16 will be called MS-DOS regardless of whether it is Win-95 or XP or Win-2000. If it is NTFS, it will display ???? regardless of which version of MS-Win it has, etc. I think there is room for 255 codes in the slice table.



I think it would be good if the FreeBSD MBR would put the sysid number it reads up along with the ???? just to help identify it, but maybe that would take too much code space.



Anyway, MS the recently (relative to the others) added the NTFS file system type came in to being after the FreeBSD MBR was created and so it gets displayed as ????. If there is a diagnostic slice, it will also probably get displayed as ????.



One more thing. This might be something to deal with at another time when you decide on its need and maybe are doing a major upgrade. FreeBSD can read NTFS filesystems, but, so far, it cannot write to them. For that reason, on systems that have NTFS for their MS system, I have put an extra FAT32 slice where I could write stuff from FreeBSD and then read it up in XP or whatever. That would mean dividing up your 100GB in to two slices - one small for sharing data and the rest for FreeBSD. I put that small transfer slice in between the MS and FreeBSD slices so it comes out as either slice 2 or 3 (if there is a diagnostic slice) and FreeBSD goes in to either slice 3 or 4. It works fine and is only needed if you want to write stuff to the MS system using NTFS.



> Excuse for my long message but I'm a little exasperated and don't
> understand why this extremely important aspects are not stressed
> enough in the BSD manuals: how to install the boot (in case of
> coexistence with other OS, mostly Windows) and how to choose and
> partition the disks already partitioned ...


Well, it is pretty well laid out in the FreeBSD handbook, though maybe not quite as pedantically as I have done above. That handbook is important reading.



> I am almost sure that many potential FreeBSD users are hold back from
> installing it because of these capital issues ...


Some of the understanding comes from reading and then just doing and seeing how it all works out. It makes a lot more sense when you try it and see it happening just as the handbook says.



For example, choosing the drive and slice on which to install; if you go ahead and run sysinstall, you will see just how it gives you the choice. Don't worry, until it says it is going to really do something, it won't make any changes and you can back out. So, just start it up and follow the steps until it says it will wipe things out and write new stuff and compare what you see with what you need.



Good luck and have fun,



////jerry






There, wasn't that worth the read? Again, I really liked how he explained about partions, in particular primary partitions, and what they are called in FreeBSD (slices). Also, personally I wouldn't bother with the FreeBSD bootloader, and would always suggest a third party one, like GAG, GRUB or, my favorite shareware one, BootIt NG.




No comments:

Post a Comment