User:FzZzT
From FBSD_tips
Contents |
[edit] Contributed Articles
- Giving a jail multiple IPs with pf and NAT
- Log monitoring with Censor
- Making ssh-agent and gpg-agent persistent
- FzZzT/Jail Tools
[edit] Tips
- You can remove the "X-Authentication-Warning" headers (and log messages) from email sent via Apache (e.g. from PHP) by uncommenting the line "#Ft/etc/mail/trusted-users" in /etc/mail/submit.cf and adding the "www" user to /etc/mail/trusted-users. You can then set mail.additional_parameters in Apache configuration files to set "-f user@host" for each virtual host (or whatever).
- To disable the ident connection Sendmail makes, uncomment the "#O Timeout.ident=5s" line in /etc/mail/submit.cf and change it to "#O Timeout.ident=0".
[edit] To do
- Installing FreeBSD onto a USB drive (with FAT partition).
- http://bsdimp.blogspot.com/ 20071016
- Using SSHFS as your home directory (w/persistent ssh-agent).
- Hard disk stress/verification testing
#!/bin/sh
# Hard disk stress test 2.0 by Josh Endries
start_date=`date +%s`
clean_up_files () { echo "Cleaning up files." && rm -rf ${output_mount}; }
clean_up_image () { echo "Cleaning up image." && umount ${image_mount} && mdconfig -du${image_device_number} && rmdir ${image_mount}; }
clean_up () { clean_up_image && clean_up_files; }
stats () {
current_date=`date +%s`
total_files=`cat ${image_mount}total_files`
awk "BEGIN { print \"$$:\", (${current_date} - ${start_date}) / ${total_files}, \"files/second\"; }"
}
trap "clean_up" 0
trap "stats" 1
trap "exit 1" 2 3 15
output_mount="$1"
output_mount=${output_mount:=/tmp}
output_mount="${output_mount}/$$/"
file_size="$2"
file_size=${file_size:=100}
image_mount="/mnt/$$/"
image_size=`expr ${file_size} + \`expr ${file_size} / 9\``
mkdir -p "${image_mount}" "${output_mount}"
free_space=`df -m ${output_mount} | tail -1 | sed 's/ */ /g' | cut -d ' ' -f 4`
echo "Using ${file_size} MB files. Estimating `expr ${free_space} / ${file_size}` files."
echo "Creating ${image_size} MB image."
image_device="`mdconfig -a -t malloc -s ${image_size}m -o reserve`"
image_device_number=`echo ${image_device} | sed 's/md//'`
newfs /dev/${image_device} >/dev/null
mount /dev/${image_device} ${image_mount} >/dev/null
dd if=/dev/random of=${image_mount}input bs=${file_size}m count=1 >/dev/null 2>&1
image_hash=`sha256 -q ${image_mount}input`
total_files=0
while [ 1 ]; do
mkdir -p "${output_mount}"
echo -n "Creating files: "
files=0
stop=0
while [ $stop -eq 0 ]; do
cp ${image_mount}input ${output_mount}${files} 2>/dev/null && {
[ "${image_hash}" = "`sha256 -q ${output_mount}${files}`" ] && {
diff ${image_mount}/input ${output_mount}${files} && {
total_files=`expr ${total_files} + 1`
echo "${total_files}" > ${image_mount}total_files
echo -n "."
} || { echo "ERROR: File $$/${files} is different."; }
} || { echo "ERROR: File $$/${files} doesn't hash identically."; }
} || { echo "ERROR: File $$/${files} didn't copy." && stop=1; }
files=`expr ${files} + 1`
done
clean_up_files
done
#!/bin/sh -e
[ -z "$1" ] && {
echo "Usage: $0 <image name>"
exit 1
}
host_root="/jails"
jail_name="$1"
jail_name_sanitized=`echo ${jail_name} | sed 's/[^A-Za-z0-9]/_/g'`
jail_root="${host_root}/${jail_name}"
mkdir -p ${jail_root}/root
dd if=/dev/zero of=${jail_root}/image bs=1m count=512
jail_image=`mdconfig -a -t vnode -f ${jail_root}/image`
newfs ${jail_image}
mount /dev/${jail_image} ${jail_root}/root
# Create the jail's directory and install the files.
cd /usr/src
make installworld DESTDIR=${jail_root}/root
make distribution DESTDIR=${jail_root}/root
umount ${jail_root}/root
dump -a -C 32 -f ${host_root}/${jail_name}.dump /dev/${jail_image}
restore -rNf ${host_root}/${jail_name}.dump
mdconfig -du${jail_image}
rm -r ${jail_root}
bzip2 ${host_root}/${jail_name}.dump
#!/bin/sh -e
[ -z "$1" -o -z "$2" ] && {
echo "Usage: $0 <jail name> <image name>"
exit 1
}
host_root="/jails"
jail_name="$1"
jail_name_sanitized=`echo ${jail_name} | sed 's/[^A-Za-z0-9]/_/g'`
jail_root="${host_root}/${jail_name}"
image_name=`echo "$2" | sed 's/\.bz2$//' | sed 's/\.dump$//'`
[ -f "${host_root}/${image_name}" ] && {
restore_command="cat ${host_root}/${image_name}"
} || {
[ -f "${host_root}/${image_name}.dump" ] && {
restore_command="cat ${host_root}/${image_name}.dump"
} || {
[ -f "${host_root}/${image_name}.dump.bz2" ] && {
restore_command="bunzip2 -ck ${host_root}/${image_name}.dump.bz2"
} || {
echo "ERROR: No image file found."
exit 1
}
}
}
# Create the jail's directory and install the files.
mkdir -p ${jail_root}/root
cd ${jail_root}/root
${restore_command} | restore -rf -
# Create an initial mtree listing.
mtree -c -p ${jail_root}/root | bzip2 -c > ${jail_root}/root.mtree.bz2
# Create a config file for rc.conf.
cat > "${jail_root}/conf" << EOF
jail_${jail_name_sanitized}_devfs_enable="NO"
jail_${jail_name_sanitized}_devfs_ruleset="devfsrules_jail"
jail_${jail_name_sanitized}_hostname="${jail_name}"
jail_${jail_name_sanitized}_ip="192.168.0.10"
jail_${jail_name_sanitized}_rootdir="${jail_root}/root"
#jail_${jail_name_sanitized}_interface=""
#jail_${jail_name_sanitized}_exec_start="/bin/sh /etc/rc"
#jail_${jail_name_sanitized}_exec_afterstart0="/bin/sh command"
#jail_${jail_name_sanitized}_exec_stop="/bin/sh /etc/rc.shutdown"
#jail_${jail_name_sanitized}_fdescfs_enable="NO"
#jail_${jail_name_sanitized}_procfs_enable="NO"
#jail_${jail_name_sanitized}_mount_enable="NO"
#jail_${jail_name_sanitized}_fstab=""
#jail_${jail_name_sanitized}_flags="-l -U root"
EOF
[edit] top memory display
Mem: 15M Active, 830M Inact, 25M Wired, 29M Cache, 111M Buf, 97M Free Swap: 2048M Total, 2048M Free
Active: Memory currently "in use" (e.g. allocated, a 10 MB array) Inact: Memory not in use, but allocated to processes (e.g. my 10 MB after I free() the array) Wired: Memory that is "wired down" and cannot be swapped. Cache: Used for VM-level disk caching Buf: Free: Available for use Swap: Swap, disk-based memory extension (not good!)
<jer> free memory is total memory - (total active + total inactive + total cached)
FzZzT 05:49, 26 November 2007 (UTC)
