Thursday, January 24, 2008

What's that line in /proc/mounts?

When I view the /proc/mounts file, the first line looks like:
rootfs / rootfs rw 0 0
I found myself wondering what this line was. Today I figured it out.

My first thought was that this is my mounted / directory, however, this is not the case. My mounted / directory appears in /proc/mounts as:
/dev/root / ext3 rw,data=ordered 0 0

The first line is actually the initial ram disk (initrd). When the system boots up, this initial ram disk is mounted as the root filesystem. Many Linux systems then just mount the actual root filesystem over top of that. I found this page, http://lwn.net/Articles/156098/, to be very helpful in explaining this.

How to add disk space with LVM on Linux

I have often had the need to add disk space to a server. The newer distributions of Linux (SUSE Linux Enterprise Server - "SLES" 9 and greater, Red Hat Enterprise Linux - "RHEL" 4 and greater) use Logical Volume Manager (LVM) which makes this a fairly simple task.
The general steps are:
  1. Physically put the disk in the server and make it available either in an array or some other way.
  2. Use fdisk to create new partition on the disk.
  3. Extend existing volume group onto new partition.
  4. Extend existing logical volume onto new space.
  5. Extend filesystem.
I'll go into more detail how to do each of these steps on SLES and RHEL. For this example we are going to assume that our new disk that has been added to our server is /dev/sdc. We will also assume that we have a volume group named rootvg and a logical volume on that volume group named homelv. Also in this example, /dev/rootvg/homelv is mounted on our Linux system as /home. Let's get started.
  1. Physically put the disk in the server and make it available either in an array or some other way.
    • This can vary widely depending on what hardware you are on, so we will not cover this portion in this tutorial. You may want to use Google to search for how to do this on your hardware.
  2. Use fdisk to create new partition on the disk.
    • As root run fdisk on the new disk. For example you would run fdisk /dev/sdc.
    • On this new disk you will create a new partition. Inside of the fdisk program you create a new partition by typing the letter "n" followed by the enter key.
    • It will then ask you if you want it to be a primary partition or an extended partition. For this example we will just assume we want it to be a primary partition. To do this we type the letter "p" followed by the enter key.
    • Next it will ask for the starting point and ending point of this partition. For this example, we will simply select the defaults by hitting the enter key twice.
    • If you want to view the details of the new partition, you can type the letter "p" from the fdisk prompt.
    • Next we need to change the type for this new partition. We do this by typing the letter "t" followed by the enter key.
    • It asks to enter in what type we want it to be. We need it to be of the Linux LVM type. The Hex code for Linux LVM is 8e. We type in "8e" followed by the enter key and it will tell us that it changed the system type for this partition to Linux LVM.
    • We then need to save these changes and exit fdisk. We do this by typing the letter "w" (for write) followed by the enter key.
  3. Use pvcreate to lay down the "setup" on the physical partition.
    • This sets up physical extents and other things that LVM needs. The command we run is "pvcreate /dev/sdc1"
  4. Extend existing volume group onto new partition.
    • For this example we are going to assume that we have an existing volume group named rootvg. We can display information about this volume group using the vgdisplay command. If we type "vgdisplay" without any arguments, it will display all the volume groups. If we just want information about the "rootvg" volume group, we would type "vgdisplay rootvg".
    • To extend the rootvg volume group onto the new partition, we use the vgextend command. Type "vgextend rootvg /dev/sdc1" followed by the enter key. This will extend the rootvg volume group onto the new partition, /dev/sdc1.
  5. Extend existing logical volume onto new space.
    • For this example we are going to assume that we have an existing logical volume on the rootvg volume group that is named homelv. The full path to this logical volume would be "/dev/rootvg/homelv". We can view information about this logical volume by typing "lvdisplay /dev/rootvg/homelv".
    • To extend this existing logical volume onto the new space we use the lvextend command. Type "lvextend -L +20G /dev/rootvg/homelv /dev/sdc1". This command says that we want to increase the /dev/rootvg/homelv logical volume by 20GB. This is only possible if /dev/sdc1 is a member of volume group rootvg and there is enough free disk space on it.
  6. The last thing we need to do is increase the filesystem.
    • Which command we use to increase the filesystem depends on what filesystem type we are currently using. If we are using reiserfs, we will use the "resize_reiserfs" command. If we are using ext3, we will use either the "ext2online" or the "resize2fs" command. On RHEL 5, we can use the "resize2fs" command, which will recognize that the filesystem is currently mounted and perform an "on-line" resize.
    • On both resize_reiserfs and ext2online, the size is optional. If we want the filesystem to take up all the available space on our logical volume, we don't need to put the size. To extend the filesystem type either "ext2online /dev/rootvg/homelv" or "resize_reiserfs /dev/rootvg/homelv".
You should now be able to run "df -h" and see the additional disk space available in the /home directory.