Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Jul 2002 11:59:56 -0400 (EDT)
From:      Jerry McAllister <jerrymc@clunix.cl.msu.edu>
To:        bts@babbleon.org (Brian T. Schellenberger), questions@freebsd.org
Cc:        kdagee@attglobal.net (karl agee), jerrymc@clunix.cl.msu.edu (Jerry McAllister), FreeBSD-Questions@freebsd.org (freebsd-questions)
Subject:   Re: Linking a directory to another filesystem
Message-ID:  <200207261559.g6QFxua19281@clunix.cl.msu.edu>
In-Reply-To: <200207252313.28903.bts@babbleon.org> from "Brian T. Schellenberger" at Jul 25, 2002 11:13:28 PM

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> On Thursday 25 July 2002 11:03 pm, karl agee wrote:
> | On Thu, 2002-07-25 at 15:50, Jerry McAllister wrote:
> 
> | I'm confused.
> |
> | Not by what you did but what I am trying to do. ;-)
> |
> | My /usr directory is on my / partition (linux lingo).  But I want to
> | move it to my /usr partition (linux lingo again) where I have gobs of
> | space and only a little is being used.
> 
> That's FreeBSD logo, too.  The quirky thing about FreeBSD is that all of it's 
> "partitions" are *within* Windows partitions, which FreeBSD calls "slices."
> 
> | I thought setting up the separate filesystems (partitions in linux
> | lingo) would put the directories there but huh.
> 
> It does.  Something when wrong in the install, or with whatever process you 
> used to create them.  It is completely impossible to have a /usr partition 
> but to also have /usr files taking up space in the / partition.  Now, if /usr 
> isn't acutally *mounted* then /usr will be used as a directory rather than a 
> mountpoint, but if you selected it as a partition at install time it should 
> be automatically mounted.

It is only mounted at boot time if there is an entry in /etc/fstab 
for it to be mounted.

As mentioned above, a mount point is merely a directory until something
is mounted on it.   You can mount any partition on any directory - and
it doesn't even have to be a directory just in the root directory (although
the whole tree starts in root).  

From the point of view of FreeBSD, disks are divided in to slices - up
to 4 of them.  These slices can be designated several types.  The type
for FreeBSD is 165.   The type for DOS FAT32 I believe is 11.  In FreeBSD
land these slices are designated s1-d4 as is da0s1...da0s4.  The fdisk
utility makes and manages slices and boot blocks.  For some reason Microsloth 
also calls their similar utility fdisk and they do similar things (though 
with some differences in ability, for example, Microsloth refuses to know 
anything about any type of slice other than one by Microsoth, but FreeBSD 
fdisk can get along with all of them). 

Each of these slices are divided in to partitions identified as a-h
as in da0s1a...da0s1h.   Partition a is normally mounted as root
on the boot device.  Partition b is normally swap.  Partition c is 
normally sort of a dummy partition that refers to the whole slice.  
For some vendors there are some additional conventions such as for 
/tmp and scratch partitions.  But, in general partitions d-h are up
for grabs although partition d seems to get skipped quite often.
The disklabel makes and manages FreeBSD partitions.  It also can
tinker with boot records.  I don't know the difference between what
fdisk and disklabel does with boot blocks.

Microsloth calls slices partitions and identifies them with what it
calls drive letters.    Unfortunately the documentation in FreeBSD
is inconsistent and often refers to slices as partitions and then
turns right around uses the same word to refer to actual partitions.
That should really be cleaned up.  It can be really confusing.

So, you divide up a disk in to slices.  If I am only running FreeBSD,
I just put all the disk in to slice 1.  I only use more than one slice
if I am making a dual/multi boot/os setup.

Now I have slice 1 on da0 created with fdisk as a FreeBSD slice (type 165).
Since da0 will be the boot drive with root I also make sure it writes in
the boot block.  This is all done with fdisk.

