Monday, December 31, 2012

Creating freeBSD vds or vps with zfs developed by Sun™

Recommend to make with 2nd disk
it is a example just we can create...
if you create zfs in main host disk, i am sure u cant boot next reboot :P

============================================
Prepare
---------
kern.geom.debugflags: 0 -> 16
freebsd82# dd if=/dev/zero of=/dev/ad0 bs=1m count=1

Build
------
freebsd82# zpool create -m /usr/ogcvps ogcdev /dev/ad0
freebsd82# zpool status
pool: ogcdev
state: ONLINE
scrub: none requested
config:

NAME      STATE    READ WRITE CKSUM
ogcdev    ONLINE   0       0         0
ad0         ONLINE   0       0         0

freebsd82# zfs set quota=10g ogcdev
freebsd82# zfs create ogcdev/ogcshell
freebsd82# zfs list
NAME USED AVAIL REFER MOUNTPOINT
ogcdev 112K 10.0G 21K /usr/ogcvps
ogcdev/ogcshell 21K 10.0G 21K /usr/ogcvps/ogcshell


freebsd82# zfs set quota=5g ogcdev/ogcshell
freebsd82# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/ad0s1a 81G 1.7G 73G 2% /
devfs 1.0K 1.0K 0B 100% /dev
ogcdev 10G 22K 10G 0% /usr/ogcvps
ogcdev/ogcshell 5.0G 21K 5.0G 0% /usr/ogcvps/ogcshell

freebsd82# zfs list
NAME USED AVAIL REFER MOUNTPOINT
ogcdev 114K 10.0G 22K /usr/ogcvps
ogcdev/ogcshell 21K 5.00G 21K /usr/ogcvps/ogcshell

freebsd82# cd /usr/src
freebsd82# make installworld DESTDIR=/usr/ogcvps/ogcshell
freebsd82# make distribution DESTDIR=/usr/ogcvps/ogcshell

============================================

FreeBSD CUSTOM kernel recompile


=========================
PREPARE 1st source kernel build world
=========================

oGcServ# cd /boot
oGcServ# cp -Rp kernel kernel.good-09-08-2011
### if stable then, stable-supfile, else standard-supfile
# if you have installed fastest_cvsup mirror go cmd:
oGcServ# csup -h `/usr/local/bin/fastest_cvsup -q -c us` /usr/share/examples/cvsup/standard-supfile
# else
oGcServ# csup -L 2 -h cvsup2.freebsd.org /usr/share/examples/cvsup/standard-supfile
oGcServ# cd /usr/src
oGcServ# less UPDATING - check for important notes
oGcServ# make -j4 buildworld &
oGcServ# make -j4 buildkernel &
oGcServ# make KODIR=/boot/kernel.release installkernel &
oGcServ# nextboot -k kernel.release
oGcServ# shutdown -r now
oGcServ# mv /boot/kernel.release /boot/kernel
oGcServ# mergemaster -p
oGcServ# make installworld
oGcServ# mergemaster -viU
oGcServ# shutdown -r now


===================
RECOMPILE CUSTOM
===================

oGcServ# cd /usr/src/
oGcServ# make -j4 buildkernel KERNCONF=OGCBOX &
oGcServ# make KODIR=/boot/kernel.ogcbox KERNCONF=OGCBOX installkernel &
oGcServ# nextboot -k kernel.ogcbox
oGcServ# shutdown -r now
oGcServ# cp -Rp kernel kernel.bak-29-08-2011
oGcServ# mv /boot/kernel.ogcbox to /boot/kernel
oGcServ# shutdown -r now

Note: putting " & " for backgroud process. even we got disconnect from interenet, the process remain in remote server as background. helpful for Myanmar users who are using internet from stupid no stable internet connection provider. like ME. lmao rofl



Howto check fast I/O, speed


[root@oGcServ ~]# wget cachefly.cachefly.net/100mb.test -O /dev/null
--2011-09-01 03:48:23-- http://cachefly.cachefly.net/100mb.test
Resolving cachefly.cachefly.net... 205.234.175.175
Connecting to cachefly.cachefly.net|205.234.175.175|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: `/dev/null'
100%[==========================================] 104,857,600 83.5M/s in 1.2s
2011-09-01 03:48:25 (83.5 MB/s) - `/dev/null' saved [104857600/104857600]


