Archive for the ‘Operating Systems’ Category.

10 Reasons why Linux as a Desktop is rarely found in an Enterprise

Application and Development

  1. Commercial apps. Like it or not the best apps, from MS Office, Adobe Creative Suite, and thousands more, exist only for Windows and most cross-platform apps just mean Windows and Mac.
  2. Internal custom apps are almost all written for Windows only. And when they are web apps they often use SharePoint with IE only features.
  3. Lack of enterprise product support for any operating system but Windows.
  4. Rapid desktop application development on Windows with Visual Studio is orders of magnitude faster than on Linux with its best IDE, which is arguably Eclipse.

Infrastructure

  1. Most existing desktop operating systems are already Windows.
  2. Desktop Management solutions that Enterprise IT departments use to manage their workstations only manage Windows or if they manage multiple operating systems, they manage Windows the best.
  3. Existing infrastructure (such as phone systems, etc…) integrate with Windows but not with Linux.

Employees

  1. Existing Full-time employees (FTE) in IT are skilled in Windows and employee replacement or training costs are high.
  2. The cost of Linux FTE in IT is higher than Windows FTE in IT.

Advertising

  1. Most companies start small and grow to be an enterprise. When most companies are started, they are started by people who have never heard of or seen Linux.

Will this change in the future?

Maybe. Change is possible but it takes a lot of time and I don’t mean just years, I mean decades. And during these decades every OS vendor is going to fight to gain a monopoly in the enterprise desktop world.

If it does happen, the changes are for the following reasons.

  1. To better support  mobile devices such as iOS and Android (which is sort of Linux)
    1. As more applications become browser apps or cloud apps that work in any browser.
  2. Cross platform development tools, such as Mono and Java and AIR are really improving.

For those who are pro-Linux because it is open source and you believe knowledge belongs to the world, the enterprise doesn’t care. This argument is completely irrelevant from an enterprise perspective. I care, though, if that makes you feel any better (though I am a person not an Enterprise).

What if a Startup uses an Open Source Operating System

Well, look at the 10 items above and you will see you can eliminate 2, 5, 7, 8, and 10. Half the reasons are eliminated by starting with an Open Source OS.  However, on the other hand, half the reasons still exist.

Building a FreeBSD kernel for debugging

You may want to actually debug the kernel or a kernel module, however, debugging is not enabled by default.

Prereqs

Before getting started it is assumed you have a FreeBSD Install and you have downloaded/installed FreeBSD Source.

The steps are identical to the steps contained in the How to build and install a custom kernel on FreeBSD? article, with the exception of the kernel configuration file.

Step 1 – Create a new kernel config

  1. Determine your architecture by running this command:
    # uname -a
    FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
    
  2. Look at the last text item in the output string. I have amd64 so that is my architecture: amd64
  3. Change to the directory of the kernel configuration files for your architecture. Remember if you are on a different architecture to replace amd64 in the following command lien with your architecture.
    # cd /usr/src/sys/amd64/conf
    
  4. Copy GENERIC to a new file.
    # cp GENERIC KRNLDBG
    
  5. Edit KRNLDBG with your favorite text editor.
  6. First, change the ident value near the top from GENERIC to KRNLDBG.
    ident           KRNLDBG
    
  7. Add debugging settings to your KRNLDBG configuraiton file.
    options           KDB
    options           KDB_TRACE
    options           DDB
    options           GDB
    
  8. Save and close your new KRNLDBG configuration file.

For the remaining steps, follow the How to build and install a custom kernel on FreeBSD? article, only replace any references to KRNL1 kernel config file with the KRNLDBG config file created in the previous step.

Once you are done building and installing the kernel, you should have debugging enabled.

I happen to be working with a kernel module that is crashing and when it crashes, it automatically places me in a debugging session with the following prompt.

db>

Installing VMWare Tools on FreeBSD 9

Virtualizing a FreeBSD server is common place. Knowing how to install VMWare Tools on a FreeBSD server without X11 is going to be extremely important. This article will provide the steps.

Lets get started.

Step 1 – Install FreeBSD as VMWare Guest.

Instructions for installing FreeBSD 9 are found here: How do I install FreeBSD 9?

It shouldn’t be much of an effort to follow these steps inside a VMWare guest.

Note: You may consider taking a snapshot here to save your current state.

Step 2 – Update FreeBSD and Install ports

Instructions for updating FreeBSD and installing ports are found here:
Update FreeBSD and Install ports

Note: You may consider taking a snapshot here to save your current state.

Step 3 – Install Prerequisites

Step 3.1 – Install Perl

Installing Perl is easy. Use either of the following commands.

From ports

# cd /usr/ports/lang/perl5.12
# make install

From packages

# pgk_add -r perl

Step 3.2 – Install compat6x-amd64

The compat6x-amd64 port is also easily installed.

From ports

# cd /usr/ports/misc/compat6x/
# make install

From packages

# pkg_add -r compat6x-amd64

Step 4 – Take a VMWare Snapshot

Important! Take a snapshot here! Do not skip this step.

Step 5 – Mount the VMWare Tools ISO

I am using VMWare workstation. Some steps may be slightly different if you are using ESXi or other VMWare solution.

  1. In VMWare Workstation, choose VM | Install VMWare Tools.
  2. In FreeBSD as root, create a directory to mount the CD-Rom to.
    # mkdir /cdrom
    
  3. Mount the cd-rom.
    # mount -t cd9660 /dev/cd0 /cdrom
    

Note: You may consider taking a snapshot here to save your current state.

Step 6 – Extract the vmware-freebsd-tools.tar.gz

