vi — ‘already locked, session is read-only’

I recently came across this error in Vi after I was editing a file and was disconnect: “foo.txt already locked, session is read-only.” I thought it was a swp file issue of some sort, so I immediately searched for it to remove it. Only to find out that one didn’t exist.

So I did what most people do and searched Google for the solution. I was lead to a message board and found out that since I was disconnected, Vi had an open process of some sort still ‘editing’ the same file. The solution was simple. All you do is run a ps and grep for vi and kill the process. Here’s the command I ran:

ps -ef | grep vi

Once you get the pid, just kill it with, uhh, kill.

Done!

Stopping Starting Sendmail in FreeBSD

Here’s a quick reference for Sendmail users. The commands below are to start, stop, restart, and rebuild aliases for the Sendmail Daemon.

Stopping Sendmail
# cd /etc/mail
# make stop

Starting Sendmail
# cd /etc/mail
# make start

Restarting Sendmail
# cd /etc/mail
# make restart

Rebuild Aliases
# cd /etc/mail
# make

Enable Sendmail on startup
# echo ’sendmail_enable=”YES”‘ >> /etc/rc.conf
# echo ’sendmail_submit_enable=”YES”‘ >> /etc/rc.conf

Disable Sendmail on startup
# echo ’sendmail_enable=”NO”‘ >> /etc/rc.conf
# echo ’sendmail_submit_enable=”NO”‘ >> /etc/rc.conf

Done!!

FreeBSD 6.2 + PHP5 + PHP5-extensions = php.core dumps!!

I had just recently installed 2 new servers and both of them had PHP dumps (php.core) and issued a segmented fault, signal 11. I installed PHP5 and installed PHP5-Extensions through the ports.

My first experience with the dump, I wrote a simple code to calculate interest rates, which was totally incorrect (my code btw). My second experience, on another server, was when I was installing pear-DB through the ports. It uses PHP to compile and it kept erroring and wouldn’t finish compiling. So I searched Google and found out that when you install PHP extensions via ports, these dumps occur. I am not sure about the exact reason why it dumps, but apparently PHP is very picky as to when the extensions are loaded, or rather the order in which they are loaded.

So my first search landed me to the FreeBSD lists, and there, they said to make sure the sessions module loaded first, or somewhat first. I edited my extensions.ini file (/usr/local/etc/php/extensions.ini) and moved ‘extension=session.so’ to the top of the list. I saved the file, and re-compiled pear-DB, and it still errored. So I researched some more and I was lead to pingle.org. His post mentioned the same extensions order as well, but placing some of the extensions last. He had recode, mysql, imap, sockets, and lastly pspell at the bottom of his list. I did the same and what do you know, no more dumps!! Woo Hoo.

From what people are saying is that when you have this “magic” order of extensions, to save the order because when you upgrade php or the extensions, it will overwrite this file.

Done!!

Areca + FreeBSD 6.2 + >2TB Installation

I’ve been trying to set up a backup file server using FreeBSD 6.2-RELEASE amd64, Areca RAID, and using a partition that is >2TB. My first install crashed the server under heavy writing. I was rsyncing 3 servers simultaneously. Checking the logs, there were some “kernel: g_vfs_done():…Error: 5″ errors before the crash. I searched google and found out that it was a common error on Areca cards using FreeBSD. So I found a solution on the Areca website, http://areca.tw.com, and it said to edit the driver source code. I recompiled the kernel and started over again. This time, I am rsyncing 4 servers simultaneously and updating ALL the ports via cvsup (I had updated them earlier so there was nothing to really update. What I did was remove the ports tree, then I cvsup again). So far, no g_vfs_done errors and no crashes (knock on wood).

Here’s how I installed the server step by step:

1) I have 10×1TB Hitachi HD’s. I created 1 Volume at 100GB using RAID6 and another Volume at approximately 6.3TB using RAID6 as well. Make sure you use LBA 64 for any volume greater than 2TB. You can obviously create your own volumes depending on your usage. However, the 100GB Volume is just for FreeBSD.

2) Install FreeBSD on the first Volume, which should be da0. Do not touch the da1 volume.

3) When that’s done, install all the sources using sysinstall, and navigate to Configure > Distributions > src, and choose ALL.

4) Now we edit the driver. Open up /usr/src/sys/dev/arcmsr/arcmsr.c with any editor. You will see the following if statement at or around line 1304.

if(acb->srboutstandingcount >= ARCMSR_MAX_OUTSTANDING_CMD) {
pccb->ccb_h.status |= CAM_SCSI_BUSY; //<-- REMOVE THIS LINE
arcmsr_srb_complete(srb, 0);
return;
}

All you need to do is remove one line and add 2 more. The new if statement should look like this:

if(acb->srboutstandingcount >= ARCMSR_MAX_OUTSTANDING_CMD) {
pccb->ccb_h.status &= ~CAM_STATUS_MASK; //<-- ADD THIS LINE
pccb->ccb_h.status |= CAM_REQUEUE_REQ; //<-- ADD THIS LINE
arcmsr_srb_complete(srb, 0);
return;
}

5) Recompile the kernel and reboot (I was going to go into detail on the kernel recompile, but I will post this elsewhere).

Hopefully you have no errors up to this point. Now we partition the >2TB filesystem, mount it, and add to the fstab. From this point, I will use my volume set up. Just adjust to your settings if yours are different.

6) We will be using gpt to create a >2TB partition table.

# gpt create -f /dev/da1

7) Next, we add a gpt partition.

# gpt add /dev/da1

You can view the partition by using this:

# gpt show /dev/da1

8 ) Now we format the partition.

# newfs /dev/da1p1

9) Create a folder, let’s just name it /HUGE_STORAGE and then we mount it.

# mkdir /HUGE_STORAGE
# mount /dev/da1p1 /HUGE_STORAGE

10) Finally, we add this to fstab. Open up /etc/fstab and add this line to the bottom.

/dev/da1p1 /HUGE_STORAGE ufs rw 2 2

This exact set up has so far been a success. I will post anything that comes up, good or bad, here. Good luck!!

Done!!

UPDATE: Feb. 21, 2008 

I am happy to say that I have been monitoring this server and haven’t received any errors at all!! It runs about 3 rsyncs simultaneously nightly, and I’ve already tar/gzip’d  a 96GB file, mounted 2 samba mounts (which doesn’t have anything to do with the RAID card or hard drives), and moved/copied/removed/hard linked directories that were approximately 100Gb.

Recompile FreeBSD Kernel

Here’s how I recompiled the kernel. I got this from the FreeBSD Handbook, but I wanted to post for my own notes. If you want more information, please refernence the handbook at FreeBSD.org

1) Before we start, make sure that we install the all the sources. Just go to sysinstall and navigate to Configure > Distributions > src, and choose ALL.

2) The handbook says to either copy the kernel or link it from another location. I chose to link it from the /root directory. Let’s just call the kernel MYKERNEL (ya ya, just like the handbook).

# cd /usr/src/sys/i386/conf
# mkdir /root/kernels
# cp GENERIC /root/kernels/MYKERNEL
# ln -s /root/kernels/MYKERNEL

3) Now we can edit either the kernel or edit any driver source code or modules, like the Areca drivers.

The next step is to compile and install the new kernel, but I wanted to mention this: If all you did was edit a driver, like in my future post, (insert link), and you don’t want to recompile all the modules, then open up /etc/make.conf (or create one) and use MODULES_OVERRIDE. This will only compile the modules or drivers you tell it to. It will definitely make the compile go much faster.

Here’s an example: Say you edited the Areca Driver, and acpi. Your MODULES_OVERRIDE line would look like this:

MODULES_OVERRIDE = acpi arcmsr

One thing to note is that this is all relative to the /usr/src/sys/dev/ directory. So if you wanted to recompile a sound driver and the modules I mentioned above, you would use this:

MODULES_OVERRIDE = acpi arcmsr sound/sound sound/driver/ds1

4) Now we can compile the kernel…

# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL

5) and install it.

# make installkernel KERNCONF=MYKERNEL

And that’s it. Again, please reference the handbook at FreeBSD information.

Done!!

On FreeBSD before 6.2 ports system unfortunately can not set default X11BASE by itself…

This is kinda old news and pretty much intuitive, but if you have an old FreeBSD system and update your ports, you may receive this error message when you try to install a package:

On FreeBSD before 6.2 ports system unfortunately can not set default X11BASE by itself so please help it a bit by setting X11BASE=${LOCALBASE} in make.conf.
On the other hand, if you do wish to use non-default X11BASE, please set variable USE_NONDEFAULT_X11BASE.
*** Error code 1

