sexta-feira, março 28, 2008

Commands useful FreeBSD

Hardware Informations

# sysctl hw.model # CPU model
# sysctl hw # Gives a lot of hardware information
# sysctl vm # Memory usage
# dmesg | grep "real mem" # Hardware memory
# sysctl -a | grep mem # Kernel memory settings and info
# sysctl dev # Configured devices
# pciconf -l -cv # Show PCI devices
# usbdevs -v # Show USB devices
# atacontrol list # Show ATA devices

Load, statistics and messages

# systat -vmstat 1 # BSD summary of system statistics (1 s intervals)
# systat -tcp 1 # BSD tcp connections (try also -ip)
# systat -netstat 1 # BSD active network connections
# systat -ifstat 1 # BSD network traffic through active interfaces
# systat -iostat 1 # BSD CPU and and disk throughput

User

# pw groupmod admin -m newmember # Add a new member to a group

Limits

# sysctl -a # View all system limits
# sysctl kern.maxfiles=XXXX # maximum number of file descriptors
kern.ipc.nmbclusters=32768 # Permanent entry in /etc/sysctl.conf
kern.maxfiles=65536 # Typical values for Squid
kern.maxfilesperproc=32768
kern.ipc.somaxconn=8192 # TCP queue. Better for apache/sendmail
# sysctl kern.openfiles # How many file descriptors are in use
# sysctl kern.ipc.numopensockets # How many open sockets are in use

Reset root password

* Boot a live CD or installation CD into a rescue mode which will give you a shell.
* Find the root partition with fdisk e.g. fdisk /dev/sda
* Mount it and use chroot:

# mount -o rw /dev/ad4s3a /mnt
# chroot /mnt # chroot into /mnt
# passwd
# reboot

Kernel modules

# kldstat # List all modules loaded in the kernel
# kldload crypto # To load a module (here crypto)
# kldunload crypto # down module

Compile Kernel

FreeBSD

To modify and rebuild the kernel, copy the generic configuration file to a new name and edit it as needed. It is however also possible to edit the file GENERIC directly.

# cd /usr/src/sys/i386/conf/
# cp GENERIC MYKERNEL
# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL
# make installkernel KERNCONF=MYKERNEL


To rebuild the full OS:

# make buildworld # Build the full OS but not the kernel
# make buildkernel # Use KERNCONF as above if appropriate
# make installkernel
# reboot
# mergemaster -p # Compares only files known to be essential
# make installworld
# mergemaster # Update all configuration and other files
# reboot

For small changes in the source, sometimes the short version is enough:

# make kernel world # Compile and install both kernel and OS
# mergemaster
# reboot

Disk usage

# du -sh * # Directory sizes as listing
# du -csh # Total directory size of the current directory
# du -ks * | sort -n -r # Sort everything by size in kilobytes
# ls -lSr # Show files, biggest last

Network

# netstat -rn # Linux, BSD and UNIX
Add and delete a route

FreeBSD

# route add 212.117.0.0/16 192.168.1.1
# route delete 212.117.0.0/16
# route add default 192.168.1.1

Nenhum comentário: