pavement

Partitioning Tips and Tricks

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (Using RAM virtual file systems)
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
==Don't dump everything in /usr !==
+
You may find [[Hard Disk Partition Sizes]] useful if you are setting up partitions for the first time.
By default, FreeBSD will partition your drive so that the /usr partition takes up all the space except for a few hundred megs apiece for swap, root, /var, and /tmp.  This is fine unless and until you wind up with a cranky machine that needs some TLC and keeps rebooting or panicking, thereby needing tremendous amounts of time to [[fsck]] a gigantic /usr partition before it can be booted!
+
 
+
You'll make your life LOTS easier in the event of problems if instead you set /usr to be no bigger than about 10GB or so, and put the remainder of the drive as a new and unrelated partition - I tend to call mine /data.  That way if you're having problems that keep causing the machine to panic or hard boot without stabilising the filesystem first, you can get up and running FAST by just [[fsck]]'ing your nice small /, /var, /tmp, and /usr partitions without having to sit through a 15 or 20 minute [[fsck]] of the rest of the 100GB or so of user data that isn't needed for the system to actually operate.
+
 
+
Of course, you WILL need to [[fsck]] that big /data partition once you've gotten the system stable again - but at least you'll only have to do it ''once'' after the problem's ''been'' fixed, instead of sitting through a 10-30 minute [[fsck]] every time the machine panics or hard-reboots while you're tracking down that pesky hardware problem.
+
  
 
==Make yourself a tiny little partition for /mnt==
 
==Make yourself a tiny little partition for /mnt==
If you plan to work with removable read-write filesystems - USB drives, IDE or SCSI removables, whatever - make yourself a teeny tiny (like 5 or 10 MB) partition for /mnt, and mount the devices to /mnt/removable or /mnt/usbdrive or what have you.  That way if a script or a command you run tries to copy a few gigs worth of data and you DON'T have your removable device properly mounted, it will fill your little throwaway /mnt partition that you don't really need (and do it very quickly), instead of you accidentally filling your root partition, which can cause system instabilities.
+
If you plan to work with removable read-write filesystems - USB drives, IDE or SCSI removables, whatever - make yourself a teeny tiny (like 5 or 10 MB or less) partition for {{file|/mnt}}, and mount the devices to {{file|/mnt/''removable''}} or {{file|/mnt/''usbdrive''}} or what have you.  That way if a script or a command you run tries to copy a few gigs worth of data and you DON'T have your removable device properly mounted, it will fill your little throwaway {{file|/mnt}} partition that you don't really need (and do it very quickly), instead of you accidentally filling your root partition, which can cause system instabilities.
  
 
==Use soft links to your advantage!==
 
==Use soft links to your advantage!==
Don't forget that you can use [[ln]] to do really nifty things with your drives and partitions.  For example if you've taken the first tip's advice and made a relatively small /usr partition and a very large /data partition, you might want to move the ports tree - which can occupy several gigs of space if you build lots of ports and aren't meticulous about cleaning out old distfiles and work directories - into the larger /data partition.  But instead of trying to laboriously fix the entire system so that it looks in /data/ports instead of /usr/ports, what you can do instead is '''mv /usr/ports /data/''' and then '''ln -s /data/ports /usr/ports''' - now it ''looks'' and ''works'' as though the ports tree is still in the default location, but in fact it's operating from the bigger partition!
+
Don't forget that you can use [[ln]] to do really nifty things with your drives and partitions.  For example if you've made a too small {{file|/usr}} partition and a very large {{file|''/data''}} partition, you might want to move the ports tree - which can occupy several gigs of space if you build lots of ports and aren't meticulous about cleaning out old distfiles and work directories - into the larger {{file|''/data''}} partition.  But instead of trying to laboriously fix the entire system so that it looks in {{file|''/data/ports''}} instead of {{file|/usr/ports}}, what you can do instead is {{cmd|mv /usr/ports ''/data/''}} and then {{cmd|ln -s ''/data/ports'' /usr/ports}} - now it ''looks'' and ''works'' as though the ports tree is still in the default location, but in fact it's operating from the bigger partition!
 +
 
 +
