Sunday, February 28, 2010

Do It Sudo

I've come across a couple sudo tricks during the past few days and thought I would pass them along.

The first thing you need to know before using sudo is that you should use the visudo command to edit the sudo config file. This script does a number of useful things, like creating a lock to prevent mulitple editing, and doing some sanity check. But if you have the problem that setting $EDITOR and $VISUAL is ignored when running something with sudo (like sudo visudo or sudo crontab -e), that's a sudo config issue. Add the following in your /etc/sudoers file:

Defaults env_keep += "EDITOR VISUAL"

And you can use sudo from within your normal Emacs window by using the Emacs' Tramp Mode, which allows all kinds of editing, even remote editing. Just use the sudo "protocol" when editing a system file, like /etc/fstab:

Find file: /sudo::/etc/fstab

This will prompt you for your password (not the root password - remember, we're doing this via sudo, which wants your password, not root's). Type it in and you can edit the file in place, rather than running a special Emacs process as root. Very nice!

Monday, February 15, 2010

Org-ing in Emacs

I have been using emacs since the beginning of computer time, way back in the mid-80s. My .emacs file has been carried around for almost as long. Each major rev causes me headaches, as I never know what archaic options are going to break things. And yet, I'm still learning new things to do with it. I think it inspired Zawinski's Law of Software Envelopment:



Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can.


My latest Emacs discovery was on an Arch Linux forum thread on note taking software. I use Remember The Milk for plenty of lists, but the web based nature of it makes it hard to be quick about doing a quick note. I started keeping a simple text file with notes on what I was doing, as I was finding whole hours at the keyboard disappearing into a black hole. I whipped up a quick Emacs macro that I bound to F7, which opened a file to prepend a new quick entry:



(setq logfile-name "/home/jdarnold/Dropbox/dailylog.txt")
(defun insert-new-log ()
"Start a new log entry"
(interactive)
(find-file logfile-name)
(beginning-of-buffer)
(insert "==== ")
(insert-now)
(insert "\n\n")
(previous-line)
)


As you can see, I put the file in my Dropbox folder (use this link to sign up and we both get an extra 250gb of storage space), so no matter which computer I'm working on, I can jot a quick note that looks something like this:



==== Monday, January 25 2010 10:43 AM (1264434222)
after a couple of hours puttering around, including writing a review
for Goodreads, I'm back at work. Trying to figure out what I did to
break the video plugin
#insors


I have a few adhoc tags, stamp it with time date and Unix time, and tried to see what I was working. It's okay, but if I forgot to jot something down when I left the keyboard (which I often did), it lost a lot of its effectiveness.



Then I found out about org-mode in Emacs. It's been in the standard Emacs distribution for a couple of releases, but I'd never heard of it before. And wow, is it amazing! The PDF of the User Manual is nearly 200 pages! And it really does everything you could want in an organizer/todo manager/note taker. It even has a clock in/clock out/idle timeout paradigm, so it can notice when I've walked away from my computer. Unfortuantely, "real" idle only works on Mac OSX and Linux (after compiling x11dle.c). On Windows, it just notices when you are idle in Emacs, which, despite the fact I use Emacs alot on Windows, isn't quite the same thing.



So now I've changed my Emacs checkin macro to be:



(defun start-new-task ()
"Start new journal task"
(interactive)
(find-file (concat dropbox-folder "org/" journalname))
(end-of-buffer)
(org-insert-heading)
(org-clock-in)
)


so it adds a new heading and starts the clock. And on my work machine, I set journalname to be a work journal and on my personal machine, I give it a different name. Still working out the kinks in the process, but it's closer to tracking what I've been doing.



I also intend on using org-mode to jot down my myriad project ideas. I'm always coming across interesting web sites, esp. for web APIs, that make me want to dabble in some projects, but I've never had anywhere to jot them down. I was using MindMeister.com, an online mind-mapping tool for it, but found it too structured. Given org-mode's flexibility, I should be able to find some easy way to just add my "brilliant" brainstorms to a file!



Monday, February 8, 2010

Tumblings, Jan 24

A couple of links posted to my Linux Tumblr last week:






Sunday, February 7, 2010

Arched

So early in December, I went on a quest for a new Linux distro. It wasn't so much that I was unhappy with my openSUSE 11.0 installation, but I knew I was probably going to install the new 11.2 version and so I figured I would cast about to see what's up with the other KDE distros. And given that Linux Format had just done a big review on the "best" KDE distros out there, it was good timing all around.



I didn't really have as complete a checklist of features as I have had in the past. Of course, it had to install on my beast of a machine, with its myriad hard drives, cd drives, dual monitors, and the like. I wanted an easy to use package manager, with plenty of packages available. I was't quite as sold on a "one size fits all" admin panel like openSUSE's Yast2. I'm feeling a little more adventurous, and hate to see my configs get changed without my knowledge. I wanted a KDE distro, as I find GNOME to be bizarre. I didn't want to get too far off the beaten path, as I like a popular, well documented distro.



First up was Sabayon, which has been getting lots of good press. I wasn't crazy about their home page - it was too hard to find even the download link. And there were a few kinks in the install process. It was a few months ago, so I don't remember exactly the problems, but they were enough to sour me on it a bit. It did have exactly the same problem I was going to find in all the rest of my installs, which is that the setup hard drive numbering for GRUB was always different than the final installation drive numbering, requiring me to reboot using the live disc and edit the /boot/grub/menu.lst file and change the hd0 to hd1. Not sure why that is, but I guess the mix of IDE & SATA hard drives makes it crazy.



So after dabbling a bit with Sabayon, I moved over to try Sidux, which really intrigued me with its cutting edge release and huge package library. It also had an incredibly clean install process and the desktop is stunning. Really a very polished and good looking release. It has a very nice community with lots of good info on the web site. I was a little turned off by its insistence that you drop down into single user mode to install any updates, which isn't something I like doing.



But I played with Sidux for a couple of days. It was nice, but I decided to give Arch Linux a try. It had been written up very nicely in the previous issue of Linux Format, in the "Remix Your Own Linux" article. It's overriding philosophy of "Keep It Simple" was really attractive, as was the very large package library. I found it amusing that the Live CD boots into a commandline, the installer is the old fashioned text-mode graphics and, even after installing, you end up with commandline! It doesn't even install X for you.



I found this a refreshing change and decided to jump right in. I even decided against installing KDE and just run openbox with a stripped down config. It's really been working nicely for me and I haven't looked back. Arch makes a great server install, as there is very little cruft installed by default. When I built my media server machine, with its 1tb software RAID, I only added Emacs & Samba and I know it is a lean, mean, serving machine.



The Arch wiki is incredibly informative and comes up early in many Google searches. The forums are active with intelligent discussions and it is a very nice, experienced, community. While I wouldn't use it for my Grandma's Linux, Arch is a great distro once you get some Linux experience and want to tailor a distro to your ideas, and not the other way around. Arch is also why the calls for fewer distros is misguided. It isn't for everyone but as long as each distro has a certain focus, and hues to it closely like Arch does, there's plenty of room out there. Next up - theme color changes!




Monday, February 1, 2010

On Being Persistent

Those of us who have multiple hard drives in our computers will inevitably boot up one morning to find the naming scheme for these drives has changed. What was once /dev/sda is now /dev/sdb and vice versa. Your computer won't boot and fsck complains about an uknown or mismatched filesystem type. This is especially true after a kernel upgrade. Nothing really can be done about this random renaming, as it is all in the timing. But how can you fix the problem?



Actually, it's a pretty easy fix. Instead of using /dev/sd? in places like grub's menu.lst file and the all important /etc/fstab, use a special label that doesn't change. I find using UUID's to be the best solution.



There are a couple of ways to get the UUID of a hard drive. The easiest is to use the blkid command from the commandline. It lists all the hard drives, along with their UUID and TYPE:



$ blkid
/dev/sdb1: LABEL="ReiserData" UUID="0e9c1455-4993-4ddf-a86a-a3dac116a5cc" TYPE="reiserfs"
/dev/sda1: UUID="a846c306-3114-403d-b893-a3e27704755a" TYPE="ext3" SEC_TYPE="ext2"
/dev/sda3: UUID="c03ce6c7-32ab-41e9-b603-da09acc0fbab" TYPE="ext4"
/dev/sda4: UUID="303889b7-ae78-436f-85ac-da95b2280596" TYPE="ext3"
/dev/sda5: LABEL="/home" UUID="d6db1ae8-30d6-48ee-8a66-90912480e8be" TYPE="ext3" SEC_TYPE="ext2"
/dev/sda6: UUID="71712106-eef9-48c3-840f-20fb77173a9d" TYPE="swap"
/dev/sdb2: LABEL="GAMEY2" UUID="4B89-0200" TYPE="vfat"
/dev/sdc1: UUID="59ac55ab-93f8-4466-804d-57d1148b76e5" TYPE="ext3"
/dev/sdc2: UUID="260834A7083477BF" LABEL="Media" TYPE="ntfs"


