Archive for the Tips and Tricks Category

Recently I was trying to do a regular and simple task for a maintenance: extending a LVM partition. But when using the lvextend on that certain logical volume I was greeted with an error:


” Insufficient suitable contiguous allocatable extents for logical volume ”

That was pretty odd, I had recently resized other partitions on that very server and there was nothing “unusual” about its setup: hardware raid, one volume group occupying the entire array and all the logical volumes in that volume group. Googled a bit, but nothing relevant. Then I did what I should have done in the first place: ran the command lvscan to show me some details about the logical volumes.

I noticed that the partition I wanted to extend was different from the others: it had as allocation policy ” contiguous ” instead of ” inherit ” like all the others. The manual for LVM ( man 8 lvm ) provides us with all the answers:

” The default for a logical volume is inherit which applies the same policy as for the volume group. ”
” The contiguous policy requires that new extents be placed adjacent to existing extents. ”

So my partition could be extended just by using free space on the drive that was next to it. And there wasn’t any because there were other partitions created after it. Someone had created – for unknown and illogical reasons in our case – the partition with a ” contiguous ” allocation policy.

So this was an easy fix: lvchange –alloc inherit [lv]

Then I could extend my partition easily. The moral of the story: be careful when creating LVM partitions and volume groups to assign them their allocation policy in line with your needs and setup.

More Vim tips

| November 2nd, 2009

I will continue my previous post with another few Vim tips I recently found in my quest to improve my Vim experience!

1) For those of you annoyed by the auto-comment feature of Vim (the feature that automatically inserts a comment leader in front of a line after your previous line was also commented), just enter this:

:set fo-=r

2) If you are like me and like to use Ctrl+E and Ctrl+A in your command line and want to also use this in Vim, here is a simple way to map end of line and beginning of line to Ctrl+E and Ctrl+A in Vim:

” map CTRL-E to end-of-line (insert mode)
imap $i
” map CTRL-A to beginning-of-line (insert mode)
imap 0i
” map CTRL-E to end-of-line (normal mode)
nmap $
” map CTRL-A to beginning-of-line (normal mode)
nmap 0

3) This is for the lazy ones or the ones that just can not get adjusted to Vim’s shortcuts, here is a trick to map Ctrl+C to copy to clipboard, Ctrl+V to paste and Ctrl+X to cut:

” map CTRL-C to copy (visual mode)
vmap y
” map CTRL-X to cut (visual mode)
vmap x
” map CTRL-V to paste (insert mode)
imap P

Add them to your .vimrc and that’s it!

Vim tips for the Windows user

| October 28th, 2009

If you are like me and want or are forced to use Windows on your desktop or laptop you most probably use putty to ssh into your servers. And also do a lot of copy / paste when editing files with vim. So you probably have noticed that when pasting in vim using right-click in putty (or any other way, doesn’t really matter) vim introduces a lot of white spaces, or transforms your tabs into white spaces or does crazy indenting in general. There are a few tips to work-around this.

1) enter command mode ( using : ) and type:

:set noautoindent

This will stop vim from messing your whole hard-worked indenting, but will not solve your white spaces problem, for this go to tip number 2.

If you want to go back to writing code with vim’s help with indenting type:

:set autoindent

2) enter command mode ( using : ) and type:

:set paste

This enables vim’s “paste mode” and will allow you to paste lines that are already indented without any modifications (tabs to white-spaces) or re-indenting .

To exit this mode type:

:set nopaste

But what if you already have a file with lots of lines that was already messed with and saved to disk. Well there is a way to solve this in tip number three:

3) Go into Visual mode ( by pressing the key “v”) and select the whole text (or just the lines you want fixed) using the arrow keys (left / right selects through a line, up / down selects or unselects whole lines) and when you are done just press the “=” key and vim will solve your indenting for you.

That’s it! Hope now your vim-ing experience will be a much better one!