Another common use for this is {{file|/var/db}} on servers with large databases.  By default [[mysql]] places databases in {{file|/var/db}}, which is normally a very small partition (256MB or so) - and can be overwritten disturbingly quickly with apache logs and mailserver logs and the like, not to mention the databases themselves.  Rather than recompiling or reconfiguring the database server itself to look for its database in a different location, you can simply move the databases to a different partition and soft link to them, just as was described for the ports tree in the paragraph above.  Kill the database server, {{cmd|mv /var/db /data/db <nowiki>&&</nowiki> ln -s /data/db /var/db}} and restart the server with no conf changes necessary, and you're in business!
 +
 
 +
==Multiple Disks? Multiple /swap==
 +
If you've got two or more disks, you'll speed up performance on them by creating swap partitions on both of them -- no more moving data through the system bus to page files from disk 1 to your swap partition on disk 0. Some folks recommend that swap always be the first slice on the disk (even before {{file|/}} or any other partitions) because it's supposed to increase read/write times for stuff in swap; I've never noticed any real difference when I've done this, but if you have a lot of read/write-intensive operations (big databases, for e.g.,) you may want to consider this.
 +
 
 +
NOTE: as always, the ''best'' way to speed up swap is not to need it in the first place - if you've got heavy swap partition activity, and you can possibly afford to do it, add more RAM.  No matter ''what'' you do with your swap partition(s), accessing them is always going to be an order of magnitude or three slower than staying in RAM.
 +
 
 +
==Using RAM virtual file systems==
 +
Here are instructions on how to use RAM as {{file|/tmp}} (temporary) or {{file|/var}} file systems. {{man|tmpfs|5}} is suitable for desktops, because it automatically adjusts its file size, unlike {{man|mdmfs|8}}.
 +
 
 +
To set up a {{man|tmpfs|5}} filesystem, enter into {{file|/etc/fstab}}:
 +
tmpfs  ''/mydir2''    tmpfs  rw,-s1g    0 0
 +
 
 +
To use the {{man|md|4}} driver, add the following, or similar variable to {{file|/etc/rc.conf}}:
 +
tmpmfs="YES"
 +
tmpsize="3g"
 +
 
 +
{{man|mdmfs|8}} can also be mounted through {{file|/etc/fstab}}:
 +
md    ''/mydir1''    mfs    rw,-s1g    0 0
 +
 
 +
{{man|mdmfs|8}} can also mount {{file|/var}} on RAM, but this is only for operating systems that are read-only. On regular installs, files in {{file|/var}} are needed for the operating system to resume normally, which would be regularly flushed on a virtual {{file|/var}} file system.
 +
varmfs="YES"
 +
varmfs="512m"
 +
 
 +
Virtual RAM filesystem are shared with harddrive swapspace to add capacity. There must be enough combined swap and RAM capacity to contain the virtual filesystem. .iso images can be mounted on swap too. See also ''[[mdconfig]]'' and related filesystem ram manpages for more information.
  
Another common use for this is /var/db on servers with large databases.  By default [[mysql]] places databases in /var/db, which is normally a very small partition (256MB or so) - and can be overwritten disturbingly quickly with apache logs and mailserver logs and the like, not to mention the databases themselves.  Rather than recompiling or reconfiguring the database server itself to look for its database in a different location, you can simply move the databases to a different partition and soft link to them, just as was described for the ports tree in the paragraph aboveKill the database server, '''mv /var/db /data/db && ln -s /data/db /var/db''' and restart the server with no conf changes necessary, and you're in business!
+
==Getting Hard Disk Information==
 +
Sometimes you need information about the model or manufacturing numbers of drives that are in a running system. If the hard disk supports SMART (most do), you can use the {{cmd|smartctl}} utility (available from {{port|sysutils/smartmontools}}) to extract the model numbersRunning {{cmd|smartctl -i /dev/ad4}} as root on my system gives output like this:
 +
=== START OF INFORMATION SECTION ===
 +
Device Model:    WDC WD2500JB-00EVA0
 +
Serial Number:    WD-WCAEH1028140
 +
Firmware Version: 15.05R15
 +
Device is:        In smartctl database [for details use: -P show]
 +
ATA Version is:  6
 +
ATA Standard is:  Exact ATA specification draft version not indicated
 +
Local Time is:    Thu Dec 22 10:48:33 2005 CST
 +
SMART support is: Available - device has SMART capability.
 +
SMART support is: Enabled
  
 
[[Category:New_User_Tips_and_FAQs]] [[Category:Common Tasks]]
 
[[Category:New_User_Tips_and_FAQs]] [[Category:Common Tasks]]
 
[[Category:FreeBSD for Servers]]
 
