Subject: Re: [Ext2 Mount] Newbie Question
To: William Pomian <willish@free.fr>
From: Rakhesh Sasidharan <rakhesh@cse.iitd.ernet.in>
List: netbsd-help
Date: 04/21/2001 17:56:19
Hi William,

First for a bit of background: When you have a disk, you generally divide
it into "primary partitions" and "extended partitons", and then furthur
divide the "extended partitions" into "logical partitons".  An extended
partition is just like a container for all its logical partitons.  This is
the way the Windows world works, and also Linux.

The total number of primary+extended partitions must be FOUR, and you can
have at most ONE primary partition.  And depending on the OS, you have
around 15-16 logical partitions (I'm not quite sure of this, but I'll get
to this later on).  

So for example, if you have a harddisk, you would have probably have some
space allocated to Windows C:\ (which would be a primary partition), and
then you would allocated the remaining space as extended.  In this
extended partition, you would create logical partitions which you could
use as D:\, E:\ etc etc.

Linux also works in a similar way: generally, you would have one primary
partition (the / partition), and then an extended partition with logical
partitions (the swap partition, /usr, /var etc etc).  Ofcourse, it is
perfectly possible that you dedicate all your space to a primary
partition (the /), and not have separate /usr, /var etc partitions (but
that is not recommended).

Now for NetBSD.  The BSDs (and NetBSD, in our situation) deal with things
a bit differently.  They have the concept of a "slice", which is to say
that you tell NetBSD you want all the space from (say) sectors 0 to 10,000
allocated for NetBSD, and then NetBSD has something called a "disklabel"
which partitions that space up into different partitions.

For example, in your case (below):

> > 8 partitions:
> > #        size   offset     fstype   [fsize bsize   cpg]
> >   a:  1091601       63     4.2BSD     1024  8192    16   # (Cyl.    0*- 1082)
> >   b:  2099664  1091664       swap                        # (Cyl. 1083 - 3165)
> >   c:  8191953       63     unused        0     0         # (Cyl.    0*- 8126)
> >   d: 90069840        0     unused        0     0         # (Cyl.    0 - 89354)
> >   e:  5000688  3191328   System V                        # (Cyl. 3166 - 8126)
> 

The letters (a-e) are the partition names.  And partitions c and d are
special.  Partition d stands for your whole disk, and c stands for the
NetBSD slice.  Thus in your case, sectors 63 to 8191953 are for NetBSD,
and in that we have partitions a (sector: 63-1091664), partition b
(1091664-3191328) and partition e (3191328-8191953).  And since your disk
is /dev/wd0, you would be mounting these partitions as /dev/wd0a,
/dev/wd0b, and /dev/wd0e.  (You can't mount /dev/wd0c and /dev/wd0d as
these are special, as I said above).

The disklabel and slice system is a hangover from the Unix days (or so I
think :-).  But they work well on PCs, coz we ar able to circument the use
of extended and partitions, and slices are a lot more flexible thing.

Now, the important thing to note about the disklabel is that you can have
a maximum of *8 partitions* in it (that's what the number 8 stands for in
your output above), and since c and d are used, you are left with 6
partitions.  Of this, b is for swap, and a is for / (these are again,
needed).  So, you are left with 4 partitions, and since you already have e
defined, in your case, you have 3 partitions left.  What I mean by that is
that, suppose you had lots of space in your NetBSD "slice", then you would
have had to carve it up into 3 partitions (or less) if you wanted to use
it -- 4 partitions would not be allowed.

A cool thing about the disklabel (and here is where it answers your
query), is that you can specify a new partition (say, f) which starts from
the sector number your Linux partition starts, and which has the size (in
sectors) of your Linux partition, and fstype (ext2fs), and other fields
blank, and *then* you can mount /dev/wd0f and access all your ext2fs data.

So now you are faced with the problem of how to go about figuring out the
start and size values of the ext2fs partition.  If your ext2fs part is a
primary one, then you could try using fdisk (see the manpage on how), and
get the values from there.  But if your ext2fs partition is a logical one,
then you would have to boot into Linux (I assume you have it; and that's
why you have ext2fs), and then try to find the values from there.

In Linux, generally /dev/hda1,2,3,4 are the primary+extended partitions,
and /dev/hda5-16 are the logical partitions.  So incase yours is a logical
partition, you could boot into Linux, fire up fdisk and try to find the
values in sectors of /dev/hda?? and note them down (how you could use
fdisk to achieve that -- read the manpage).

After all that, when you have the values of start/size in sectors, then
run the disklabel program in NetBSD (again, refer the manpage, and ask if 
any doubts) to *edit* the disklabel (ya, the program is also called
disklabel) and then enter the values as with the other lines for a
partition f.  Save and exit the disklabel, and then you could try mounting
that partition (/dev/wd0f).  Just make sure you have compiled in ext2fs
support in your kernel (I don't remember if it is there by default).

Well, that's it.  Hopefully you will get things right. :-)

Regards,
__
Rakhesh Sasidharan	rakhesh at cse.iitd.ac.in