Then I use disklabel to divide up that slice (da0s1) in to partitions.
Partition 'a' starts at offset 0 and goes up to 300 MBytes for example
  - eg size of 614400 (I like big roots when I have room for them).  It is
  given an fstype of 4.2BSD (I have seen some that said 4.3BSD and they 
  seem to work the same.
Partition 'b' used for swap, offsets at 614400 and is 640 MBytes
  or size or 1310720 (My rule of thumb is 2.5 time memory for swap - or 
  more for a heavily used, by many separate processes, system).  It is
  gectors per unit - ven an fstype of swap.
Partition 'c' refers to the whole slice.  I read the size info - sectors
  per unit - from disklabel output run with no flags after fdisking, but 
  before starting to partition.  This disk is nominally an 18 GByte drive
  so the partition 'c' has offset of 0 and size of 35551782 and is given
  a type of unused - which makes it really a comment.
Partition 'e' will be used for /tmp and I want a lot so it becomes 1 GByte
  The offset is 1925120 and the size is 2097152.   The fstype is 4.2BSD.
Partition 'f' will be the rest of the drive where I put everything else
  such as home directories and a linked to /var and /usr/local and 
  whatever else seems to need to grow without trashing root.  So
  the offset becomes 4022272 and the size is 31529510 which amounts
  to about 15.4 GBytes.

Then I need to newfs(8) all the partitions except for swap.
You can just take the default settings for newfs unless you need
lots more inodes (eg files per partition) or something.
  newfs /dev/rda0s1a  (or newfs /dev/rda0a)   I don't know why the second
  newfs /dev/rda0s1e  (or newfs /dev/rda0e)   form here works, but it
  newfs /dev/rda0s1f  (or newfs /dev/rda0f)   seems to.

Now I need to fix up my fstab.  It will look like:

  # Device            Mountpoint      FStype  Options       Dump    Pass#
  /dev/da0s1a         /               ufs     rw            1       1
  /dev/da0s1b         none            swap    sw            0       0
  /dev/da0s1e         /tmp            ufs     rw            2       2
  /dev/da0s1f         /lump           ufs     rw            2       2
  /dev/acd0c          /cdrom          cd9660  ro,noauto     0       0
  proc                /proc           procfs  rw            0       0

Which includes mounts for the cdrom and the dummy procfs file system 
used by the system to manages processes.

Of course you don't have to call the mount point for that last 
hold-all partition '/lump' but it seems pretty mnemonic to me.

The marvelous thing is that the install program will do all this for 
me after I respond to just a few questions about sizes and mount points.
AND, it installs stuff in those partitions just so neatly (or you could do 
the installation part by hand and end up committing suicide after a month 
or two of frustration)

  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

Now I want to move /var, /usr/local and  /usr/ports in to that big /lump 
partition to give them room to grow.  (You DID install the full ports
tree when you did the installation I hope!)

  boot to single user
  fsck -p
  mount -u /
  mount -a
  cd /
  tar cf /lump/var.tar tar
  cd /usr
  tar cf /lump/local.tar local    /* probably really empty at this point
  tar cf /lump/ports.tar ports
  cd /lump
  tar xf var.tar
  mv var var.big
  tar xf local.tar
  mv local usr.local
  tar xf ports.tar
  mv ports usr.ports
  cd /
  mv var var.old
  ln -s /lump/var.big var
  cd /usr
  mv local local.old
  ln -s /lump/usr.local local
  mv ports ports.old
  ln -s /lump/usr.ports

Now check out the moved and linked var, local and ports directories
and when you are confident they are OK (they will be), get rid of
extraneous stuff.

  cd /
  rm -rf var.old
  cd /usr
  rm -rf local.old
  rm -rf ports.old
  cd /lump
  rm var.tar
  rm local.tar
  rm ports.tar

You are finished.  Reboot and enjoy.

  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

All this can be done to a second disk also da1 for example.
Then the FreeBSD letter partitions can be used for whatever
except you should still reserve 'c' as referring to the whole slice
and probably 'b' as swap.  You can leave 'b' as zero size and call
it unused if you want - or add some more to the swap from the first
drive - just make it  some size and call it swap and add it as
swap in fstab.  The system will do the rest.    The second drive 
can be all used in one big 'a' or 'e' (or whichever) partition
or divided how ever you want with the constraints of size and
available partition letters you have.   Newfsing, mounting, 
fixing up fstab and moving stuff to it is just the same as above
except no it is da1s1a...h.

  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

If you want to dedicate a whole partition to one of these things 
(/var, /usr/local, etc) you move.  It is almost the same except 
you make the mount points in different places (eg not in /lump).   
You'd have to move /var to var.old before mounting the new partition 
to /var and untarring stuff in it the sa

Say you make a partition on 'g' for /var and 'h' for /usr/local on
your second drive because you really want to accumulate lots of logs
and mail spool files and plan to install every possible freeware port
which installs in to /usr/local.
To move stuff, do the following - also best in single user.

  cd /var 
  tar cf /lump/var.tar *   /*Hey we have to put it someplace
  cd /
  umount /var
  mv var var.old
Edit /etc/fstab so now /var mounts the /dev/da1s1g partition you just made
You can also add the mount for /dev/da1s1h to /usr/local at this time too
    (vi /etc/fstab)
  mount /var               /* now it mounts the new space
  cd /var
  tar xf /lump/var.tar
  cd /usr/local
  tar cf /lump/local.tar *
  mv local local.old
  mkdir local
  mount /usr/local
  cd /usr/local
  tar xf /lump/local.tar

Now, check things out and when you are sure they are right clean up.

  cd /lump
  rm local.tar
  rm var.tar
  cd /
  rm -rf var.old
  cd /usr
  rm -rf local.old
 
reboot and it should all be hunky dory.

I hope this can settle the recent questions about partitioning and
moving stuff to other places and linking them, etc.  

////jerry


> 
> This is all exactly the same as Linux or any other Unix-like operating system.
> 
> | make sense?  
> 
> No . . .
> 
> | Guess I dont know how I would make sure I move /usr
> | directory to the /usr filesystem (and properly soft link it)and not just
> | make a new /usr directory  on the /usr directory on the / filesystem...
> | %-)



Note:   There is no "/usr" file system as such.  There is only a partition
that you create such as /dev/da0s1g or whatever.  It becomes /usr only
when it is mounted on a mount point called /usr  eg a directory in the
root directory called usr.

Further note:  If you mount a partition on an existing directory with 
stuff in it, the mounted partition will "cover up" the underlying
directory and that stuff will be unavailable until that partition is
unmounted.   Then it will reappear from hiding.  So, if you want to
move stuff from a directory in to a separate partition which gets
mounted on the same name mount point you have to copy the stuff off
somewhere and then do the mount and then copy the stuff in to the
newly mounted partition.    There are lots of ways of doing the 
copying, but probably the easiest is tar if either the old or new 
directory is not a separate partition and dump/restore if both were
separate mounted partitions (then you merely have to play with renaming
(mv-ing) mount point names).



> You don't know how to do it because it's impossible; worse, the premise is 
> impossible.  /usr is /usr, and it's *either* a partition (that is, to say, a 
> mount point) *or* an ordinary directory.  The funny thing is, until you 
> actually mount something on a mount point it *is* an ordinary directory.



Well, saying it is impossible only further confuses things.  Sure, the
procedure is wrong, but the concept of having a separate /usr file
system is not impossible.  You just have to do it right.  See all the
stuff above.

/jrm


> 
> | -karl who throughly confusted himself
> 
> Us, too.
> 
> At this point, I strongly suggest that you follow up to this with 
> 
> - The output from the "df" command, and
> - The contents of your /etc/fstab file.
> 
> 
> -- 
> Brian, the man from Babble-On . . . .   bts@babbleon.org (personal)
>                                         http://www.babbleon.org
> 
> http://www.eff.org                      http://www.programming-freedom.org 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200207261559.g6QFxua19281>