FreeBSD 8 create tmp ramdisk

Scobee’s been on my ass for a few days now to create a ramdisk for the /tmp folder. I am not really confident about it since memory leaks could wreak havoc and it could render the server and data fucking useless, however he insisted, so the script below, should help you if you need to create a ramdisk anywhere for … whatever you may feel like you need.  I’ll cover the backups area anyway and save his ass like i always do.

Make sure you unmount the /tmp drive that is disk based first. You may find what’s locking /tmp from unmounting by doing a “lsof |grep tmp”. If you still have issues, then make all programs that start at server reboot to not actually start, and comment the tmp line from /etc/fstab. Then reboot, and /tmp would be off and you can run the script below.

#!/bin/sh
case “$1” in
create)
/sbin/mdmfs -M -S -o async -s 2560m md0 /tmp
/bin/chmod 777 /tmp
echo “2.5G ramdisk created on md0 and mounted on /tmp”
exit 0
;;
destory)
/sbin/umount /tmp
/sbin/mdconfig -d -u 0
echo “ramdisk umounted from /mnt and destory from md0”
;;
*)
echo “Usage: `basename $0` {create|destroy}” >&2
exit 64
;;
esac

Freebsd / Drives larger than 1tb / gpart

This has taken me more than it should have.

Okay long story short: If you’re installing FreeBSD, then you should know that it doesn’t support drives larger than 1 tb drives by default from sysinstall / fdisk / label.
Quick and easy once you learn it, you realise that you can get the job done really quick by using gpart.

Problems you may encounter:

———————————————————–
??(~)->gpart create -s gpt aacd1
gpart: geom ‘aacd1’: File exists

^^ This happens if you already tried (like i did) to mount the big 9 tb raid array through fdisk. Solution – dd the drives, and then you will erase the mbr, and it’s good to go:

??(~)->gpart show aacd1
=> 63 19503513477 aacd1 MBR (9.1T)
63 19503513477 – free – (9.1T)

??(~)-> dd if=/dev/zero of=/dev/aacd1 bs=1k count=1

??(~)->gpart show aacd1
gpart: No such geom: aacd1.

??(~)->gpart create -s gpt aacd1
aacd1 created

^^ And it works like a charm.
———————————————————–
??(~)->gpart show aacd1
=> 34 19503513533 aacd1 GPT (9.1T)
34 19503513533 – free – (9.1T)

Time to make a partition and get this over with:

??(~)->gpart add -t freebsd-ufs -l bigraid aacd1
aacd1p1 added

??(~)->newfs aacd1p1

Once the partition is loaded, just add it to fstab:

/dev/aacd1p1 /var/www/html ufs rw 2 2

Then do a “mount -a” and it’s finished.

Took me a while to figure all this out. Hope it makes your life easier.

LE: for optimizing the block size: newfs -O2 -U -b 65536 -f 8192 -i 65536 /dev/ad5p1

LEE: for destroying partitions:

??(~)->gpart delete -i 1 ad7
??(~)->gpart destroy ad7

htop with freebsd

Most of the times i use htop to check cpu threads usage in linux. I have quite a few freebsd servers, so i ran into some issues when installing htop on vanilla freebsd. Well, you need to make some adjustments so that htop works,  so here it goes:

First you have to dynamically load the linux object in the kernel:

kldload linux

Then we have to make this loading permanent so addlinux_enable=”YES” to /etc/rc.conf.

After this, install a linux layer:

cd /usr/ports/emulators/linux_base-fc4 (for some strange reason fc6 is not working for me)
make install distclean

Go to /etc/fstab and add the following line:

linproc /compat/linux/proc linprocfs rw 0 0

Mount the new filesystem: mount linproc and go to/usr/ports/sysutils/htop and install as usual.

Enjoy

configure: error: Cannot find OpenSSL’s – freebsd

configure: error: Cannot find OpenSSL’s <evp.h> freebsd

usually you get this error if openssl path is not specified when compiling php i got this error when compiling php-5.2.9.

solution:

cd /usr/ports/security/openssl

make install distclean

then add –with-ssl=/usr to the ./configure line for php.

should work like a charm

freebsd hdparm – diskinfo

For allof you who tried to find a  freebsd equivalent to hdparm, we have diskinfo. It’s fairly simple, although, i much more prefer hdparm for drive testing. Here is a sample output:

??([email protected])(08:43:16)
??(~)->diskinfo -c /dev/da0
/dev/da0
512             # sectorsize
72833679360     # mediasize in bytes (68G)
142253280       # mediasize in sectors
17433           # Cylinders according to firmware.
255             # Heads according to firmware.
32              # Sectors according to firmware.

I/O command overhead:
time to read 10MB block      0.202952 sec       =    0.010 msec/sector
time to read 20480 sectors  20.515689 sec       =    1.002 msec/sector
calculated command overhead                     =    0.992 msec/sector

————————————————————————————————-

??([email protected])(08:46:06)
??(~)->diskinfo -tv /dev/da0
/dev/da0
512             # sectorsize
72833679360     # mediasize in bytes (68G)
142253280       # mediasize in sectors
17433           # Cylinders according to firmware.
255             # Heads according to firmware.
32              # Sectors according to firmware.

Seek times:
Full stroke:      250 iter in   1.719489 sec =    6.878 msec
Half stroke:      250 iter in   1.513216 sec =    6.053 msec
Quarter stroke:   500 iter in   3.043343 sec =    6.087 msec
Short forward:    400 iter in   2.327002 sec =    5.818 msec
Short backward:   400 iter in   1.799896 sec =    4.500 msec
Seq outer:       2048 iter in   2.055626 sec =    1.004 msec
Seq inner:       2048 iter in   2.066084 sec =    1.009 msec
Transfer rates:
outside:       102400 kbytes in   1.782695 sec =    57441 kbytes/sec
middle:        102400 kbytes in   1.625616 sec =    62992 kbytes/sec
inside:        102400 kbytes in   2.253411 sec =    45442 kbytes/sec