You can also get the UUID of paritions by using ls :



$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Feb 1 00:00 0e9c1455-4993-4ddf-a86a-a3dac116a5cc -> ../../sdc1
lrwxrwxrwx 1 root root 10 Feb 1 00:00 260834A7083477BF -> ../../sdb2
lrwxrwxrwx 1 root root 10 Feb 1 00:00 303889b7-ae78-436f-85ac-da95b2280596 -> ../../sda4
lrwxrwxrwx 1 root root 10 Feb 1 00:00 4B89-0200 -> ../../sdc2
lrwxrwxrwx 1 root root 10 Feb 1 00:00 59ac55ab-93f8-4466-804d-57d1148b76e5 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Feb 1 00:00 71712106-eef9-48c3-840f-20fb77173a9d -> ../../sda6
lrwxrwxrwx 1 root root 10 Feb 1 00:00 a846c306-3114-403d-b893-a3e27704755a -> ../../sda1
lrwxrwxrwx 1 root root 10 Feb 1 00:00 c03ce6c7-32ab-41e9-b603-da09acc0fbab -> ../../sda3
lrwxrwxrwx 1 root root 10 Feb 1 00:00 d6db1ae8-30d6-48ee-8a66-90912480e8be -> ../../sda5


You can see that FAT32 and NTFS partitions have different kinds of UUIDs, but it should work for our purposes. Now you just need to replace all references to the various /dev/sd? names with the correct UUID. This will remove all "randomness" from the boot order. Even if you currently have only one hard drive, you really should go to this "persistent" method of naming partitions, as you never know when you might add another.



In the /etc/fstab, replace /dev/sd? with UUID="uuid", like this:




#/dev/sda4
UUID="303889b7-ae78-436f-85ac-da95b2280596" / ext3 defaults 0 1


and in the /boot/grub/menu.lst file, replace it with the /dev/disk/by-uuid path, like this:



kernel /boot/vmlinuz26 root=/dev/disk/by-uuid/303889b7-ae78-436f-85ac-da95b2280596 ro vga=773


The Arch Linux Wiki has a very nice page on Persistent block device naming here: http://goo.gl/GTWT.



Wednesday, December 2, 2009

Glorious LXF126 Contest

Linux Format #126 Cover Image
If you are the winner in my glorious Linux Format 2009 Christmas Issue giveaway, here's what you have to look forward to:




  • Ultimate eye candy

    - a pretty interesting article on how to get the most dazzling display, whether you use Compiz, KDE, or GNOME. Despite my general disdain for eye candy, I would try the Compiz/Emerald 3d window manager if it worked on dual monitors, but last I looked it didn't support them.

  • KDE distributions

    - coincidentally enough, just as I'm looking to move on up from my OpenSUSE 11.0 install, along comes LXF with their KDE distro Roundup. I wouldn't have to go too far afield if I stayed with their winner, which is OpenSUSE 11.2, but I'm trying out a couple of other ones they regard highly, like Sabayon and Sidux. I'm a KDE man, so it works out well.

  • Get to grips with /proc and /sysfs

    - this is an excellent overview of the virtual filesystems /proc and /sysfs.

  • DVD Coverdisc

    - the DVD coverdisc includes live previews of the latest versions of KDE and GNOME, which is pretty cool. It also includes Ubuntu Netbook Remix (which I think I'll try on my Dell Mini), Moblin 2.0 and Puppy Linux 4.3.



To enter my little contest, where I will mail you a pristine copy of LXF #126, along with the DVD coverdisc, just drop me an email at jdarnold@buddydog.org. On Monday, Dec. 7th, probably in the evening, I will randomly select one entry and email you back asking for your mailing address and soon it will show up on your doorstep. Open to both of my international readers too :)



Oh, and I also heartily endorse subscribing to the magazine. Yeah, it's pretty expensive, but if you do it via the TuxRadar web page, you can cut it down to US$99 for 13 issues. And, as a subscriber, you get access to all the back issues in PDF format and they really have gotten their act together with it. The PDFs look great and they have a nice HTML page linking it all together. You won't be disappointed.