Easy fix..just add X11BASE=${LOCALBASE} to the /etc/make.conf file like this…

echo 'X11BASE=${LOCALBASE}' >> /etc/make.conf

Done!!!

Logging in through SSH without a password

I normally don’t do this for my own personal account, but sometimes you need to use SSH in your scripts. Anyways, here we go:

I will refer to the server that you will access from as ‘Server_Alpha’, this is where the scripts would reside. The server that will be accessed, will be referred to as ‘Server_Beta’. The user wil be named, uhh, ‘User’.
First of all, make sure the user is in both machines. Once that is done, create a folder in your home directory with:

$ mkdir -p /usr/home/User/.ssh

Now to create the key:

$ ssh-keygen -t rsa

You will get a prompt and the output so far should be something like:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/User/.ssh/id_rsa):

Hit Enter, and it will then prompt for a passphrase. Do not use a passphrase. Just hit the enter button twice.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

If successful, you will see something like this:

Your identification has been saved in /home/User/.ssh/id_rsa.
Your public key has been saved in /home/User/.ssh/id_rsa.pub.
The key fingerprint is:
2f:c3:ab:02:ea:f3:c6:3e:6a:21:f4:a8:45:e1:65:77 User@Server_Alpha

OK, we are done with Server_Alpha. Let’s move on to Server_Beta.

Make sure that a .ssh directory exists in the home directory and copy id_rsa.pub from Server_Alpha to A file named authorized_keys in the .ssh folder.

You can copy and paste, or use ssh. Just make sure that it is only one line!!

Done!!

Removing Files That Begin With a Dash “-”

So I wasted about an hour of my life trying to figure out how to remove a filename that begins with a dash, like “-filename”. I tried quotes, backslashes, renaming the file, etc., and I still get the error:

rm: illegal option --

How did I figure this out?? Uhh read the manpage…haha

It looks like there are a few ways to do it. Let’s try to delete -filename

# rm -- -filename
# rm /full/path/to/-filename
# rm ./-filename

Done!!

Error installing GD from php5-extensions using FreeBSD Ports

I’ve run into another problem installing Apache-PHP-MySQL FreeBSD server. While installing php5-extensions, I received an error when it tried to install GD. Here’s the error:

===> Patching for php5-gd-5.2.3
===> Applying FreeBSD patches for php5-gd-5.2.3
===> php5-gd-5.2.3 depends on executable in : phpize - found
===> php5-gd-5.2.3 depends on file: /usr/local/bin/autoconf259 - found
===> php5-gd-5.2.3 depends on file: /usr/local/libdata/xorg/libraries - not found
===> Verifying install for /usr/local/libdata/xorg/libraries in /usr/ports/x11/xorg-libraries
/usr/X11R6 exists, but it is not a symlink. Installation cannot proceed.
This looks like an incompletely removed old version of X. In the current version, /usr/X11R6 must be a symlink if it exists at all.Please read /usr/ports/UPDATING (entry of 20070519) for the procedure to upgrade X.org related ports.
*** Error code 1
Stop in /usr/ports/x11/xorg-libraries.
*** Error code 1

Stop in /usr/ports/graphics/php5-gd.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.

To fix, all I did was add WITHOUT_X11=yes to my make install line. You can also do a XORG_UPGRADE=yes. Either way works, but the latter will install some x11 items.

Done!!

Can’t Install mysql50-server Through the Ports?

I’ve been trying to install mysql50-server via ports, but have been getting a checksum error, like this:

=> MD5 Checksum mismatch for mysql-5.0.41.tar.gz.
=> SHA256 Checksum mismatch for mysql-5.0.41.tar.gz.
===> Giving up on fetching files: mysql-5.0.41.tar.gz mysql-5.0.41.tar.gz
Make sure the Makefile and distinfo file (/usr/ports/databases/mysql50-server/distinfo)
are up to date. If you are absolutely sure you want to override this
check, type "make NO_CHECKSUM=yes [other args]".
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.

For an easy fix, all I did was fetch the mysql tar from freebsd.org and place in /usr/ports/distfiles/, intalled again through the ports, and voila!!

Here’s an easy one liner fixer (for the lazy people, like me). Just copy and paste at prompt.

cd /usr/ports/distfiles/ && fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/mysql-5.0.41.tar.gz && cd /usr/ports/databases/mysql50-server/ && make install clean

NOTE: This is all one line.

Done!!