Now that the drive is mounted, it should be easy to get to the vwmare-tools file.

  1. Copy the vmware-freebsd-tools.tar.gz file to a local location.
    # cp /cdrom/vmware-freebsd-tools.tar.gz /root
    
  2. Extract the vmware-freebsd-tools.tar.gz file.
    # cd /root
    # tar -xzf vmware-freebsd-tools.tar.gz
    

VMWare tools should now be extracted.

Step 7 – Recompile VMWare Tools Modules

Before you install VMWare tools on FreeBSD 9, you need the modules to work with FreeBSD 9. VMWare is slow to update the vmware tools for the FreeBSD guest. So you are just going to have to update them yourself.

Note: We are now at the point where we are going to do more and install more than you want to for your nice new clean server, but that is ok, because we have a snapshot and once we get the files compiled you can revert to the clean snapshot. Alternately if you have another FreeBSD system, you can do these steps on that system.

If you install without recompiling as of May 10, 2012, you will get this result.

Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                                   done
   Guest memory manager:                                              failed
   Blocking file system:                                              failed
   Guest operating system daemon:                                      done
Unable to start services for VMware Tools

Execution aborted.

Compiling the modules first should prevent the above failures.

Step 7.1 – Get FreeBSD Source

Download the FreeBSD Source as described here.

How to download FreeBSD source using svn?

Step 7.2 – Configure the /etc/make.conf

Right now there is a move toward compiling with clang over gcc. Because of changes due to this, you need to add the following line to your /etc/make.conf to compile with gcc. I have not tried to compile with clang yet.

  1. As root open the /etc/make.conf file with you favorite editor and add the following line:
    MK_CLANG_IS_CC=no
    
  2. Save and close the /etc/make.conf file.

Your /etc/make.conf is now configured.

Note 1: You may want to compile a custom kernel while you are at this. If so, check out this article: How to build and install a custom kernel on FreeBSD? If you do this, remember that you have to copy the new kernel to your clean system too.

Step 7.3 – Compile the vmmemctl module

Recompile vmmemctl using these steps.

  1. Go to the lib/modules/source directory under where you extracted vmware-freebsd-tools.tar.gz.
    # cd /root/vmware-tools-distrib/lib/modules/source/
    
  2. Extract vmmemctl.tar
    # tar -xf vmmemctl.tar
    
  3. Change to the vmmemctl-only directory.
    # cd vmmemctl-only
    
  4. Run make.
    # make
    
  5. Run make install.
    # make install
    

You have now built and installed the vmmemctl module.

Step 7.4 – Compile the vmblock module

  1. Go to the lib/modules/source directory under where you extracted vmware-freebsd-tools.tar.gz.
    # cd /root/vmware-tools-distrib/lib/modules/source/
    
  2. Extract vmblock.tar
    # tar -xf vmblock.tar
    
  3. Change to the vmblock-only directory.
    # cd vmblock-only
    
  4. Run make.
    # make
    
  5. Run make install.
    # make install
    

You have now built and installed the vmblock module.

Step 8 – Install VMWare Tools

You are now ready to install the VMWare Tools.

Note: If you are trying to keep you server clean and pristine, then copy the /root/vmware-tools-distrib directory off the server somewhere. THen revert to the snapshot you took just before Step 4. Copy the directory back to your clean snapshot and continue.

  1. Move into the directory created by the extraction.
    # cd /root/vmware-tools-distrib/
    
  2. Run vmware-install.pl
    # ./vmware-install.pl
    
  3. Select all the defaults.

Your vmware tools installation should go smoothly.

How to build and install a custom kernel on FreeBSD?

Lets get started. The main reason I am writing this when so many articles on this already exist is because many articles do not have all the steps in one place. For example, the article in the FreeBSD Handbook doesn’t have steps for downloading the source using subversion or for making sure you have enough space on the root partition. See this article here: Building and Installing a Custom Kernell

Step 1 – Install FreeBSD as VMWare Guest.

Instructions for installing FreeBSD 9 are found here:

How do I install FreeBSD 9?

You may also want to install FreeBSD ports:

How to install FreeBSD ports

Step 2 – Download FreeBSD Source

Instructions for downloading FreeBSD Source can be found here:

How to download FreeBSD source using svn?

Step 3 – Build the GENERIC Kernel

Before you create a custom kernel it is always good to know that the default GENERIC kernel is compiling and working. Also, if you are practiced at this and are certain this will work, feel free to skip this step.

Note: I call it the GENERIC kernel because the GENERIC is the file name of the default kernel configuration.

  1. Go to the /usr/src directory:
    # cd /usr/src
    
  2. As root, run this command:
    # make buildkernel
    
  3.  Wait for the compile to complete

Step 4 – Create a new kernel config

  1. Determine your architecture by running this command:
    # uname -a
    FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
    
  2. Look at the last text item in the output string. I have amd64 so that is my architecture: amd64
  3. Change to the directory of the kernel configuration files for your architecture. Remember if you are on a different architecture to replace amd64 in the following command lien with your architecture.
    # cd /usr/src/sys/amd64/conf
    
  4. Copy GENERIC to a new file.
    # cp GENERIC KRNL1
    
  5. Edit KRNL1 with your favorite text editor.
  6. First, change the ident value near the top from GENERIC to KRNL1.
    ident           KRNL1
    
  7. Make any other changes you would like to make.It is hard to know why you are building a custom kernel and hopefully you know what you need in your custom kernel. This is where you modify the kernel to provide what you need.
  8. Save and close your new KRNL1 configuration file.

Step 5 – Build the custom kernel

