Logical Volume Manager Cheatsheet

Today I got a new harddisk, so it was finally time for me to have an in depth look at LVM. I use it to combine two harddisks /dev/sdg1 and /dev/sdb1 into one volume group ext_vg which contains one big logical volume /dev/ext_vg/ext. In short, my 250GB and 500GB harddisks are used in one big 750GB ext3 mount point.

I followed the excellent LVM Tutorial, and was surprised how easy everything goes. Here is a short cheat sheet of the important commands (take care to exchange the partition/volume names if you use this):

Installation

I use Ubuntu, so this is a piece of cake:

sudo apt-get install lvm2

There is also a GUI available, but I found the command line tools are very easy to use so there is no real need. I wouldn’t use EVMS as it is not supported in Ubuntu 7.10 and may cause problems.

Create a New Filesystem

First I create the physical volume on the partition sdg1, create a new volume group ext_vg that contains this physical volume, and create a new logical volume of size 450GB within the volume group. Finally create the filesystem (disabled reservation space, see Get More Space Out of Your ext3 Partition).

sudo pvcreate /dev/sdg1
sudo vgcreate ext_vg /dev/sdg1
sudo lvcreate -L 450G -n ext ext_vg
sudo mkfs.ext3 -m 0 /dev/ext_vg/ext

Show Status

Each LVM layer has its corresponding command to get information about the metadata:

sudo pvdisplay
sudo vgdisplay
sudo lvdisplay
sudo pvs
sudo vgs
sudo lvs

Mount via fstab

I use the filesystem mainly for data, so allowing just rw is enough (no executables allowed). noatime allows quicker access.

sudo mkdir /media/mega
/dev/ext_vg/ext /media/mega     ext3    rw,noatime,user 0       2
mount /media/mega

Resize

It is even possible to do an online resize of the system, wohoo :-) This extends the logical volume by 200MB.

sudo lvextend -L +200 /dev/ext_vg/ext
sudo resize2fs -p /dev/ext_vg/ext

You can watch the resize process going on with df -h.

Add Another Partition to the Logical Volume

To add another partition and use up all the available space in the logical volume, first add the physical volume to the volume group, then use pvdisplay to find out the total available number of free PE (add the numbers from the physical volumes), then use lvextend to use up all this available space.

sudo pvcreate /dev/sdb1
sudo vgextend ext_vg /dev/sdb1
sudo pvdisplay
sudo lvextend -l +63602 /dev/ext_vg/ext
sudo resize2fs /dev/ext_vg/ext

That’s it! Any questions? please post.

Howto Get Enough Sleep Despite StumbleUpon with Ubuntu

What?

I am a long-term StumbleUpon user, which means that I don’t get much sleep. Now, after almost 4 years of stumbling, I have decided to get my life back. Well, at least some sleep!

What does this do?

Every night when I have to work on the next day (Sunday night to Thursday night ), at 23:25 my computer shows me this little warning message:

go to bed warning

After the 5 minutes have passed, the computer shuts itself automatically down.

I use this little trick with Ubuntu, but it should work anywhere where Gnome is installed.

How?

Thanks to the power of Linux, this is not difficult to do for yourself, and configure it however you want it to behave:

  1. Open /etc/crontab with your favourite text editor (no need for crontab -e since this is the system wide crontab), e.g.
    sudo gedit /etc/crontab
  2. Add the following lines (replace manker with your username!)
    25 23 * * 0-4   manker  /usr/bin/zenity --display :0 --warning --text="Shutdown in 5 minutes. Go to bed."
    25 23 * * 0-4   root    shutdown -h +5
  3. The first part of both lines 25 23 * * 0-4 means that the commands are executed at 23:25, but only Sunday (day 0) to Thursday (day 4). Read man 5 crontab for a detailed description of that format.
  4. The first command uses zenity to show a warning message. You have to execute this as the same user that you use for working, or you will not see the message, so change manker to your username (root does not work either).
  5. The second command shutdown -h +5 means that the computer will halt in 5 minutes. This has to be run as root, and it also shows nice warning messages in all your open terminals so you can’t really miss it.
  6. Save the file, and stumble until it is 23:25.

Sweet dreams!

Get More Space Out of Your ext3 Partition

I have just discovered that ext3 defaults to reserving 5% of its partition exclusively for root, as a precaution measure that your system does not get FUBAR when you use it for your root partition. I have a 230GB external USB disk that I use for all my big storage requirements, downloaded stuff, backups etc. Due to this reservation I had 11.5GB of unusable disk space, thankfully this is easy to fix:

tune2fs -m 0 /dev/sdf1

Replace sdf1 with your partition name. You don’t even have to unmount your disk. Voilá, 11.5 GB more space for free :-) Here is the output of df -h as proof:

Before:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sdf1             230G  193G   26G  89% /media/disk

After:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sdf1             230G  193G   38G  84% /media/disk

If you like this, you might also be interested in How to change Ubuntu forced fsck.

Update: The free space limitation is also used to prevent fragmentation. So if you set the limit to zero and operate on a very full harddisk for a while, your filesystem might slow down.

Major Clearlooks Compact Update

The Clearlooks Compact theme was released just a few days ago, and it already is the highest rated theme at gnome-look.org, out of more than a thousand. I guess the compactness really hit the nerve of lots of Linux users.

This encouraged me to do some further updates, I have incorporated lots of several tips and from the post “Making Eclipse look good on Linux“. The result is a very compact theme that does not waste space if possible.

Hope you like it as much as I do

Compact Theme Update

Compact theme just got more compact, now it switches to 16×16 icons which saves quite a bit of space for the buttons. More info here.

Next Page →