Showing posts with label BSD. Show all posts
Showing posts with label BSD. Show all posts

Wednesday, June 20, 2012

HowTo: Enable Wake-on-LAN on FreeBSD

Wake-on-LAN also know as WOL is the ability to switch on a computer that is connected to a network (local or otherwise) by means of a special network message called a magic packet. This magic packet contains the MAC address of the destination computer. If the destination computer has a network interface card that supports WOL then the system wakes up.

In this post I'll describe how to Wake-on-LAN a FreeBSD destination computer so that it can be turned on from another computer.

For sake of simplicity I've broken down the procedure into a few steps:
1) Enable WOL in BIOS
2) Check for driver WOL support
3) Collect network interface information
4) Wake up computer from local network
5) Wake up computer from internet

1) Enable WOL in BIOS

These days pretty much all integrated or otherwise NICs support Wake-on-LAN, however more often than not you'll need to enable it in the BIOS. There are literally hundreds of BIOS around but look for the typical options: "Enable Wake-on-LAN", "Enable Wake on PCI" and "Enable Power of PCIE Devices".

2) Check for driver WOL support

With each FreeBSD release more and more ethernet drivers get support for Wake-on-LAN. To check the list of drivers with WOL support in your FreeBSD release (in my case 7.4-RELEASE) run:
  1. $ grep -l IFCAP_WOL /usr/src/sys/dev/*/*.c
    /usr/src/sys/dev/ae/if_ae.c
    /usr/src/sys/dev/age/if_age.c
    /usr/src/sys/dev/alc/if_alc.c
    /usr/src/sys/dev/ale/if_ale.c
    /usr/src/sys/dev/e1000/if_em.c
    /usr/src/sys/dev/e1000/if_lem.c
    /usr/src/sys/dev/fxp/if_fxp.c
    /usr/src/sys/dev/jme/if_jme.c
    /usr/src/sys/dev/nfe/if_nfe.c
    /usr/src/sys/dev/nge/if_nge.c
    /usr/src/sys/dev/re/if_re.c
    /usr/src/sys/dev/sis/if_sis.c
    /usr/src/sys/dev/ste/if_ste.c
    /usr/src/sys/dev/stge/if_stge.c
    /usr/src/sys/dev/txp/if_txp.c
    /usr/src/sys/dev/vge/if_vge.c
    /usr/src/sys/dev/vr/if_vr.c

Now compare the list of WOL supported drivers with the driver attached to your network interface:
 $ ifconfig -m   
 re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500  
     options=389b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_UCAST,WOL_MCAST,WOL_MAGIC>  
     capabilities=4399b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,WOL_UCAST,WOL_MCAST,WOL_MAGIC,VLAN_HWTSO>  
     ether 00:aa:11:bb:22:cc  
     inet 192.168.1.3 netmask 0xffffff00 broadcast 192.168.1.255  
     media: Ethernet autoselect (100baseTX <full-duplex>)  
     status: active  
     supported media:  
         media autoselect mediaopt flowcontrol  
         media autoselect  
         media 1000baseTX mediaopt full-duplex,flowcontrol,master  
         media 1000baseTX mediaopt full-duplex,flowcontrol  
         media 1000baseTX mediaopt full-duplex,master  
         media 1000baseTX mediaopt full-duplex  
         media 1000baseTX mediaopt master  
         media 1000baseTX  
         media 100baseTX mediaopt full-duplex,flowcontrol  
         media 100baseTX mediaopt full-duplex  
         media 100baseTX  
         media 10baseT/UTP mediaopt full-duplex,flowcontrol  
         media 10baseT/UTP mediaopt full-duplex  
         media 10baseT/UTP  
         media none  
 plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST,NEEDSGIANT> metric 0 mtu 1500  
 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384  
     inet6 fe80::1 prefixlen 64 scopeid 0x4   
     inet6 ::1 prefixlen 128   
     inet 127.0.0.1 netmask 0xff000000   
By analysing the output of ifconfig one can notice that I have re driver attached to network card. Also the re0 card not only is capable of WOL but also it is already setup to use it.

FreeBSD is extremely well documented and as such WOL support can be confirmed in re(4) man page.

3) Collect network interface information

From the output of ifconfig -m I can write down the MAC address for re0, 00:aa:11:bb:22:cc.
  1. $ ifconfig -m | grep ether        ether 00:aa:11:bb:22:cc

4) Wake up computer from local network

With the destination computer turned off, from the computer that will be used to send the magic WOL packet, install the net/wakeonlan port and run it:
  1. # cd /usr/ports/net/wakeonlan
  2. # make install clean
  3. # rehash
  4. # wakeonlan -i 192.168.1.255 00:aa:11:bb:22:cc

Replace 192.168.1.255 with the broadcast from your network. 192.168.1.255 is the broadcast address for a 192.168.1.x subnet which is the case of my local network and 00:aa:11:bb:22:cc is MAC address of the destination computer.

It should be noted that net/wakeonlan and similar applications are available in all Unix-like operating systems.

5) Wake up computer from internet

This involves enabling port forwarding of UDP port 9 to the destination computer in the router's administration webpage. To fully benefit from WOL you should configure a dynamic DNS service.

Afterwards to issue the wake up command you can use websites such as http://wakeonlan.me, Android applications (Wake on Lan) or any other Wake-on-LAN application (every Unix-like system as an alternative available). Just make sure to use your dynamic DNS provided address and the destination computer's MAC.

Thursday, June 7, 2012

HowTo: Install and setup MiniDLNA on FreeBSD

MiniDLNA is a server software with the aim of being fully compliant with DLNA/UPnP-AV clients. MiniDLNA is used to serve multimedia files such as music, videos and picture to clients on a given network.

MiniDLNA employs Universal Plug and Play (UPnP) thus you can have clients such as TVs, consoles and smartphones.

In this post I'll describe the steps needed to install and configure it to run on FreeBSD, though the steps were performed on 7.4-RELEASE they'll work on more recent FreeBSD branches such as 8.x and 9.x.

Let's start by installing the net/minidlna port:
  1. # cd /usr/ports/net/minidlna
  2. # make config-recursive
  3. # make install clean

Having installed the port, it's time to edit the configuration file. As an example, I'll leave my own as reference. Make sure that you edit network_interface, media_dir and friendly_name.
  1. # vim /usr/local/etc/minidlna.conf

    # port for HTTP (descriptions, SOAP, media transfer) traffic
    port=8200

    # network interfaces to serve, comma delimited
    network_interface=re0

    # set this to the directory you want scanned.
    # * if have multiple directories, you can have multiple media_dir= lines
    # * if you want to restrict a media_dir to a specific content type, you
    #   can prepend the type, followed by a comma, to the directory:
    #   + "A" for audio  (eg. media_dir=A,/home/jmaggard/Music)
    #   + "V" for video  (eg. media_dir=V,/home/jmaggard/Videos)
    #   + "P" for images (eg. media_dir=P,/home/jmaggard/Pictures)
    media_dir=V,/home/samba/public/movies
    media_dir=V,/mnt/1/tv
    media_dir=V,/mnt/2/anime
    media_dir=A,/mnt/1/music
    media_dir=P,/mnt/1/photos

    # set this if you want to customize the name that shows up on your clients
    friendly_name=FreeBSD DLNA Server

    # set this if you would like to specify the directory where you want MiniDLNA to store its database and album art cache
    db_dir=/var/db/minidlna

    # set this if you would like to specify the directory where you want MiniDLNA to store its log file
    log_dir=/var/db/minidlna

    # set this to change the verbosity of the information that is logged
    # each section can use a different level: off, fatal, error, warn, info, or debug
    log_level=general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn

    # this should be a list of file names to check for when searching for album art
    # note: names should be delimited with a forward slash ("/")
    album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

    # set this to no to disable inotify monitoring to automatically discover new files
    # note: the default is yes
    inotify=yes

    # set this to yes to enable support for streaming .jpg and .mp3 files to a TiVo supporting HMO
    enable_tivo=no

    # set this to strictly adhere to DLNA standards.
    # * This will allow server-side downscaling of very large JPEG images,
    #   which may hurt JPEG serving performance on (at least) Sony DLNA products.
    strict_dlna=no

    # default presentation url is http address on port 80
    #presentation_url=http://www.mylan/index.php

    # notify interval in seconds. default is 895 seconds.
    notify_interval=900

    # serial and model number the daemon will report to clients
    # in its XML description
    serial=1337
    model_number=1

    # specify the path to the MiniSSDPd socket
    #minissdpdsocket=/var/run/minissdpd.sock

    # use different container as root of the tree
    # possible values:
    #   + "." - use standard container (this is the default)
    #   + "B" - "Browse Directory"
    #   + "M" - "Music"
    #   + "V" - "Video"
    #   + "P" - "Pictures"
    # if you specify "B" and client device is audio-only then "Music/Folders" will be used as root
    #root_container=.

To have MiniDLNA working properly the dlna user must be made owner of the /var/db/minidlna directory:
  1. # mkdir -p /var/db/minidlna
  2. # chown dlna:dlna /var/db/minidlna

To start using MiniDLNA immediately issue the following command:
  1. # /usr/local/etc/rc.d/minidlna onestart

If you want to have it start up automatically whenever FreeBSD boots, add it to /etc/rc.conf like so:
  1. # echo 'minidlna_enable="YES"' >> /etc/rc.conf

Finally MiniDLNA's log file can be monitored for errors:
  1. # tail -f /var/db/minidlna/minidlna.log

MiniDLNA it's quite simple and lightweight however it is missing features that can be found in more complete UPnP servers. Those operating on old hardware might find it very useful.

Be advised that if you're planning on sharing multimedia files over a local network composed mainly of desktops and laptops, NFS and Samba are more flexible filesharing alternatives. On the other hand, if you want to stream to a TV, console or smartphone then by all means go for an UPnP server like MiniDLNA or MediaTomb.

If you're using an Android smartphone have a look at the MediaHouse app. From my experience it works just fine with MiniDLNA.

Monday, May 28, 2012

HowTo: Mount UFS partition on CentOS / SL 6.2

By default RHEL clones such as CentOS and Scientific Linux don't come with UFS filesystem support.

However the ELRepo repository has the kmod-ufs package which provides the much needed kernel module. As such enabling ufs support on RHEL/CentOS/SL 6.2 consists of adding the ELRepo repository, installing and loading the kernel module for UFS.

The required steps are:
  1. $ su
  2. # rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
  3. # rpm -Uvh http://elrepo.org/elrepo-release-6-4.el6.elrepo.noarch.rpm
  4. # yum update
  5. # yum install kmod-ufs
  6. # modprobe ufs

Now that we have kernel support for UFS let's proceed to identify the partition(s) with UFS filesystems:
  1. # fdisk -l /dev/sdb
 
 Disk /dev/sdb: 203.9 GB, 203928109056 bytes  
 255 heads, 63 sectors/track, 24792 cylinders  
 Units = cylinders of 16065 * 512 = 8225280 bytes  
 Sector size (logical/physical): 512 bytes / 512 bytes  
 I/O size (minimum/optimal): 512 bytes / 512 bytes  
 Disk identifier: 0x90909090  
   Device Boot   Start     End   Blocks  Id System  
 /dev/sdb1        1    1968  15807928+  7 HPFS/NTFS  
 /dev/sdb2      1969    7067  40957717+ a5 FreeBSD  
 /dev/sdb3  *    7068    12166  40957717+ a5 FreeBSD  

In the BSD world slices are subdivided into partitions. Where Linux fdisk sees a FreeBSD partition that partition is in fact a BSD slice with internal partitions. Taking a peek at the output of /var/log/messages helps in identifying which are partitions that can be mounted.

For example in my system:

  1. # grep /dev/sdb /var/log/messages
 May 24 21:44:33 athon kernel: sda5 sdb2: <bsd: sdb5 sdb6 sdb7 sdb8 sdb9 >  
 May 24 21:44:33 athon kernel: sda6 sda7 sda8 sdb3: <bsd: sdb10 sdb11 sdb12 sdb13 >  
 May 28 19:39:09 athon kernel: sda5 sda6 sdb2: <bsd: sdb5 sdb6 sdb7 sdb8 sdb9 >  
 May 28 19:39:09 athon kernel: sda7 sda8 sdb3: <bsd: sdb10 sdb11 sdb12 sdb13 >  

What does this mean? sdb2, sdb3, sdb5, sdb6, sdb7, sdb8, sdb9, sdb10, sdb11, sdb12 and sdb13 are FreeBSD UFS partitions.

To mount a FreeBSD UFS partition:
  1. # mount -t ufs -o ufstype=ufs2,ro /dev/sdb2 /mnt/

In which -t ufs -o ufstype=ufs2,ro identify the UFS filesystem as being UFS2 and mounted as read-only.

Sunday, May 13, 2012

HowTo: Install and run NetBSD on Virtualbox

NetBSD attracts me.

Maybe it's the philosophy being it... or maybe it just the old BSD daemon holding the flag on top of computer. Regardless of the reason, I've been toying with the idea of installing NetBSD on my Athon XP 3200+ nForce2 old desktop for a while now.

However the only instructions I found to convert a NetBSD 5.1.2 CD image into an USB bootable install medium involved using NetBSD. This chicken-egg dilema lead me to VirtualBox 4.1.14.

Just a few seconds after booting the install image into the VirtualBox machine it kernel panicked with the following error:
 uvm_fault(0xc0b82a00, 0, 1) -> 0xe 
 fatal page fault in supervisor mode 
 trap type 6 code 0 eip c0100d27 cs 8 eflags 3046 cr2 0 ilevel 1 
 kernel: supervisor trap page fault, code=0 
 Stopped in pid 0.19 (system) at netbsd:Xspllower+0x17: addb %al,0(%eax) 
 db{0} 
Just the luck heh?

The workaround? VBoxSDL.

VBoxSDL is a simple graphical user interface (GUI) that lacks the nice point-and-click support which VirtualBox, our main GUI, provides. VBoxSDL is currently primarily used internally for debugging VirtualBox and therefore not officially supported.

To be able to install NetBSD 5.1.2 on VirtualBox 4.1.14, assuming the virtual machine is name "NetBSD", you'll have to use VBoxSDL like this:
  1. $ VBoxSDL --norawr0 --startvm NetBSD

Now you'll be able to install NetBSD without any issues.

The problem is when you, in your sweet innocence, reboot the system and VirtualBox isn't able to start the vm stating that:
 Failed to open a session for the virtual machine NetBSD. 
 The virtual machine 'NetBSD' has terminated unexpectedly during startup because of signal 11. 
 Details 
 Result Code: NS_ERROR_FAILURE (0x80004005) 
 Component: Machine 
 Interface: IMachine {5eaa9319-62fc-4b0a-843c-0cb1940f8a91} 

The workaround? Yes you've guessed... VBoxSDL:
  1. $ VBoxSDL --nopatm --startvm NetBSD

Peace at last. I can finally muck around NetBSD :D

For reference:
 --[no]rawr0 Enable or disable raw ring 3 
 --[no]patm Enable or disable PATM 
Sources:
http://download.virtualbox.org/virtualbox/UserManual.pdf
http://chvnx.com/post/18341637412/netbsd-in-virtualbox
VBoxSDL --help

Saturday, May 12, 2012

Tip: Merge PDF files into a single PDF using Pdftk

In a previous post I've explained how to extract pages from a PDF document.

Funny enough a few days latter I needed to merge some PDF files into a single document, instead of hunting the web for a Windows application to do that (I have to use Windows at work) I used scp to send the files to the home server, ran pdftk there and scp the merged PDF back ;)

So today I'll use Pdftk this time to merge several PDF documents into a single PDF.

Start by installing Pdftk if you haven't using your distributions package manager:
  • Instructions for installing Pdftk for FreeBSD can be found here
  • If you are using a Debian based distribution issue apt-get install pdftk.
  • Users of RPM distribution's such as RHEL, CentOS, Scientific Linux and Fedora can install it by running yum install pdftk.
  • To install the program on Gentoo use emerge pdftk.
Now onto using Pdftk for our purpose!

The steps to merge PDF documents into a single PDF consist of:

  1. $ cd change_to_directory_with_target_pdfs
  2. $ pdftk first.pdf second.pdf third.pdf cat output merged-pdf.pdf

The PDF should be listed in the order in which they are to be placed in the final document. More information on Pdftk can be found using man pdftk.

Monday, May 7, 2012

Tip: Split selected pages from PDF document using Pdftk

Pdftk is a simple tool for manipulating PDF documents that runs in FreeBSD, Linux, Mac OS X, Solaris and Windows. With it the user can merge PDF documents, repair corrupted PDF, rotate PDF pages or document and extract selected pages from a PDF document creating a new document among other features.

BSD Magazine is a great and free magazine that deals with a wide range of BSD related subjects. The latest issue had a particular article that I felt I wanted to keep close to me.

Using Pdftk I was able to extract the pages that composed the article and keep it in a new PDF document.

Installing Pdftk on FreeBSD is a matter of changing to the print/pdftk port and issuing make install clean, like so:

  1. $ su
  2. # cd /usr/ports/print/pdftk
  3. # make install clean

Make sure to build lang/gcc46 with the JAVA Enable the Java frontend (i386 and amd64 only) OPTION selected or else the build process will fail (take it from me I learned it the hard way).

If you prefer to use packages instead of the ports tree, issue the following commands instead:

  1. $ su
  2. # pkg_add -r pdftk

Now for the fun part: using Pdftk on the this months' BSD Magazine as an example. Start by downloading BSD Magazine 5/2012 issue which you can find here.

I wanted to extract the Hardening FreeBSD with TrustedBSD and Mandatory Access Controls article which runs from page 46 to 49, this how to do it using Pdftk:
  1. $ pdftk 'BSD_05_2012.pdf' cat 46-49 output 'Hardening-FreeBSD-with-TrustedBSD-and-MAC.pdf'

You can find plenty of other uses for Pdftk in applications man page:
  1. $ man pdftk

Wednesday, May 2, 2012

Tip: Fix nmap "Error compiling our pcap filter: icmp7 not supported" on FreeBSD

I was going to start Nmap 5.61TEST5 on FreeBSD when it bricked with the following error:
 Starting Nmap 5.61TEST5 ( http://nmap.org ) at 2012-05-02 15:17 WEST  
 Error compiling our pcap filter: icmp6 not supported  
Found that weird because last time I used security/nmap it worked fine but then again that was something like 3 years ago and the port and the application have been updated since. This lead me to think that most likely an OPTION had been introduced to the port:

  1. # cd /usr/ports/security/nmap
  2. # make config===> No options to configure

While investigating the issue I came across problem report ports/159376: security/nmap 5.59BETA1 not working which described the cause of the problem: since NMAP 5.59BETA1 that there was no option to build the port without IPv6 support.

I was pretty sure I've disabled IPv6 and I confirmed that:

  1. # grep INET6 /etc/src.confWITHOUT_INET6=YES

Fortunately since NMAP 5.61TEST2 a patch was added that introduced a workaround for systems build with WITHOUT_INET6 by using net/libpcap.

This is also documented under /usr/ports/security/nmap/Makefile:
 # XXX: Workaround if OS is build with WITHOUT_INET6  
 # PR: ports/159376  
 #  
 # Note: If this option is specified in src.conf it has to  
 # be defined as param -DWITHOUT_INET6 during build time  
 # since the port system has no access to src.conf  
 .if defined(WITHOUT_INET6)  
 LIB_DEPENDS+= pcap.1:${PORTSDIR}/net/libpcap  
 CONFIGURE_ARGS+= --with-libpcap=${LOCALBASE}  
 .endif
The -DWITHOUT_INET6 option needs to be passed to make while building the port, like so:

  1. # make deinstall clean
  2. # make -DWITHOUT_INET6 install clean

Nothing like well documented problem reports and Makefiles ;)

Friday, April 20, 2012

Tip: Fixing Chromuim not compiling with base GCC error on FreeBSD

I haven't updated the ports tree for a month or so imagine my surprise when portmaster aborted with the following message:
 ===>>> Launching child to update chromium-17.0.963.79 to chromium-18.0.1025.162  

 ===>>> Port directory: /usr/ports/www/chromium  

     ===>>> This port is marked IGNORE  

     ===>>> does not compile with base gcc  

     ===>>> If you are sure you can build it, remove the  

         IGNORE line in the Makefile and try again.  

 ===>>> Update for chromium-17.0.963.79 failed  

 ===>>> Aborting update  

Oh!

Quickly browsed through /usr/ports/UPDATING and didn't notice any entry on www/chromium so the next step was checking /usr/ports/www/chromium/Makefile and yes there was an IGNORE line.

I was pretty sure I didn't change the default buid options last time so I browsed to http://www.freshports.org/www/chromium/ and noticed that on chromium-18.0.1025.142 gcc46 and clang were introduced as compilers as base gcc became too old.

Upon running make config on the port I noticed that I hadn't a compiler defined so it was a matter to enabling GCC46 and running portmaster once again to update Chromium.

Of course you can use CLANG instead if you prefer.

Friday, April 13, 2012

HowTo: Get etkey and Punbuster files on Enemy Territory

As of October 2011 EvenBalance ended it's Punkbuster support for Wolfenstein: Enemy Territory. As such, fresh installs of Enemy Territory are without the required etkey file and new Punkbuster GUID aren't generated.

What does this mean to the end user?

On a fresh install you'll need:
  1. etkey
  2. updated Punkbuster files
To circumvent these issues the community came up with the following solutions:
  1. point to http://etkey.org/pages/etkey-home.php, press the Get an ETKEY button, download the file and place it in ~/.etwolf/etmain/
  2. download the last up to date Punkbuster files from here, extract the files and placed them in a directory named pb in ~/.etwolf/
I'll update or create HowTo on how to install and setup Wolfenstein: Enemy Territory in a near future.

Thursday, April 12, 2012

Tip: Enemy Territory Master Server is back online!

Wolfenstein: Enemy Territory is once again online as announced at the Splash Damage Forum. The post can be found here.

Paul's interim master server is still working and most likely will continue to do so. So if you've used my tip to use the interim master server you are advised to remove the interim server address from the /etc/hosts file.

Happy fragging!

Monday, April 9, 2012

HowTo: fsck an ext2 partition in FreeBSD

The fsck available in FreeBSD's base system doesn't work on Linux file formats such as ext2 and ext3. For that end one first needs to install sysutils/e2fsprogs.

Bellow I'll explain how to install sysutils/e2fsprogs and use the supplied fsck.ext2 on a ext2 partition.

First, install the port:
$ su
# cd /usr/ports/sysutils/e2fsprogs
# make install clean
# rehash

Now the fsck.ext2, fsck.ext3 and fsck.ext4 commands are available. Assuming the /dev/ad4s1 as being the faulty partition, run:

# fsck.ext2 /dev/ad4s1
e2fsck 1.42 (29-Nov-2011)
/dev/ad4s1 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/ad4s1: 37/10040 files (13.5% non-contiguous), 13062/40128 blocks

And that's it ;)

Sunday, March 25, 2012

Tip: Improve NVIDIA driver performance on FreeBSD

When my desktop northbridge fan died I stopped both playing Enemy Territory and using FreeBSD to do so. I've recently replaced the northbridge cooling and went back to install FreeBSD, NVIDIA drivers for the graphics card and Enemy Territory.

I use the same demo file to benchmark Enemy Territory since 2003 and imagine my surprise as I score 33 FPS when I usually achieved ~100 FPS on the same exact setup under FreeBSD.

With X11 running I dropped to the ttyv0 and saw a suspicious message "NVRM: detected agp.ko, aborting NVIDIA AGP setup".

I suspected that FreeBSD AGP module agp.ko wasn't playing nice with NVIDIA's AGP module.

So I went back to my post on configuring NVIDIA driver on FreeBSD and read NVIDIA README /usr/local/share/doc/NVIDIA_GLX-1.0/README that is installed with the port.

Adding hint.agp.0.disabled="1" to /boot/device.hints and Option "NvAGP" "1" under the Device section of /etc/X11/xorg.conf fixed the problem.

Upon rebooting and running the benchmark again I scored 98,3 FPS which is close to 3x the score without NVIDIA's AGP module!

The solution was in both my old post and NVIDIA's README file all along ;)

Sunday, March 18, 2012

Tip: Fix Enemy Territory empty server list

Ever since my desktop's northbridge fan died I stopped playing Enemy Territory. Luckily I've finally replaced the fan so fired ET up and noticed that no server was listed.

It seems that as of late the Enemy Territory's masterlist is down. As a workaround edit the hosts file and add a new masterlist provided by etmaster.net.

In FreeBSD and Linux distributions, run the following command:
# echo "91.220.53.73 etmaster.idsoftware.com" >> /etc/hosts

Fire up ET as a new list of servers will be available.

Major thanks Paul at the Splash Damage forums for providing a solution ;)

HowTo: nForce2 sound on FreeBSD

I finally got around to replace the northbridge fan of my ABIT AN-7 powered desktop and with it boot its old FreeBSD 7.4-STABLE install. Though I have a Creative SoundBlaster Audigy 4 I wanted to make sure I could go by with just the motherboard's nForce2 integrated sound system, so bellow I'll explain how to enable the nForce2 sound on FreeBSD.

Let's check if FreeBSD recognized and assigned a sound driver to the device:
$ cat /dev/sndstat
FreeBSD Audio Driver (newpcm: 32bit 2007061600/i386)
Installed devices:

# dmesg | grep -i audio
pci0: at device 5.0 (no driver attached)
pci0: at device 6.0 (no driver attached)

# cd /usr/ports/sysutils/pciutils ; make install clean ; rehash

# lspci | grep -i audio
00:05.0 Multimedia audio controller: nVidia Corporation nForce Audio Processing Unit (rev a2)
00:06.0 Multimedia audio controller: nVidia Corporation nForce2 AC97 Audio Controler (MCP) (rev a1)

Ok. So no sound driver is attached to the device. To use the sound device load the proper driver which in this case is snd_ich according to FreeBSD 7 Relase Notes

Let's attach the driver to the device:

# kldload snd_ich

To be sure that the sound driver was correctly loaded run:

$ cat /dev/sndstat
FreeBSD Audio Driver (newpcm: 32bit 2007061600/i386)
Installed devices:
pcm0: at io 0xb400, 0xb800 irq 22 bufsz 16384 kld snd_ich [MPSAFE] (1p:1v/1r:1v channels duplex default)

To attach the appropriate driver at boot, we need to add it to loader.conf(5) like so:
# echo 'snd_ich_load="YES"' >> /boot/loader.conf

To setup sound output levels for various audio sources and frequency ranges you can use the FreeBSD mixer. To display the current mixer values do the following:

$ mixer
Mixer vol      is currently set to  75:75
Mixer pcm      is currently set to  75:75
Mixer speaker  is currently set to  75:75
Mixer line     is currently set to  75:75
Mixer mic      is currently set to   0:0
Mixer cd       is currently set to  75:75
Mixer rec      is currently set to   0:0
Mixer igain    is currently set to   0:0
Mixer ogain    is currently set to  50:50
Mixer line1    is currently set to  75:75
Mixer phin     is currently set to   0:0
Recording source: mic

To change mixer values you can type mixer followed by the name of the device and the desired level. If you wanted to change the CD output volume to 95 percent on left channel and 85 on the right channel:

$ mixer cd 95:85

And that's it. As a side note, though I mention FreeBSD 7.4-STABLE these instructions apply to recent versions of FreeBSD, namely FreeBSD 9.0-RELEASE.

For additional information consult sound(4) and snd_ich(4) man pages.

Thursday, January 26, 2012

HowTo: Mounting NTFS partition in write mode on FreeBSD

My brother's old laptop died and I got to keep its hard-drive. Being a Windows machine, it had a bunch of NTFS partitions. So this post explains how to identify a NTFS partition, mount it as read-only and finally learn how to mount it in write mode. I should mention that FreeBSD 7.4 was used but the same steps should apply to latter versions of the OS.

Physically attached the hard-drive (in my case I plugged an USB HDD) and have a look at /var/log/messages to identify the harddrive.
% su
# tail -n 20 /var/log/messages
Jan 26 21:40:03 flumen kernel: da0: Fixed Direct Access SCSI-4 device
Jan 26 21:40:03 flumen kernel: da0: 40.000MB/s transfers
Jan 26 21:40:03 flumen kernel: da0: 114473MB (234441648 512 byte sectors: 255H 63S/T 14593C)
Similar information can be collected from dmesg.
# dmesg
umass0: on uhub4
da0 at umass-sim0 bus 0 target 0 lun 0
da0: Fixed Direct Access SCSI-4 device
da0: 40.000MB/s transfers
da0: 114473MB (234441648 512 byte sectors: 255H 63S/T 14593C)
Let's find out which is the NTFS partition:
# fdisk /dev/da0
******* Working on device /dev/da0 *******
parameters extracted from in-core disklabel are:
cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=14593 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:

The data for partition 1 is:
sysid 18 (0x12),(Compaq diagnostics)
start 63, size 16611147 (8110 Meg), flag 0
beg: cyl 0/ head 1/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 7 (0x07),(OS/2 HPFS, NTFS, QNX-2 (16 bit) or Advanced UNIX)
start 16611210, size 117194175 (57223 Meg), flag 80 (active)
beg: cyl 1023/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
sysid 15 (0x0f),(Extended DOS (LBA))
start 133805385, size 100631160 (49136 Meg), flag 0
beg: cyl 1023/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 4 is:
Issuing the following command will mount a NTFS partition in read-only mode:
# mount -t ntfs /dev/da0s2 /mnt/
To be able to write into a NTFS partition it is required to install the sysutils/fuse-ntfs port:
# cd /usr/ports/sysutils/fusefs-ntfs/ && make install clean
If you use, as described in the man page, mount -t ntfs-3g an error will occurr:
# mount -t ntfs-3g /dev/da0s2 /mnt/
mount: /dev/da0s2 : Operation not supported by device
To mount the NTFS partition in write mode issue:
# ntfs-3g /dev/da0s2 /mnt/
Let's make sure that the partition is mounted:
#mount
/dev/ad4s1a on / (ufs, local)
devfs on /dev (devfs, local)
/dev/ad4s1e on /tmp (ufs, local, soft-updates)
/dev/ad4s1f on /usr (ufs, local, soft-updates)
/dev/ad4s1d on /var (ufs, local, soft-updates)
/dev/ad5s1d on /mnt/1 (ufs, local, soft-updates)
/dev/fuse0 on /mnt/2 (fusefs, local, synchronous)
man ntfs-3g contains some Linuxisms and as such read the man page with a grain of salt ;)

Thursday, March 25, 2010

HowTo: Upgrade FreeBSD 7.2 to 7.3

Disclaimer: this post is for those that instead of using FreeBSD's excellent documentation maintain the bad habit of googling for things already covered in the project's official documentation. This is more or less a copy-paste of the FreeBSD 7.3-RELEASE Announcement instructions for upgrading 7.2 to 7.3.

These are needed steps to upgrade, through the binary upgrade method, the kernel and userland utilities to 7.3-RELEASE:
  1. % su
  2. # freebsd-update upgrade -r 7.3-RELEASE
  3. # freebsd-update install
  4. # shutdown -r now
  5. % su
  6. # freebsd-update install
  7. # shutdown -r now
On step 1 we've started of by becoming the superuser. Step 2 initiates the freebsd-update utility pointing the upgrade to 7.3-RELEASE, after that we proceed with the installation of the kernel on step 3.

Upon rebooting the new kernel is enabled and we move into step 6. Here we end the upgrade process by updating the userland utilities.

That's it!

If you found this post useful that's actually a bad news: you aren't reading the project's official documentation! So please point to http://www.freebsd.org and educate yourself on FreeBSD ;)

Tuesday, January 12, 2010

Tip: Dealing with nvidia-driver-195.22 on FreeBSD 7.2-RELEASE

I haven't migrated to FreeBSD 8.0 as I came across visual artefacts while running 8.0, nvidia-driver-195.22 and Enemy Territory on a test install.

To update my installed ports I use for the most part csup to update the ports collection and sysutils/portmaster to actually update the ports with new versions.

Recently nvidia-driver-195.22 hit the Ports tree and upon running portmaster -a I found out that Nvidia's latest driver version requires FreeBSD-STABLE or FreeBSD-CURRENT. Guess who's running RELEASE?

Symptoms:
  • % su
  • # csup -L 2 -h cvsup2.uk.freebsd.org /usr/share/examples/cvsup/ports-supfile
  • # portmaster -L
===>>> nvidia-driver-185.18.36
===>>> New version available: nvidia-driver-195.22
===>>> This port is marked IGNORE
===>>> requires fairly recent FreeBSD-STABLE, or FreeBSD-CURRENT
  • # portmaster -a
===>>> Launching child to update nvidia-driver-185.18.36 to nvidia-driver-195.22

===>>> Port directory: /usr/ports/x11/nvidia-driver
===>>> This port is marked IGNORE
===>>> requires fairly recent FreeBSD-STABLE, or FreeBSD-CURRENT

===>>> If you are sure you can build it, remove the
IGNORE line in the Makefile and try again.

===>>> Update for nvidia-driver-185.18.36 failed
===>>> Aborting update

Solution:
  • # cd /var/db/pkg/nvidia-driver-185.18.36/
  • # touch +IGNOREME
  • # portmaster -a
===>>> Launching child to update nvidia-driver-185.18.36 to nvidia-driver-195.22

===>>> nvidia-driver-185.18.36 has an +IGNOREME file

===>>> Update anyway? [n]
  • answer "n"
Now portmaster -a ignores updates to the nvidia-driver port until the issue is fixed or I move to 8.0 ;)

Friday, September 18, 2009

HowTo: Mount EXT2FS partitions with inode 256 on FreeBSD

Mounting ext2/ext3 slices (or "partitions" in the Linux world) is easy on FreeBSD... if the filesystem was NOT created with inode 256 that is!

If you are one of those unlucky bastards this post presents the required steps on how to patch the FreeBSD 7.2 kernel module that mounts ext2/ext3 filesystems.

First let's begin by installing the sysutils/e2fsprogs application that provides tune2fs which will allow us to confirm that the ext2/ext3 filesystem was in fact created with inode 256. Assuming that the target slice is in the /dev/ad4 disk:
  • % su
  • # cd /usr/ports/sysutils/e2fsprogs
  • # make install clean
  • # rehash
  • # fdisk /dev/ad4
******* Working on device /dev/ad4 *******
parameters extracted from in-core disklabel are:
cylinders=395136 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=395136 heads=16 sectors/track=63 (1008 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 131 (0x83),(Linux native)
start 63, size 80262 (39 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 4/ head 254/ sector 63
The data for partition 2 is:
sysid 130 (0x82),(Linux swap or Solaris x86)
start 80325, size 1012095 (494 Meg), flag 0
beg: cyl 5/ head 0/ sector 1;
end: cyl 67/ head 254/ sector 63
The data for partition 3 is:
sysid 131 (0x83),(Linux native)
start 1092420, size 10008495 (4886 Meg), flag 0
beg: cyl 68/ head 0/ sector 1;
end: cyl 690/ head 254/ sector 63
The data for partition 4 is:
sysid 15 (0x0f),(Extended DOS (LBA))
start 11100915, size 350907795 (171341 Meg), flag 0
beg: cyl 691/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
  • # tune2fs -l /dev/ad4s1 | grep -i 'inode size'
fdisk is used to list the slices that exist on the disk. Sysid 131 means that a ext2/ext3 slice exists and this is target for tune2fs.

Next let's fetch the patch:
  • % wget http://pflog.net/~floyd/ext2fs.diff
In alternative, get the patch from here:
  • % wget http://pastebin.ca/raw/1280738
Now that we have the patch, let's proceed by applying it and build the patched module:
  • # cd /usr/src/sys/gnu/fs
  • # patch < /path/to/patch
  • # cd /usr/src/sys/modules/ext2fs
  • # make depend ; make obj ; make ; make ; make install ; make unload ; make load ; make clean
This way you'll build all dependencies for the module, build the module itself, install it, unload the current loaded module and finally load the new one.

Having the new module loaded you can now successfully mount your ext2/ext3 filesystem:
  • # mount -t ext2fs /dev/ad6s1 /mnt
That's it!

References:
kern/124621: [ext3] [patch] Cannot mount ext2fs partition
man mount
sysutils/e2fsprogs

Thursday, September 17, 2009

Tip: Introducing the PKGDIR environment variable on FreeBSD

Though I prefer using the ports tree to install applications on FreeBSD, the fact is that packages are way faster especially if your hardware is old or you just want to bring a test install online as fast as possible.

If you want to keep the downloaded packages, you need to set the PKGDIR environment variable pointing to the place where to store the downloaded .tbz files.

Here's how to set PKGDIR with the t/csh shell to /usr/ports/packages/All:
  • % su
  • # setenv PKGDIR /usr/ports/packages/All
  • # mkdir -p /usr/ports/packages/All
To download, store and install a package named foo:
  • # pkg_add -Kr foo
The -K switch informs pkg_add that you want to keep the downloaded package on the directory defined by PKGDIR.

Using packages is all fine and dandy, however not all applications in the ports tree are available as packages due to licensing issues.

I found out that after setting the PKGDIR, every single port that I tried to install failed with the same error: "Missing pkg-descr".

To fix the problem simply unset the PKGDIR environment variable like so:
  • # unsetenv PKGDIR
And voilá! You can now use the best of both worlds.

Tuesday, August 25, 2009

Tip: Fetch and password-protected web pages

In order to make fetch (the FreeBSD downloading tool) ask for username/password when it encounters a password-protected web page, you can set the environment variable HTTP_AUTH to 'basic:*'.

Users of t/csh shells can temporarily set the environment variable like so:
% setenv HTTP_AUTH='basic:*'
To set it permanetly we need to add it to .cshrc:
% vim ~/.cshrc
setenv HTTP_AUTH 'basic:*'
And that's it.