Now that you have a new configuration file, build a kernel using that configuration file.

  1. Compile the kernel.
    # cd /usr/src
    # make buildkernel KERNCONF=KRNL1
    
  2. Wait for you kernel to build.

Step 6 – Verify you have enough space for the new kernel

  1. Make sure you have enough free space to install your kernel.Note: Your output may be quite different than mine.
    # df -ah
    Filesystem    Size    Used   Avail Capacity  Mounted on
    /dev/da0p2     74G    4.3G     64G     6%    /
    devfs         1.0k    1.0k      0B   100%    /dev
    
  2. If your root partion, /, has a capacity greater than 55%, you probably OK. Otherwise, your backup or kernel installation may fail.

Step 7 – Install the custom kernel

  1. Install the Kernel.
    # make installkernel KERNCONF=KRNL1
    
  2. Reboot the system.
    # reboot
    

You now have a custom kernel installed.

Install Telnet.exe from the command line

I have a previous post about installing telnet.exe in windows 7, however, I explain how to do it using the UI. You may need to install telnet.exe from the command line.

To install telnet.exe on Windows 7 from the command line, run this command:

C:\Windows\system32>dism.exe /online /Enable-Feature:TelnetClient

Now telnet to a machine:

c:\> telnet 10.1.1.1

Yes, it is that easy. Of course, you may think about using ssh these days as telnet just isn’t that secure. However, telnet is used for other things, such as port testing.

You can telnet using a different port or test that a port is open just by adding the port number.

c:\> telnet 10.1.1.1 3389

Using FreeBSD inside a controlled network – A required HTTP Proxy and No FTP

Inside a controlled network, it is a little harder to use FreeBSD. The simple things become hard, such as running “portsnap fetch extract” or running “make install” on a port.

In a certain network, I am experiencing certain security settings that I must make FreeBSD work around:

  1. An HTTP proxy is required to access external sites
  2. No FTP access.

Working with a required HTTP proxy on FreeBSD

You cannot bypass the proxy. Most ports are blocked with HTTP/HTTPS forced through the proxy. Even worse, DNS only responds for internal addresses  and the proxy handles the external sites, so your local box never actually resolves names to IP addresses and the browser only works because the proxy makes it work.

Setting a global proxy on FreeBSD

You can configure FreeBSD to use a proxy. You can set a global proxy, sort of. It looks like you can set a global proxy per shell. However, not all apps respect that proxy.

csh/tcsh

To add a global proxy to any csh or tcsh shell, add the following line to this file: /etc/csh.cshrc

setenv HTTP_PROXY http://ProxyNameOrIp:8080

sh

To add a global proxy to any sh shell, add the following lines to this file: /etc/profile

HTTP_PROXY=http://ProxyNameOrIp:8080
export HTTP_PROXY

Now that you have made these settings, your proxy should be working and any tool that uses HTTP/HTTPS, such as fetch, portsnap, make fetch, etc., should now properly use the proxy to access the internet.

fetch and tools that use it (ports, portsnap, etc…)

Any HTTP source should now work. Both ports and portsnap and other such FreeBSD tools use fetch so as soon as the environment variable is set, fetch and any tool that uses it will work.

Tools that don’t use fetch (Subversion, etc…)

Other tools, such as subversion, may not support the HTTP_PROXY environment variable and must be manually configured. For Subversion, I couldn’t find a global setting, instead it was a user setting. The file in your home directory. It usually exists by default but contains only comments. The following is the minimal lines you need.

[global]
http-proxy-host = ProxyNameOrIP
http-proxy-port = 8080

Working with no FTP access on FreeBSD

This problem is easy to get around. Always use HTTP or HTTPS. FreeBSD has usually made it that simple as all the common tools that use FTP seem to have HTTP options as well.

Ports

Most ports have an HTTP site as a backup download location. The best case, you run make install and it just finds an HTTP site and downloads the port for you. In the worst case, you may have to manually edit the Makefile and add an http source.

Portsnap uses http by default.

Decoupling settings from /etc/rc.conf in FreeBSD

The rc.conf file can have a lot of settings that quite important. In fact, I would say it has so many settings that it often gets very bloated. Have you ever made a huge mistake and wiped out the rc.conf when it is huge and full of many settings. Or have you ever had a system crash that wiped out the rc.conf? I have! A large rc.conf can be difficult to recover without a backup. On a production server, I will have such a backup but in my lab and on my PC-BSD desktop, I don’t.

My personal experiences of erasing the rc.conf are silly but they happened. Feel free to laugh but I have been using FreeBSD since 2001 (11 years as of the writing of this post) and each of these happened in lab environments or on my personal laptop where I was less careful and none of them ever happened on a production server.

  1. I accidentally ran a command that wiped it because I used > which overwrites the file, instead of >>, which appends to the file.
    $ sudo echo ‘someapp_enable=”yes”‘ > /etc/rc.conf
  2. PC-BSD wireless settings are written to the /etc/rc.conf file and once while managing my wireless settings, the system crashed, rebooted, and my /etc/rc.conf was empty.
  3. I once was going to delete the hosts file and add a new one and I am so used to typing /etc/rc.conf that I typed that instead of /etc/hosts. Oops!
    $ rm -f /etc/rc.conf
  4. While writing a script to update a setting in /etc/rc.conf, my script wiped it. Maybe the reason was similar to #1, maybe it was different, I don’t remember.

How to store settings in separate files on FreeBSD

If you do a quick read of the man 5 rc.conf, it will tell you that you can put setting in rc.conf, rc.conf.local, or in any filename residing in a folder called /etc/rc.conf.d and all these files can store settings.

