Free DNS provides easy shared DNS hosting & URL forwarding
Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Thursday, April 17, 2014

Udev tricks - How to toggle built-in wi-fi on/off

My Toshiba Satellite laptop has a RTL8192CE built-in wifi, which is a total joke. It only works if I'm within a few meters range of the router and without any big obstacles between. For example, if I'm in my home office I can't even use the router that is in the next room. All other devices in our house can connect and mark it as strong signal. If by any luck my laptop manages to connect, the connection is unusable, with network speeds of less than 1Mb/s and most of the packages failing their CRC checksum.

I googled and test various solutions. None of them worked. I found many others which have same problem. Different OSes, different laptop models, same card type, same problem. After loosing (in total) more than 3 days on this, I decided it's just not worth it and bought and Atheros external USB wifi dongle (model TL-WN721N). It works perfectly and without any problems.

The problem I had now is that when I plug the USB wifi, Network Manager in Ubuntu clutters its menu and dialog boxes with various options to select which wifi card to use. For example, when I want to connect to a hidden network, it asked me to select which card to use for connection. It also used to keep trying to reconnect to the home network on the faulty card (but that I fixed by deleting Wi-fi network settings). This is annoying and overall makes me waste a lot of time. Therefore, I read udev man pages to find out how can I disable the built-in wifi whenever I plug in the USB one. Eventually I came up with these rules:

SUBSYSTEM=="net", ACTION=="add", ENV{INTERFACE}=="wlan1", RUN+="/sbin/rmmod rtl8192ce"
SUBSYSTEM=="net", ACTION=="remove", ENV{INTERFACE}=="wlan1", RUN+="/sbin/modprobe --quiet rtl8192ce"

The major time waster was ENV{INTERFACE}=="wlan1" because NAME=="wlan1" works on add event, but not on remove. I also lost some valueable time trying to get it work with INTERFACE=="wlan1", before I actually understood that INTERFACE is not a property.

These rules go under: /etc/udev/rules.d/99-disable-builtin-wlan.rules.

Later on, I decided to do something similar for the built-in soundcard (for similar reasons). It took me some time to find out the proper commands to disabled it. First I tried to remove its modules (like i did with the wifi), but that option failed because they were always in use by PulseAudio. So I started to look into PulseAudio options. I found the pactl (and pacmd) which seemed to do what I needed. It took another 30 minutes of testing to find out how to use them for this task and another 15 minutes to find out that they don't work as root, but should be run as the current user. After that, writing the udev rules was a piece of cake:

SUBSYSTEM=="sound", ACTION=="add", ENV{ID_TYPE}=="audio", RUN+="/bin/su abautu -c '/usr/bin/pactl set-card-profile alsa_card.pci-0000_00_1b.0 off'"
SUBSYSTEM=="sound", ACTION=="remove", ENV{ID_TYPE}=="audio", RUN+="/bin/su abautu -c '/usr/bin/pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo+input:analog-stereo'"

Note that you need to replace "su abautu" with your own username or it won't work.

Thursday, January 30, 2014

How to create ASCII armored signatures/encrypted files with Seahorse plugin

Recently I played looked into various Linux (Ubuntu) software that can digitally sign documents. After testing various software (open source and proprietary) and various signature options, I decided that Ubuntu's Seahorse best fits my needs. After installing the seahorse-plugins package, I was thrilled with the results with respect to flexibility, ease of use, and end results.
Only one thing was bugging me: when signing (or encrypting) a file, the result file was in binary format. It worked fine, but I just felt that an ASCII armored file would be better (for me). I tried to find some UI option to change that, but I didn't. I googled for this feature, but found nothing interesting (except for requests/forum posts of other people asking about this feature). In the end, I decided to download the source code and see how it works. After 15 minutes of searching through code, I found out what I needed. It's really easy.
To create ASCII armored signatures/encrypted files with Seahorse plugin (in Nautilus) I followed these steps:
1. open gconf-editor
2. navigate to /desktop/pgp/ascii_armor
3. enable the ascii_armor option
Once I found out what the option name was, googleing exactly that got me to this page: https://wiki.gnome.org/Apps/Seahorse/SpecialGconfKeys