[[Category:FreeBSD for Servers]]

Latest revision as of 01:09, 11 February 2018

You may find Hard Disk Partition Sizes useful if you are setting up partitions for the first time.

Contents

[edit] Make yourself a tiny little partition for /mnt

If you plan to work with removable read-write filesystems - USB drives, IDE or SCSI removables, whatever - make yourself a teeny tiny (like 5 or 10 MB or less) partition for /mnt, and mount the devices to /mnt/removable or /mnt/usbdrive or what have you. That way if a script or a command you run tries to copy a few gigs worth of data and you DON'T have your removable device properly mounted, it will fill your little throwaway /mnt partition that you don't really need (and do it very quickly), instead of you accidentally filling your root partition, which can cause system instabilities.

[edit] Use soft links to your advantage!

Don't forget that you can use ln to do really nifty things with your drives and partitions. For example if you've made a too small /usr partition and a very large /data partition, you might want to move the ports tree - which can occupy several gigs of space if you build lots of ports and aren't meticulous about cleaning out old distfiles and work directories - into the larger /data partition. But instead of trying to laboriously fix the entire system so that it looks in /data/ports instead of /usr/ports, what you can do instead is mv /usr/ports /data/ and then ln -s /data/ports /usr/ports - now it looks and works as though the ports tree is still in the default location, but in fact it's operating from the bigger partition!

Another common use for this is /var/db on servers with large databases. By default mysql places databases in /var/db, which is normally a very small partition (256MB or so) - and can be overwritten disturbingly quickly with apache logs and mailserver logs and the like, not to mention the databases themselves. Rather than recompiling or reconfiguring the database server itself to look for its database in a different location, you can simply move the databases to a different partition and soft link to them, just as was described for the ports tree in the paragraph above. Kill the database server, mv /var/db /data/db && ln -s /data/db /var/db and restart the server with no conf changes necessary, and you're in business!

[edit] Multiple Disks? Multiple /swap

If you've got two or more disks, you'll speed up performance on them by creating swap partitions on both of them -- no more moving data through the system bus to page files from disk 1 to your swap partition on disk 0. Some folks recommend that swap always be the first slice on the disk (even before / or any other partitions) because it's supposed to increase read/write times for stuff in swap; I've never noticed any real difference when I've done this, but if you have a lot of read/write-intensive operations (big databases, for e.g.,) you may want to consider this.

NOTE: as always, the best way to speed up swap is not to need it in the first place - if you've got heavy swap partition activity, and you can possibly afford to do it, add more RAM. No matter what you do with your swap partition(s), accessing them is always going to be an order of magnitude or three slower than staying in RAM.

[edit] Using RAM virtual file systems

Here are instructions on how to use RAM as /tmp (temporary) or /var file systems. tmpfs(5) is suitable for desktops, because it automatically adjusts its file size, unlike mdmfs(8).

To set up a tmpfs(5) filesystem, enter into /etc/fstab:

tmpfs  /mydir2     tmpfs   rw,-s1g     0 0

To use the md(4) driver, add the following, or similar variable to /etc/rc.conf:

tmpmfs="YES"
tmpsize="3g"

mdmfs(8) can also be mounted through /etc/fstab:

md     /mydir1     mfs     rw,-s1g     0 0

mdmfs(8) can also mount /var on RAM, but this is only for operating systems that are read-only. On regular installs, files in /var are needed for the operating system to resume normally, which would be regularly flushed on a virtual /var file system.

varmfs="YES"
varmfs="512m"

Virtual RAM filesystem are shared with harddrive swapspace to add capacity. There must be enough combined swap and RAM capacity to contain the virtual filesystem. .iso images can be mounted on swap too. See also mdconfig and related filesystem ram manpages for more information.

[edit] Getting Hard Disk Information

Sometimes you need information about the model or manufacturing numbers of drives that are in a running system. If the hard disk supports SMART (most do), you can use the smartctl utility (available from sysutils/smartmontools ) to extract the model numbers. Running smartctl -i /dev/ad4 as root on my system gives output like this:

=== START OF INFORMATION SECTION ===
Device Model:    WDC WD2500JB-00EVA0
Serial Number:    WD-WCAEH1028140
Firmware Version: 15.05R15
Device is:        In smartctl database [for details use: -P show]
ATA Version is:  6
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Thu Dec 22 10:48:33 2005 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
Personal tools