Tuesday, April 3, 2012

LVM Basics

I've just spent a few hours with an EqualLogic iSCSI SAN disks and Linux Logical Volume Manager (LVM). The abstraction is even deeper than that, because Linux at work is running under VMware, so it is really VMware talking to the SAN and presenting a SCSI disk to Linux. Since I only get into the LVM weeds a few of times a year, I thought it would be helpful to list the steps to get usable disk space under Linux starting with the raw disk space.

Step One - create a new partition

Create a new partition with FDISK or PARTED. Mark the partition type hex 8E for LVM. In my case, the SCSI disk appeared as /dev/sdb and the partition using all space became /dev/sdb1. LVM is capable of using a raw device (no partition type), but I stayed in familiar partitioning territory.

Step Two - create LVM physical volume

pvcreate /dev/sdb1

Step Three - create LVM volume group in the physical volume

vgcreate new_volume_group /dev/sdb1

Step Four - create LVM logical volume in the volume group

lvcreate --name new_logical_volume --size 100G new_volume_group

Step Five - create a file system on the logical volume

mkfs -t ext4 /dev/mapper/new_volume_group-new_logical_volume
Note: Linux device mapper automatically creates a symlink to the disk in /dev/mapper using the volume group and logical volume names. If you choose more meaningful names than the example, the name won't look so awful.

Step Six - turn off automatic file system checks (optional)

tune2fs -c 0 /dev/mapper/new_volume_group-new_logical_volume

Step Seven - add mount point in /etc/fstab

Once the mount point is list in fstab, mount it manually and it is ready to use.

Saturday, March 31, 2012

File Timestamps [classic]

Each file has three timestamps associated with it (stored as the number of seconds since the Epoch, Jan 1, 1970). The three timestamps are:

  • Access time (atime) - the last time the file was read
  • Modify time (mtime) - the last time the file contents were changed
  • Change time (ctime) - the last time the file permissions were changed

In a long directory listing, the timestamp shown is the Modify time (mtime). To see all timestamps and a lot of other useful information, use the stat program with the verbose option (-x):
stat -x filename

Here is sample output from stat:
keithw$ stat -x "Mona Lisa Overdrive.mp3"
File: "Mona Lisa Overdrive.mp3"
Size: 6853358 FileType: Regular File
Mode: (0644/-rw-r--r--) Uid: (501/ keithw) Gid: (501/ keithw)
Device: 14,9 Inode: 10208 Links: 1
Access: Fri May 25 11:46:30 2007
Modify: Fri Dec 8 16:38:54 2006
Change: Fri Dec 8 16:38:54 2006

Deleting files with bad names [classic]

If a file with a bad name gets accidentally created, such as a name that begins with a hyphen "-", it can't be deleted with a normal remove command (rm). Use the "--" option to tell rm that no more options follow, then it can delete the file.

To delete a file whose file name begins with "-":

rm -- -bad-file-name
Or
rm ./-bad-file-name

To delete a file with non-printable characters in the name:

Use shell wildcards, '?' for one character and '*' for zero or more characters. For example, if the file name "bad file name" can't be deleted, one of the spaces may in fact contain a hexademical value. Try:
rm bad?file?name

caution: run ls bad?file?name first to make sure you are not matching more files than you think with wildcards before deleting them.

Thursday, March 29, 2012

Asus 1001-PXD Project: Keyboard Replacement

After I got Easy Peasy running, I ordered a replacement keyboard on eBay.

The keyboard that came with it was warped and bulging a little in spots, so I wanted to install a fresh one.

I found some instructions online that described the steps involved, but this YouTube video was very helpful.

You can use a spudger or a small standard screwdriver to make the switch. The key to getting the top part of the keyboard out is to push the small connectors at the top back a little, allowing the keyboard to pop out. I mangled one of the keys on the old keyboard trying to find the right angle. No permanent damage.