Saturday, November 9, 2013

Openssl - setting up a custom CA certificate, requesting and approving certificates with Subject Alternative Name (SAN)

I spent last couple of hours reading web resources, man pages and config files to get what I need: a custom CA setup that allows me to sign certificate request which include Subject Alternative Name (SAN) extensions.

Setup custom CA certificate

I started with the Ubuntu certificates guide. It explains how to setup the custom CA. I used the instructions in there, but I decided to use the default Ubuntu CA setup (which used /etc/ssl/demoCA directory).
First I edited /etc/ssl/openssl.cnf. In the CA_default section:
- I changed dir = ./demoCA to dir = /etc/ssl/demoCA (this is so that I can run openssl ca from any directory without entering full paths)
- I uncommented copy_extensions = copy  (this is required so that I can include in certificates SANs from their certificate requests)

In the req section:
- I uncommented req_extensions = v3_req

In the v3_req section
- I added subjectAltName = $ENV::subjectAltName so that I can pass SAN content via environmental variables (I found this trick somewhere on the internet, in order to avoid writing them in config files).


Finally I ran following commands to create the required files:
sudo mkdir /etc/ssl/demoCA
cd /etc/ssl/demoCA
sudo sh -c "echo '01' > serial"
sudo touch index.txt
sudo mkdir private newcerts
sudo chown 700 private newcerts
sudo openssl req -new -x509 -extensions v3_ca -keyout private/cakey.pem -out cacert.pem -days 3650 -newkey rsa:2048

Create a certificate with SAN

As indicated in the Ubuntu docs (and lots of other places):
openssl genrsa -des3 -out server.key 2048
openssl rsa -in server.key -out server.key.insecure
mv server.key server.key.secure
mv server.key.insecure server.key
env 'subjectAltName=DNS:testbox.local' openssl req -reqexts v3_req -new -key server.key -out server.csr
openssl req -in server.csr -noout -text
sudo env 'subjectAltName=DNS:testbox.local' openssl ca -in server.csr 
The signed certificate will be saved in /etc/ssl/demoCA/newcerts/.

Sunday, October 28, 2012

Speed up Ubuntu Quantal Quetzal

I recently upgraded my Ubuntu 12.04 Precise to Ubuntu 12.10. Overall, I didn't see much difference, probably because I didn't run/notice the bugs/limitations that were fixed in this new release. One thing that I (subjectively) noticed is that boot up and application startup is slower, with the UI experiencing occasional freezes. I guess these slowness/freezes were already in 12.04, but they become more obvious after the upgrade. To the point that they become frustrating. So I looked into some ways that might speed up the system (not minor or complete tweakings, but just a few to get over the current situation).

Mount options

First thing I tried was adding nodiratime and noatime options to the mount options of / and /home partitions. To do that, just edit /etc/fstab and add these options alongside the existing ones. My fstab looks something like this now:
/dev/sda1 / ext4 nodiratime,noatime,errors=remount-ro 0 1
UUID=..... /home ext4 defaults,nodiratime,noatime 0 2
I didn't notice any major speedup after these changes, but they do seem common sense and lack of speedup might be due to my particular setup (some VMs I'm using).

Install ureadahead

Next I installed the ureadahead package which is supposed to lower boot up times. Install was easy:
sudo apt-get install ureadahead
According to what I read, on first run, ureadahead logs bootup files accesses and then aggregates these files into cached file that will be used in next bootups to speed things up. It also optimizes this cached file according to the type of disk that you have (SSD or HDD). After the system boots, ureadahead process seems to terminate and just gets out of the way.
I didn't notice any major speedup on this either. It could be some, but bootup time is still several times more of the Ubuntu advertised "10 seconds bootup".

Install preload

Preload is a daemon that logs statistics about programs usage and requirements and use these statistics to speed up programs startup. I guess this is what Windows has on by default in that prefetched folder. As mentioned in the man pages, the speed up is not immediately, because preload first needs to collect the stats and create some caches before it can use them. Even so, I did see programs starting faster pretty soon after installing preload. I just installed using:
sudo apt-get install preload