[root@oGcServ ~]# dd if=/dev/zero of=test.file bs=64k count=16k conv=fdatasync
16384+0 records in
16384+0 records out
1073741824 bytes (1.1 GB) copied, 17.6911 seconds, 60.7 MB/s
[root@oGcServ ~]#


Note: for BSD exclude 'condv=fdatasync'

FreeBSD boot error howto rescue


Yesterday i got some freeezzz my box fvkBSD while changing in loader.conf
If something wrong loader.conf, we can rescue setting from boot loader.
To fix variable setting:

1. reboot fvkBSD box
2. FreeBSD boot menu -> Press 6 to select "Escape to loader prompt"
3. In loader prompt, type: "show" there u can see loader setting. press page down and search wrong setting that you set before.
4. fix correct type: "set (variable)=(correct value)"
5 after set value, type: boot


Good Luck...

Ubuntu rc.d iptables

#!/bin/sh
#
#This is an Ubuntu adapted iptables script from gentoo
#(http://www.gentoo.org) which was originally distributed
#under the terms of the GNU General Public License v2
#and was Copyrighted 1999-2004 by the Gentoo Foundation
#
#This adapted version was intended for and ad-hoc personal
#situation and as such no warranty is provided.

. /lib/lsb/init-functions

IPTABLES_SAVE="/etc/default/iptables-rules"
SAVE_RESTORE_OPTIONS="-c"

checkrules() {
if [ ! -f ${IPTABLES_SAVE} ]
then
echo "Not starting iptables. First create some rules then run"
echo "\"/etc/init.d/iptables save\""
return 1
fi
}

save() {
/sbin/iptables-save ${SAVE_RESTORE_OPTIONS} > ${IPTABLES_SAVE}
return $?
}

start(){
checkrules || return 1
/sbin/iptables-restore ${SAVE_RESTORE_OPTIONS} < ${IPTABLES_SAVE}
return $?
}

case "$1" in
save)
echo -n "Saving iptables state..."
save
if [ $? -eq 0 ] ; then
echo " ok"
else
echo " error !"
fi
;;

start)
log_begin_msg "Loading iptables state and starting firewall..."
start
log_end_msg $?
;;

stop)
log_begin_msg "Stopping firewall..."
for a in `cat /proc/net/ip_tables_names`; do
/sbin/iptables -F -t $a
/sbin/iptables -X -t $a

if [ $a == nat ]; then
/sbin/iptables -t nat -P PREROUTING ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT ACCEPT
elif [ $a == mangle ]; then
/sbin/iptables -t mangle -P PREROUTING ACCEPT
/sbin/iptables -t mangle -P INPUT ACCEPT
/sbin/iptables -t mangle -P FORWARD ACCEPT
/sbin/iptables -t mangle -P OUTPUT ACCEPT
/sbin/iptables -t mangle -P POSTROUTING ACCEPT
elif [ $a == filter ]; then
/sbin/iptables -t filter -P INPUT ACCEPT
/sbin/iptables -t filter -P FORWARD ACCEPT
/sbin/iptables -t filter -P OUTPUT ACCEPT
fi
done
log_end_msg 0
;;

restart)
log_begin_msg "Restarting firewall..."
for a in `cat /proc/net/ip_tables_names`; do
/sbin/iptables -F -t $a
/sbin/iptables -X -t $a
done;
start
log_end_msg $?
;;

*)
echo "Usage: /etc/init.d/iptables {start|stop|restart|save}" >&2
exit 1
;;
esac

exit 0

http:// mirror instead of ftp:// for pkg manage


all you know our myanmar users restrict ftp ports, i got problem too.. when i use pkg_add package in freebsd... so i would like to advice to replace http mirror instead of ftp..

if you are using bash shell..
# export PACKAGEROOT='http://ftp.FreeBSD.org'

if you are using csh default shell...
# setenv PACKAGEROOT='http://ftp.FreeBSD.org'

i hope that will help you more... :P