The keyboard I bought was for a 1001HA, but it worked perfectly in the 1001PXD. In fact, the colorized icons look even better than the original. The netbook is working liking a dream.

Saturday, March 24, 2012

Asus 1001-PXD Project: Installation

I bought an Asus 1001PXD netbook on eBay to create custom Linux "couch computer". The idea was to have someone light, portable, and secure and that didn't cost as much as an iPad or Galaxy tablet. I had done a little research on which netbooks were Linux compatible and on the various netbook oriented distributions, but it turned out to be a little trouble than I expected.

Updating the BIOS for USB book

The netbook came with Windows 7 starter edition. The first step was to update the BIOS so it supported booting from a USB flash drive. One of the guides I referenced was this one for Crunch Bang Linux.

One of the early steps to get ready for the BIOS update is:

prepare your USB flash drive with a: 16 mb FAT16 partition at the start of the disk
I first tried using a FAT32 USB drive, but that was never recognized by the Asus BIOS update utility. Next, I tried to partition the USB flash drive from Windows 7 and that was not supported. I ended up creating a 4MB FAT16 partition on a small USB flash drive and that didn't work. Finally, I used a program called BootIce to create a 1MB FAT16 partition on the same flash drive and at last it was recognized and updated the BIOS.

Installing Easy Peasy

After looking through some choices of netbook optimized distributions, I decided to try Easy Peasy. The interface is tablet like, one maximized window at a time, big icons, easy navigation, etc. I downloaded the ISO and unetbootin to create the USB boot image. The one trick here is to first reformat the USB flash drive partition back to FAT32 for booting. I tried leaving is as FAT16 and it didn't work. When booting, I hit ESC to bring up the boot menu, then chose USB and once it was up, chose to install on the hard drive with default options.

Out of the box, every appears to be working. Wireless networking, suspend/resume, camera, package installation and updates, etc. The online documentation for Easy Peasy seems a bit sparse, and the wiki had some signs of spam vandals, but I an pleased with the choice so far.

Thursday, March 22, 2012

Dusting off nano

For a number of years, nano was my favorite text editor. It was easy, modeless, and had most of the features of you need. If doesn't compete with the heavyweights, vi and emacs, but is simple and elegant.

When I am wearing my programming hat, there are two killer features I need: brace matching and syntax highlighting. I was recently jarred by how much I had come to depend on syntax highlighting when opened a source file on a foreign computer where highlighting was not configured. I thought, how am I supposed to make sense of this? Then I remembered that I didn't always have highlighting and managed to get by.

Anyway, I dug into the current release of nano and found brace matching can be enabled with this .nanorc setting:
set matchbrackets "(<[{)>]}"

A matching brace can be found by putting the cursor on one and using Alt-].

Syntax highlighting has to be defined in the .nanorc file for each type of file. In Red Hat Linux and CentOS, a lot of languages are available to be included in the .nanorc file in /usr/share/nano/. For example,
## Ruby
include "/usr/share/nano/ruby.nanorc"
Go nano!

Tuesday, March 13, 2012

Vi[m] [classic]

While in command mode (case sensitive)

  • move the cursor with arrow keys; if there aren't any arrow keys, use j,k,h,l
  • i - change to insert mode (before cursor)
  • a - change to insert mode (after cursor)
  • A - change to insert mode (at end of line)
  • r - replace one character
  • R - overwrite text
  • x - delete one character
  • dd - delete one line
  • yy - yank line (copy)
  • p - paste deleted or yanked text after cursor
  • P - paste deleted or yanked text before cursor
  • G - go to end of the file
  • 1G - go to top of the file
  • J - merge next line with this one
  • / - search, follow / with text to find
  • :wq - write file and quit
  • :q! - quit without saving
  • :%s/old/new/g - substitute; replace "old" with "new" on all lines
  • :g/pattern/d - delete all lines that match the pattern

While in insert mode

  • ESC - change to command mode
  • any text typed is entered at the cursor

If you gave vi a whirl and don't dig it, give the nano editor a try.