Moving all your settings to rc.conf.local just moves the problem I described above, it doesn’t actually fix it, so I am not going to use that solution. However, using a separate file per setting in the /etc/rc.conf.d directory is quite a great idea.

Step 1 – Create the /etc/rc.conf.d directory

  1. Create a /etc/rc.conf.d directory:
    # sudo mkdir /etc/rc.conf.d

Step 2 – Create a file to hold a setting

Example 1 – Hostname

  1. Create a file in /etc/rc.conf.d and name it hostname.
  2. Add the hostname=”SystemName.domain.tld” setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘hostname=”SystemName.domain.tld”‘ > /etc/rc.conf.d/hostname

Example 2 – SSH

  1. Create a file in /etc/rc.conf.d and name it ssh.
  2. Add the sshd_enable=”YES” setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘sshd_enable=”YES””‘ > /etc/rc.conf.d/ssh

Example 3 – Default Gateway

Yes, on FreeBSD the default route setting is called defaultrouter, not gateway or defaultroute as one would expect.

  1. Create a file in /etc/rc.conf.d and name it defaultrouter, or if you want to name it gateway or defaultroute.
  2. Add the defaultrouter=”192.168.0.1″ setting to the file.

Note: You can do both steps at the same time with one command:

# sudo echo ‘defaultrouter=”192.168.0.1″‘ > /etc/rc.conf.d/defaultroute

Conclusion

If you use the /etc/rc.conf.d file, then if you ever accidentally overwrite a file, it is not that hard to deal with because every setting is decoupled in its own file. You only lose one setting.

From now on, in my posts, I will tell likely suggest adding settings using a separate file in /etc/rc.conf.d.

How to install MySQL on FreeBSD

Note: Tested on FreeBSD 9

Step 1 – Install FreeBSD

  1. First install FreeBSD. Instructions for installing FreeBSD is contained in this article.
    How I install FreeBSD 9?
    (Legacy) How I install FreeBSD?
  2. Second update FreeBSD and install the ports tree. Instructions for this are in this article.
    What are the first commands I run after installing FreeBSD?

Step 2 – Installing MySQL

Install MySQL from Ports

  1. Change to the directory of the mysql55-server port.
    # cd /usr/ports/databases/mysql55-server
  2. Now install mysql55-server with ‘make install’.
    # make install

    MySQL 5.5 Server (and MySQL 5.5 client) will download, compile, and install automagically for you.

    Note: You may be wondering about the WITH_CHARSET option that used to exist. This is not necessary during compile and install and we will set the character set in a later step. Don’t start the MySQL service until we make these changes.

Installing MySQL from Packages

  1. Install easily as a binary package with this simple command.
    pkg_add -r mysql55-server

Step 3 – Configure MySQL

Configuration of MySQL is done in the my.cnf file.

Example 1 – Configuring mysql to use UTF8

For this example, we will change our server to use UTF8.

  1. Change to the /usr/local/etc/ directory. This is the default location for the my.cnf file.
    cd /usr/local/etc/
  2. Add the following to the my.cnf file.
    # # # > /usr/local/etc/my.cnf echo '[mysqld]' >> /usr/local/etc/my.cnf echo character-set-server=utf8 >> /usr/local/etc/my.cnf echo collation-server=utf8_general_ci

Note: FreeBSD has multiple example my.cnf files here: /usr/local/share/

  • my-huge.cnf
  • my-innodb-heavy-4G.cnf
  • my-large.cnf
  • my-medium.cnf
  • my-small.cnf

Step 4 – Configure MySQL to start on boot

  1. Add the following lines to the /etc/rc.conf file.
    #
    #
    echo # MySQL 5.5 Server >> /etc/rc.conf
    echo 'mysql_enable="YES"' >> /etc/rc.conf
  2. Now start your server.
    # /usr/local/etc/rc.d/mysql-server start

Step 5 – Secure your MySQL installation

MySQL documentation covers this and I’ll not repeat it here. Instead, go here:
2.2 Securing the Initial MySQL Accounts

Integration with Apache and PHP

If you want to integrate Apache and PHP see these articles.

How to install FreeBSD 9?

FreeBSD 9 comes with a new installer and installing it is quite fast.

Part 1 – Download the media

Step 1 – Download the DVD ISO

  1. Go to http://www.freebsd.org/where.html and click to the ISO link for FreeBSD 9 for you architecture. (x86, amd64, etc…)
  2. Click to download the FreeBSD-9.0-RELEASE-amd64-dvd1.iso.

Step 2 – Burn the ISO to a DVD

I am not going to give you steps for burning an ISO, as you could be on Windows, Linux, OS X, and you could be using any of the DVD burning tools out there.

I’ll give you this hint though…Do not burn the ISO file onto the disk as a file.

Note: Skip this step if you are installing to  a virtual machine.

Part 2 – Install FreeBSD

Step 1 – Boot off the DVD

  1. Put the DVD in your drive. (Or if using a virtual machine, point the virtual machine’s DVD drive to the ISO file.)
  2. Boot your system.
    Note: If you system doesn’t boot off the DVD check the BIOS settings or try pressing F12 to select the boot device

  3. The next screen will automatically boot but delays 9 seconds.
    Press enter to continue without waiting.


    Your now booting to the installer.