Install prelink

Preling is a tool that improves memory usage and load times by optimizing programs and libraries. Install it using:
sudo apt-get install prelink
After install, you need to start the optimization process. Before I did that, first I edited /etc/prelink.conf to include /opt directory in the optimization process because I have some custome software there. After that, just run

sudo prelink -avmR
The option v is for verbose so that you can see what's processing. You could remove that if you don't care. I guess I'll need to run such a command when I update/install new software, but that's not a big issue.
Although I installed it mostly for the "memory optimizations" promise, Prelink also seemed to help with speed. I'm not sure how much since I installed it after preload which already helped in that area.

Tuesday, November 29, 2011

Setup GeoIP for PHP5 on Ubuntu Server

I lost a few hours on this, although I done it sometime ago. To make sure I don't forget it again, here it is:
  1. Install geoip packages:
    sudo apt-get install geoip-bin php5-geoip
  2. Download GeoIP Lite version:
    wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -O /tmp/GeoLiteCity.dat.gz
  3. Unzip GeoIP Lite to /usr/share/GeoIP/GeoIPCity.dat (this is what I forgot: to rename the file):
    sudo gunzip -c /tmp/GeoLiteCity.dat.gz > /usr/share/GeoIP/GeoIPCity.dat
  4. Reload apache
    sudo /etc/init.d/apache2 reload

Tuesday, July 6, 2010

Working out OpenVPN with Network Manager in Lucid Lynx

For two years now, I've used OpenVPN to connect to a server where I upload some of the stuff I work on. Until now I always started OpenVPN from the terminal, because I didn't manage to get it working from the Network Manager in the last 4 Ubuntu versions.
Last weekend, I had some spare time and I installed Lucid Lynx on my laptop. I tried (again) to get OpenVPN working with Network Manager. As usually it failed, although I was pretty sure everything I did was correct.
So I decided to import my existing openvpn configuration file and export it back to see if there's something different. After doing this, I've noticed a few difference, but most of them were just due to syntax. However, two lines looked more interesting:

user openvpn
group openvpn
I've checked and saw that with these lines in the configuration file, the openvpn connection failed to start even from the terminal. Therefore, I did the following:
  1. create the openvpn group as a system group using

    groupadd -r openvpn
  2. assign the openvpn group to the directory (and files) that holds my openvpn key and certificates (mine and server's):

    chgrp -R openvpn openvpn_folder
  3. assign group read permissions to the openvpn settings directory and remove permissions for others:

    chmod g+r,o-rwx openvpn_folder
After these steps, the OpenVPN connection started from the Network Manager without problems (note that it's recommended route only traffic for that network through that connection).

Tuesday, May 4, 2010

Manually setup the Broadcom wireless card firmware on Dell Inspiron 1501

These steps summarize the information presented here: http://wireless.kernel.org/en/users/Drivers/b43#devicefirmware.
  1. Download and extract the b43-fwcutter.
  2. Download and extract the Broadcom drivers.
  3. Compile the b43-fwcutter
  4. Run the b43-fwcutter to extract the firmware
Run the following commands as root and then restart the network service:
cd /tmp 
wget http://bu3sch.de/b43/fwcutter/b43-fwcutter-013.tar.bz2
wget http://mirror2.openwrt.org/sources/broadcom-wl-4.150.10.5.tar.bz2
tar xjf b43-fwcutter-013.tar.bz2
tar xjf broadcom-wl-4.150.10.5.tar.bz2
cd b43-fwcutter-013
make
cd ..
b43-fwcutter-013/b43-fwcutter -w /lib/firmware broadcom-wl-4.150.10.5/driver/wl_apsta_mimo.o

Thursday, January 28, 2010

Thunderbird beats Evolution

I recently decided to get my email stored locally in case my internet connection fails and I need them. I used to have them save in Outlook Express (for backup purposes), but I dropped this habbit when I start forwarding everything to Gmail.
I decided to give Evolution a shot and see how it's doing these days. This is mainly because of it's "great integration with Gnome". The overall interface it's not very impressive, and looks like it's an old application. I could have gone along with it, no problem, but something else was a show stopper: I use POP3 and all email clients I used allowed me to "delete email on server when deleted from Inbox". Guess what? Evolution does not have this (again, for POP). It's either "delete emails when retrieving" or "delete after X days". It seems that this feature was requested back in Evolution 1.0 but it was never implemented. I search a lot on forums for an explanation and I found two Evolution developers (back in a 2003 thread):
  1. this feature is a POP hack and will not be implemented
  2. Evolution is targeted more to enterprise users which use IMAP
My reaction was:
  1. is it "hack" to use two POP commands to get a feature implemented? I guess no, since all other clients are doing it. Or maybe, they are all hackers, and Evolution developers are the real-deal.
  2. then why "force" it into my new Ubuntu desktop install (like that other half application that tries to replace Pidgin)?
One way or the other, Evolution is purged and Thunderbird is installed on my system (btw, same goes with empathy and pidgin). I care less for "Gnome integration" than I care about functionality.

Wednesday, November 11, 2009

Karmic Koala doesn't like my display

Yesterday I installed Karmic Koala on my office PC. I had a Jaunty installation before that I did not used/customize much so I figured there's not much for me to gain in an upgrade. Thus, I did a fresh install from a 4GB USB stick. The installation went very well, taking less than 15 minutes boot-to-reboot. Another thing I liked is that there was no need to unplug & replug the USB stick during the installation (this was required by Jaunty and earlier versions).
The first things I noticed is that overall the system is much nicer than Jaunty:
  • the icon theme has greater details and nicer design,
  • it has up-to-date packages not available in Jaunty (like Octave 3.2),
  • start up time has lowered (not at much as others say, but then again, my PC is not cutting edge),
  • the new IM client is empathy (I'm using it right now, but I'm not sure I like it better than Pidgin).
This means that upgrading my home PC will be a step forward (that I can't do right now because of other work).
One thing that I then noticed as annoying was the slow resolution (800x600) and the incapacity to make it larger. I then realized this happens in Xubuntu 9.10, too. Therefore it's not related to Xubuntu (as I thought before).
I spend some time on forums, trying to find a direct solution for this problem only to find out that something changed in X and something else changed in the kernel, and one is using the other, and there's another link point to another 5 pages discussion and then another link, and so on.
One thing that I got by browsing though all these forum posts was this: X in Ubuntu Karmic Koala comes with no xorg.conf because it's suppose to autodetect the video card and display settings. It does not happen in my case. I blamed the video card.
Next thing I found useful is that I can make X write a configuration for me using the command:
X -configure
This is new stuff for me, because I used x86cfg (or something similar) to do this way back (like 2-3 years ago). Anyway, this creates a file called xorg.cfg.new in my home directory which I then moved into /etc/X11, renamed it to xorg.cfg, and restarted the Gnome Display Manager (gdm) service.

This did not solve the problem either. So I went and looked into /var/log/Xorg.0.log to see if I get some pointers on whats happening. I saw a lot of messages like this:
(II) intel(0): EDID for output VGA1
(II) intel(0): Not using default mode "640x350" (vrefresh out of range)
(II) intel(0): Not using default mode "640x400" (vrefresh out of range)
(II) intel(0): Not using default mode "720x400" (vrefresh out of range)
... and so on

Then I realized that it's not the video card, but the display that is not being detected correctly. So I added the following lines to my /etc/X11/xorg.conf (I found something similar on forums) inside the "Monitor" section:
HorizSync 28-64
VertRefresh 43-75

This did the trick and after restarting gdm, I got a wonderful big resolution (which I trimmed down to 1024x768).

Tuesday, November 10, 2009

Surprice "gift" inside the Octave package

Today I noticed that my Octave packages got upgraded to Octave 3.2 (from 3.1). I don't know when that happened, but I immediately typed news to see what's new. I was expecting a few bug fixes, one or two new features and some code rewrites. I was wonderfully surprised by the large number of major changes that come with 3.2.
The full list is available on http://www.gnu.org/software/octave/NEWS-3.2.html, but just to mention a few:
  • Many optimizations: sorting and searching, matrix transposition, array indexing, logical operators, etc.
  • Block comments: this will allow me to easily comment large chunks of code
  • Object Oriented Programming: I'm not sure how soon I'll get to use that, but it's nice to know it is there.

Sunday, November 8, 2009

I'm hooked to Linux

These days I "celebrate" 1 year since I switched to Linux as my main operating system. Before I continue, I have to say that I still use Windows XP at my office (older PC) and occasionaly at home (mostly for existing Texnic Center projects and Microsoft Excel).

I started using Ubuntu on a daily basis about 1 year ago (by upgrading from the until-then unfrequently used 8.04 to 8.10). I used Linux before but just to see what's new in it:

  • starting in 2002 with Mandrake 8 (I started by formatting by mistake the entire disk instead of the future home partition);
  • moving then to Mandriva Free 2004 (former Mandrake);
  • tried Ubuntu 6 (that I got from Tudor);
  • returned to Mandriva Free (2006, I believe);
  • played with Fedora (which I didn't like because I wasn't fond of Gnome);
  • tested Kubuntu 7.10 (because of KDE);
  • moved to Kubuntu 8.04 (which I didn't like because of KDE 4);
  • installed Ubuntu 8.04 (but didn't used it much);
  • upgraded to Ubuntu 8.10 (and switched to Linux).

I liked Ubuntu because I found it very easy to install applications on it. Since I do a lot of development, I also use the terminal quite frequently and the command line completion features also helped me a lot in my first days (and they still do). Overall, I'm very happy with it, although it requires more RAM than Windows XP to run smoothly (especially when you start Office applications). Currently, my 1GB RAM (don't laugh!) is doing it's job, but I ordered more RAM on eBay (that's also a premier for me). I had my ups-and-downs with Ubuntu (like getting Skype to work), but it's been fun to learn. Some things (like getting the webcam to work), I didn't figure out until now and I'm still wasting time trying to fix it.

Since I switched to Ubuntu, I kept on looking to other distributions, too, but I always returned to Ubuntu:

  • Xubuntu - I like it (especially because it's simple UI), but i find it limited (e.g. mousepad vs. gedit) and buggy (on my Dell Inspiron laptop it doesn't allow dual-displays, on my Maguay office PC is allows 800x600 pixels, etc).
  • ArchLinux - didn't finish installing it: I'm a techie user and I used more or less many OSs (including CP/M, MSDOS 5, Windows 3.1, Windows 95, QNX, etc), but I never liked doing more task that are required (these days, this means typing long cryptic commands that are hard to figure out or reproduce unless you use them daily or you have a wiki page in front of you)
  • LinuxMint - I liked it a lot especially because the launch menu (Ubuntu System Panel), but except for that, it felt too close to Ubuntu to make the switch. Instead I installed its launch menu in Ubuntu.
  • openSuse - nice but less friendly than Ubuntu. It also has a nice launch menu which looked cool the first time I tested it, but last week I checked it again and it felt just annoying (just like Vista and KDE4's menu). Too many clicks to open an application.
  • OpenSolaris - No, no, no. I don't have that much RAM to throw at the OS. I need RAM for my applications. Unfortunatelly, it's like comparing Visual Studio with Eclipse. One is fast and memory efficient, the other is not (but I use Eclipse).

Monday, May 18, 2009

Eclipse says "Workspace in use or cannot be created"

Out of the blue, Eclipse is saying that the "Workspace in use or cannot be created". I say ok, probably a lock file was left behind and so I do:
rm ~/workspace/.metadata/.lock

No error (so the file was left behind), yet the problem is not solved. I tried clearing out the workspace path. Same problem.
Googleing, I found this post, so I ran:
sudo gedit /usr/share/eclipse/configuration/.settings/org.eclipse.ui.ide.prefs
removed the RECENT_WORKSPACES line. It works now.