Step 2 – Install FreeBSD

  1. Click Install on the first screen.

  2. If you need a special keyboard layout, click yes, otherwise, click no. I clicked no.
  3. Enter the host name for this new installation.
  4. Select the optional system components and press enter.

  5. Partitioning can be done for you with Guided or you can do it yourself with Manual.Note: With todays hard drives, there is little to no benefit from having  multiple partitions as there was in the past. Just use Guided and the root partition will fill the drive.Note: Doesn’t look like we have ZFS options yet.

  6. Look over the guided partition settings.
  7. Click Commit to perform the installation.

    It runs the checksum verification to make sure media is valid.


    It then commits the install.

    It is actually not that long of a wait before you are pretty much done.

    The installation has committed. You will now be asked post-installation configuration questions.

Step 3 – Configure Post-installation settings

  1. Enter a password for the root account when prompted. Enter it again to verify it.
  2. Select your network card.
  3. Unless you know for sure you are going to use IPv6 only, say Yes to enabling IPv4.
  4. Unless you have been given a specific IP address to use, say Yes to enabling DHCP.
  5. Lately I like to enable IPv6 because all my operating systems now support it. But you probably don’t need it unless you know you need it.
  6. If you enabled IPv6, you probably want this option, unless you have a specific IPv6 address you need to use.

    Your dynamic network settings are determined.
  7. Your DNS setting may be detected for you, but if not, you can enter your DNS settings manually. I only entered a single DNS entry for IPv4.
  8. Unless you have a server that needs its clocked synchronized to UTC, select No when prompted.
  9. Select your time Region.
  10. Select your Country.
    Note: United States is number 49.
  11. Select your Time Zone.
  12. You may get a prompt to very whether the Time Zone you selected is correct. Select Yes if it is correct.
  13. Choose what to install.
    Note: If you are on a laptop you consider selecting powerd.
  14. If you want to contribute to FreeBSD and help them resolve bugs (especially yours) select yes. Otherwise, select No.
  15. Select Yes when prompted to Add user accounts.
  16. Enter a user name and follow the prompts.


    Note: Don’t forget to invite the user to the wheel group if they are going su to root.
  17. Enter Yes when all the settings are correct.
  18. Select Yes if you want to add more users and repeat these steps. Once you are done adding users, select No.
  19. Press Enter to Exit.
  20. I don’t have any special settings to make, so I select No here.
  21. Go ahead an press Enter to reboot.

    Important! Do not boot of the DVD again!

    Your system will now boot and create an SSH key on its own and give you a login prompt.


    FreeBSD is now installed.

Part 3 – Configure Your FreeBSD Install as Desired

What do you want to do next?

Why a developer’s next computer should be an Apple

It is not because OS X is better

Let me start by saying that I do not fall into the “my os is better than yours” mantra. I like to talk about the right tool for the job.

  • For a home user, Windows 7 and OS X still beat Linux (yes, even Ubuntu).
  • For a geeky home user, Ubuntu or any other OS might be more fun.
  • If you want to give away your old computer but not give away your Operating System license, put Ubuntu or PC-BSD on it.
  • Similarly if you get a free computer without an OS and you don’t want to buy one, put Ubuntu or PC-BSD on it.
  • For most businesses, Windows 7 is the better solution for a lot of reasons, many of which are IT related and not even user related.
  • For an artist, OS X is the right choice. Sure Windows has caught up in graphic tools, but not in peer knowledge.
  • For a Web Server, I would never run windows or MAC, I would recommend BSD or Linux.
  • For a NAS server, I would use FreeNAS.
  • For an enterprise to sell a secure appliance I would recommend a BSD derivative.

Those are just a generalizations based on the idea of using the right tool for the job. In every case others have different opinions and there are always exceptions. The appropriate thought is that you should use the right tool for the job.
So if you are a developer, what is the right tool for the job? Here is my new generalization.

  • For a Developer, I now recommend Apple hardware.

Notice I said Apple Hardware, but I didn’t say that I recommend OS X. Run whatever OS you need.

It is not because Apple Hardware is better

Also, this has nothing to do with saying that Apple hardware is better. Dell, HP, Lenovo, Sony, and others all make some great hardware for running whatever OS you can run.

Many argue that Alienware makes the best hardware, not any of the above vendors.  It is not about the best hardware.  So if it was a hardware issue, I would be recommending Alienware. But it is not.

Let me repeat.

  • For a Developer, I now recommend Macintosh hardware.

Notice, I qualified this by saying For a developer. I am not telling everybody to get Apple hardware.

Answer #1: It is simply a licensing issue

Legally you cannot run OS X on any hardware other than Apple hardware (an no Hacintosh is not legal) . Since iOS development realistically can only happen on OS X, you cannot legally run iOS on hardware designed for windows either.

Answer #2 – The cross-platform world

You need every Operating System today.

Lets talk about where development has taken us.  We have gone from not really cross-platform (Windows only and sometimes support Macintosh too), to having to be able to code on Windows, Windows Phone 7, OS X, iOS, Android, and possibly Linux and Unix as well.

Lets list these in a table and you will see why buying an Apple Laptop frees you to develop on all those platforms.

Operating System Apple Hardware Windows Hardware
Windows Run OS and Develop for it Run OS and Develop for it
BSD/Linux Run OS and Develop for it Run OS and Develop for it
Android Emulate OS and Develop for it Emulate OS and Develop for it
OS X Run OS and Develop for it Not supported*
iOS Emulate OS and Develop for it Not supported*

* While it can be done it is illegal and breaks license agreements.

Only Apple hardware allows you to install on all the popular Operating Systems that exist today.

So Apple has put themselves in an interesting position where cross-platform development on all popular operating systems can only occur on Apple hardware. It is this position that has me making this statement.

  • For a Developer, I now recommend Macintosh hardware.

As for the operating system that I recommend, you probably have guessed from this post my recommendation: If you are a developer, run them all.

LANDesk Support Tools – Android Edition (Demo)

This is my first real project written for Android. Yes, I wrote it in C# using Mono for Android.

How to write a FreeBSD Kernel Module

You may be think that writing your first kernel module is going to be a long, painful, grueling task, but really it is only slightly harder than writing your first program, Hello World!, in C or C++.

Lets break this into nice easy steps.

Prerequisites

It is assumed you have installed FreeBSD already. If not, follow the instructions below with one change: Install the FreeBSD source during the “Choose Distribution” section.

How do I install FreeBSD?

Step 1 – Create a basic module file

A FreeBSD kernel module is written in C. This is going to be only a slightly harder than writing hello world in C. We are going to create a single text file with a .c extension and put some C code in it.

  1. Create a folder to hold you project. I used this directory:
    /usr/home/jared/code/kernel/hwm
  2. Create the file to hold your code. I named my file this:
    hello_world_kmod.c
  3. Edit the file with you favorite editor, vi, vim, emac, ee. I used easy editor (ee):
    ee hello_world_kmod.c
  4. Add the following code to the file.I have broken the code of the simplest kernel module into four parts or steps:
    1. Add four required #include statements.
    2. Create the kernel load/unload event handler.
    3. Create a struct to name the module and point to the event handler function.
    4. Call the DECLARE_MODULE macro.
    /*
     * Step 1 - Add the four needed libraries to include
     */
    #include <sys/param.h>
    #include <sys/module.h>
    #include <sys/kernel.h>
    #include <sys/systm.h>
    
    /*
     * Step 2 - Handle the load/unload event
     */
    static int EventHandler(struct module *inModule, int inEvent, void *inArg)
    {
            // Set return code to 0
            int returnCode = 0;
    
            switch (inEvent)
            {
              case MOD_LOAD:
                    uprintf("Hello, World! \n");
                    break;
              case MOD_UNLOAD:
                    uprintf("Bye, World! \n");
                    break;
              default:
                    returnCode = EOPNOTSUPP;
                    break;
            }
    
            return(returnCode);
    }
    
    /*
     * Step 3 - Name the module and the event hander function
     *          This is done using a struct of type moduledata_T
     */
    static moduledata_t  moduleData = {
            "hello_world_kmod",     // Module Name
            EventHandler,           // Event handler function name
            NULL                    // Extra data
    };
    
    /*
     * Step 4 - Declare the module
     *          This is done with the DECLARE_MODULE macro
     */
    DECLARE_MODULE(hello_world_kmod, moduleData, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
    
  5. Save and close the file.

Step 2 – Create a Makefile

Creating a Makefile to build a kernel module is quite easy because almost all the work is done for you. FreeBSD has a file that you include, /usr/src/share/mk/bsd.kmod.mk, that does most of the work for you and all you have to do is include it.

  1. In the same directory where you put your .c file, create a new text file called Makefile.
  2. There are three basic parts to the kernel module Makefile:
    1. Module name
    2. Source files
    3. Include of bsd.kmod.mk
    # Module Name
    KMOD = hello_world_kmod
    
    # Source files
    
    SRCS = hello_world_kmod.c
    
    # Include <bsd.kmod.mk>
    .include <bsd.kmod.mk>
    
  3. Save and close the file.

Step 3 – Run make to build the module

  1. In the command prompt, in the directory where you have created your code and make file, run make.
    > cd /usr/home/jared/code/kernel/hwm
    > make
    Warning: Object directory not changed from original /usr/home/jared/code/kernel/hwm
    @ -> /usr/src/sys
    machine -> /usr/src/sys/amd64/include
    x86 -> /usr/src/sys/x86/include
    cc -O2 -pipe -fno-strict-aliasing -Werror -D_KERNEL -DKLD_MODULE -nostdinc   -I. -I@ -I@/contrib/altq -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common  -fno-omit-frame-pointer  -mno-sse -mcmodel=kernel -mno-red-zone -mno-mmx -msoft-float  -fno-asynchronous-unwind-tables -ffreestanding -fstack-protector -std=iso9899:1999 -fstack-protector -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual  -Wundef -Wno-pointer-sign -fformat-extensions  -Wmissing-include-dirs -fdiagnostics-show-option -c hello_world_kmod.c
    ld  -d -warn-common -r -d -o hello_world_kmod.ko hello_world_kmod.o
    :> export_syms
    awk -f /sys/conf/kmod_syms.awk hello_world_kmod.ko  export_syms | xargs -J% objcopy % hello_world_kmod.ko
    objcopy --strip-debug hello_world_kmod.ko
    >
    

Step 4 – Test loading an unloading the module

Loading and unloading kernel modules must be done as root. If you have sudo installed, use it, otherwise install it (Configuring sudo on FreeBSD) or su to root.

  1. Use kldload to load the module and kldunload to unload the module.
    > sudo kldload ./hello_world_kmod.ko
    Hello, World!
    > sudo kldunload ./hello_world_kmod.ko
    Bye, World!
    >
    

You have now performed the Hello World version of a FreeBSD kernel module.

Resources

Android and Xml Serialization with Simple

Xml serialization is almost becoming a standard requirement for a language these days and so as I have been taking an Android class and I couldn’t find an Xml Serialization library as part of Android by default, I set out in search of one.

I came across a java XML Serialization project called Simple.

So here is a quick entry-level example of how to use Simple in an Android development project.

Note: This walk-thru assumes you are using Eclipse.

Step 1 – Create a new Android Project

  1. Go to File | New Project and select Android.
  2. Provide a Project Name.
  3. Select the minimum build target.
  4. Provide a Package name.
  5. Click Finish.

Step 2 – Download Simple

  1. Go to the Simple download page: http://simple.sourceforge.net/download.php
  2. Extract the zip file.

Step 3 – Add the Simple library to your project

  1. Create a folder called libs in your project.
  2. Copy the jar file called simple-xml-2.6.2.jar to the libs directory you just created.Note: Be aware your version may be newer than 2.6.2.
  3. In Eclipse, right-click on simple-xml-2.6.2.jar (if it doesn’t show up refresh) and choose Build Path | Add to Build Path.

Step 4 – Create an Serializeable object

  1. Right-click on your package and choose New | Class.
  2. Provide a class name and click ok.
  3. The following is an example Person class:Person.java
    package org.jaredbarneck.cs6890;
    
    import org.simpleframework.xml.Element;
    import org.simpleframework.xml.Root;
    
    @Root
    public class Person
    {
    
    	public Person()
    	{
    	}
    
    	public Person(String inFirstName, String inLastName)
    	{
    		SetFirstname(inFirstName);
    		SetLastname(inLastName);
    	}
    
    	@Element
    	private String FirstName;
    
    	public String GetFirstName()
    	{
    		return FirstName;
    	}
    
    	public void SetFirstname(String inFirstName)
    	{
    		FirstName = inFirstName;
    	}
    
    	@Element
    	private String LastName;
    
    	public String GetLastName()
    	{
    		return LastName;
    	}
    
    	public void SetLastname(String inLastName)
    	{
    		LastName = inLastName;
    	}
    
    	@Override
    	public boolean equals(Object inObject)
    	{
    		if (inObject instanceof Person)
    		{
    			Person inPerson = (Person)inObject;
    			return this.FirstName.equalsIgnoreCase(inPerson.FirstName)
    				&& this.LastName.equalsIgnoreCase(inPerson.LastName);
    		}
    		return false;
    	}
    }
    

Step 5 – Serialize and Deserialize in your main Activity

  1. Add the following code to your main Activity:Note: Code should be clear and is commented.PersonActivity.java
    package org.jaredbarneck.cs6890;
    
    import java.io.File;
    
    import org.simpleframework.xml.Serializer;
    import org.simpleframework.xml.core.Persister;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class PersonActivity extends Activity
    {
    	public void onCreate(Bundle savedInstanceState)
    	{
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    
    		// Create a Person object
    		Person person1 = new Person("John", "Johnson");
    
    		// Create a file to save to and make sure to use the path provided from
    		// getFilesDir().getPath().
    		File xmlFile = new File(getFilesDir().getPath() + "/Person.xml");
    
    		// Serialize the Person
    
    		try
    		{
    			Serializer serializer = new Persister();
    			serializer.write(person1, xmlFile);
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    
    		// Create a second person object
    		Person person2 = null;
    
    		// Deserialize the Person
    		if (xmlFile.exists())
    		{
    			try
    			{
    				Serializer serializer = new Persister();
    				person2 = serializer.read(Person.class, xmlFile);
    			}
    			catch (Exception e)
    			{
    				e.printStackTrace();
    			}
    		}
    
    		boolean b = person1.equals(person2);
    	}
    }
    

Go ahead and try this in your Android emulator and step through it with a debugger.

You have now successfully implemented Xml Serialization in Java on Android using Simple.

How to make a Makefile?

Most software compiled on BLU (BSD/Linux/Unix) operating systems is done using make.

The simplest Makefile

The simplest Makefile compiles one single executable. Think of your simplest “Hello, World!” project.

HelloWorld.cpp

#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!";
  return(0);
}

Of course, for one file you don’t need a Makefile. You could simply run this command that will compile hw.cpp

g++ -o HelloWorld HelloWorld.cpp

So even though a Makefile seems useless for a single file, here is how you would do it.

all:
	g++ -o HelloWorld HelloWorld.cpp

Notice that you have a label and the same compile command one line below the label.

Important! The syntax requires the second line to start with a tab.

Adding objects to your Makefile

Lets assume instead of one file, you have the three file HelloWord.

  • Main.cpp
  • HelloWorld.h
  • HelloWord.cpp

Main.cpp

#include <iostream>
#include "HelloWorld.h"

using namespace std;

int main()
{
  HelloWorld hw = HelloWorld();
  cout << hw.Text << endl;
}

HelloWorld.h

#include <iostream>

using namespace std;

class HelloWorld
{
public:
  HelloWorld();
  ~HelloWorld();

  string Text;
};

HelloWorld.cpp

#include "HelloWorld.h"

HelloWorld::HelloWorld()
{
  Text = string("Hello, World!");
}

HelloWorld::~HelloWorld()
{
}

This simple project can also easily be compiled without a Makefile using this command line.

g++ -o HelloWorld Main.cpp HelloWorld.cpp

However, even with only three files you can start to see how it is much easier to type make than the lengthening command above.

Makefile

all:
	g++ -o HelloWorld Main.cpp HelloWorld.cpp

This is not perfect however, as this compiles both files every time make is run. If changes are made only to Main.cpp there is no reason to recompile HelloWorld.cpp. We can accomplish this by compiling HelloWorld.cpp to a HelloWorld.o module.

all: HelloWorld.o
	g++ -o HelloWorld Main.cpp HelloWorld.o

Similarly if you make changes to HelloWorld.h or HelloWorld.cpp, why do you need to recompile Main.cpp? So you can make it a module too.

all: Main.o HelloWorld.o
	g++ -o HelloWorld Main.o HelloWorld.o

Now only the libraries that have been modified will be recompiled when you run make. This can save significant build time when the project size increases.

Using variables in your Makefile

Mistakes are annoying.  Having to type the same thing in multiple places often leads to mistakes and typos. If you look at the above, there is duplication that is unnecessary.

Makefile with duplication

all: Main.o HelloWorld.o
	g++ -o HelloWorld Main.o HelloWorld.o

Makefile using a variable to avoid duplication

objs = Main.o HelloWorld.o
all: ${objs}
	g++ -o HelloWorld ${objs}

We can even add more variables which may not seem useful now, but are useful later.

CXX = g++
CXXFLAGS =
objs = Main.o HelloWorld.o
Outfile = HelloWorld

all: ${objs}
	${CXX} ${CXXFLAGS} -o ${Outfile} ${objs}

Think about it. Right now you only have one build command, but someday on a huge project you may have dozens and possibly hundreds. Could you imaging changing the CXXFLAGS everywhere? We don’t even have one listed yet, but of course, with the variable you only have to change it once in one place and it will work everywhere you used it.

Adding make clean to your Makefile

It is very common to want to delete all build files and build again. This is often done with the make clean command. But to get make clean to work you have to create a section or label in the make file called clean.

Because we already have variables, it is easy to configure the Makefile to support make clean.

Makefile with clean

CC = g++
CXXFLAGS = -W
objs = Main.o HelloWorld.o
Outfile = HelloWorld

all: ${objs}
	${CC} ${CXXFLAGS} -o ${Outfile} ${objs}

clean:
	rm ${objs} ${outfile}

So simple, we just use rm to delete the files we created, which are all in variables so we had a nice clean short command.

Adding debugging to your make file

There are two schools of thought for debugging.

  • All builds should be release builds unless you run make debug.
  • All builds should be debug builds unless you run make release.

I am not going to tell you which school of thought you should have.  What matters is that you can configure the Makefile to perform how you want it to.

This make file will always build without debugging (release) unless yous specify make debug.

CXX = g++
CXXFlags = -W
objs = Main.o HelloWorld.o
Outfile = HelloWorld

all: objects build

objects: ${objs}

debug: clean
CXXFLAGS += -g
LDFLAGS += -g

debug: objects build

build:
	${CXX} ${CXXFLAGS} -o ${Outfile} ${objs}

clean:
	rm -f ${objs} ${Outfile}

Notice we set LDFLAGS but we never actually call it. It is a special variable that is called automatically by the linker when creating the objects. Yes it must be capitalized.

How to create an Android menu?

Ok, so adding a menu that pops up from the bottom when the menu button is clicked is very common and quite easy to do.

Note: This assumes you have the Android SDK, Emulator, and Eclipse all working already.

Step 1 – Create your Android project

  1. In Eclipse, select File | New Project | Android | Android Project.
  2. Give your project a Name.
    I named this project “HelloAll”.
  3. Select the Build Target (the minimum version of Android).
    I selected Android 2.2.
  4. Enter a Package name.
    Package name is like a namespace, it can be anything you want, but you should actually choose a name as carefully as you choose and the name of an object.  I named the package this: org.rhyous.
  5. Click Finish.

Your project is now created.

Step 2 – Add an XML file for the menu

  1. Expand the res directory in your project.
  2. Right-click on the layout folder and choose New | Other.
  3. Choose XML | XML file and click Next.
  4. Name the file.
    I named my file menu.xml.
  5. Click Finish.
  6. Add the following text into your menu:
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        id="@+id/menu_item_1" android:title="@string/menu_1"/>
        id="@+id/menu_item_2" android:title="@string/menu_2"/>
        <item android:id="@+id/menu_item_3" android:title="@string/menu_3"/>
    </menu>
    

Step 3 – Add the strings for the menu items

  1. Expand the res\values directory in your project.
  2. Open the strings.xml.
  3. Add strings for each menu item.
    Make sure you use the same id strings you used in the menu.xml for the title of each menu item.
    Your strings.xml should now look like this:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="hello">Hello World, HelloAllActivity!</string>
        <string name="app_name">HelloAll</string>
        <string name="menu_1">Menu 1</string>
        <string name="menu_2">Menu 2</string>
        <string name="menu_3">Menu 3</string>
    </resources>
    

You now have a menu and strings for each menu item.

Step 4 – Overload onCreateOptionsMenu

  1. Open your Activity.
    Mine is src\org.rhyous\HelloAllActivity.java.
    It should look like this:

    package org.rhyous;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class HelloAllActivity extends Activity {
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle inSavedInstanceState) {
    		super.onCreate(inSavedInstanceState);
    		setContentView(R.layout.main);
    	}
    }
    
  2. Add code to override onCreateOptionsMenu and add code to inflate the menu.
    	@Override
    	public boolean onCreateOptionsMenu(Menu inMenu) {
    		super.onCreateOptionsMenu(inMenu);
    		getMenuInflater().inflate(R.layout.menu, inMenu);
    		return true;
    	}
    

You can now build your application and test that the menu pops up. However, the menu doesn’t do anything yet.

Step 5 – Overload onCreateOptionsMenu

  1. Add code to override onOptionsItemSelected and add code to inflate the menu.
  2. Use a switch statement with the inItem.getItemId() function to perform the appropriate action for each menu item.
    	@Override
    	public boolean onOptionsItemSelected(MenuItem inItem) {
    		switch (inItem.getItemId()) {
    		case R.id.menu_item_1:
    			// Do something here
    			return true;
    		case R.id.menu_item_2:
    			// Do something here
    			return true;
    		default:
    			// Should never get here
    			return false;
    		}
    

Based on the item clicked, the appropriate code will run.

Hope you enjoyed this simple Android development example.