-
Configuring drive space on a Linux box with/without LVM
Configuring drive space on a Linux box
This document walks through creating new drive space on a Linux box using either physical drives or SAN LUN's.
Step one is to physically connect the new drive to the server. Since there are several ways of doing so, this document will assume this is already complete.
NOTE: everything that you have to type at the command line is italicized and bold for reference.
Following the general rule, all drives will show up as /dev/controller/device.
For example: /dev/cciss/c0d0 would be the first drive (d0) on the first controller (c0) on the controller labeled “cciss”.
Other examples would be:
/dev/hda, /dev/hdb for the first and second IDE drives.
/dev/sda, /dev/sdb for the first and second SCSI drives. This is where SAN LUN's appear.
NOTE: these are drive assignments, not partitions--sda refers to the entire drive. Partitions are refered to with numbers as sda1, sda2, etc.
NOTE: This document does not address permissioning of this new space.
Read each Scenario carefully as you will most likely need only one set of instructions.
Scenario 1: This will be to simply mount the entire contents of the new drive (/dev/sdb) to a mount point (/newdrive). This is also the method for mounting only a portion of the drive...simply create partitions of the correct size and mount them as follows, remembering that each partition will be labeled /dev/sdb1, sdb2, sdb3, etc., etc.
NOTE: in this scenario, we will assume our new drive is /dev/sdb.
NOTE: you can only have 4 primary partitions! You can have additional partitions but they will be extended partitions. If you create extended partitions, there is normally no partition 4, since partition 4 will contain all the extended partitions, but itself is not addressable. This partition number (4) can actually be 1,2,3 or 4, but is typically 4.
Using your favorite partitioning tool, create your partitions. Here we use fdisk:
# fdisk /dev/sdb
From the partitioning menu's, create a new partition of whatever size you need (in our case the full amount).
Change the partitions system ID from its default to 83 (a simple Linux partition).
Save and exit the fdisk utility by pressing w.
There are some situations that require a reboot for the partition table to be updated. Exiting the fdisk utility will let you know if you need to reboot.
Now we need to format the new partition. There are several ways to do this, depending on the type of file system you want (ext3, ext2, Rieser, etc). We will use the mke2fs command, using the -j option to make an ext3 file system.
# mke2fs -j /dev/sdb1 Note here we format the partition sdb1, not the drive sdb.
There are many options to the mke2fs command, but the above line is all we usually need.
Now that the partition is formatted, we can mount that to our newly created folder:
# mkdir /newdrive
# mount -t ext3 /dev/sdb1 /newdrive
To mount it at boot time, edit the /etc/fstab file as follows:
/dev/sdb1 /newdrive ext3 default 0 0
and enjoy your new space!
NOTE: Since we are not covering permissoins, you will need additional information to allow others to read/write to this space.
Scenario 2: In this scenario, we will create logical volumes out of our new drive. This will give us the flexibility to grow or shrink these volumes in the future. It will also limit any one folder from filling up the entire drive.
Again, connect your new drive as before. In this example, we will use /dev/cciss/c0d1 as our new device, and assume that it is a 72Gig drive. We will create 2 volumes for practice.
Create a partition on the new drive
# fdisk /dev/cciss/c0d1
From the partitioning menu's, create a new partition spanning the entire drive.
Change the partitions system ID from its default to 8e (a Linux LV).
Save and exit the fdisk utility by pressing w.
Now we need to create a physical volume on that partition
# pvcreate -v /dev/cciss/c0d1p1
This prepares the new partition for logical volumes.
Now we will create a volume group, that later we can add additional drives to.
NOTE: in the following example, I use vg01, assuming that vg00 is being used by the system (the OS). vg01 would be the next logical name, and is my standard, however, any name is technically acceptable.
# vgcreate vg01 -v /dev/cciss/c0d1p1
This creates vg01 and adds our new partition to it.
Type vgdisplay vg01 at the # prompt and make note of the Alloc PE / Size and Free PE / Size values.
Next we start creating logical volumes. These are similar to partitions, but offers resizing abilities since they are not tied to physical mappings on the drive.
NOTE: again, we are building a logical volume out of a piece of vg01, which we created earlier. In the example, we are creating a 20Gig volume and calling it lvsales, and will assign this to the /sales folder. We will also create a 50Gig volume for our mp3s.
# lvcreate vg01 -v -L 20G -n lvsales
# lvcreate vg01 -v -L 50G -n lvmp3s
Type vgdisplay vg01 again and compare the values to the previous output. Do you see about 70Gigs missing from the Free PE / Size entry?
Now that we have our 2 logical volumes, we need to format them as we would any new partition:
# mke2fs -j /dev/vg01/lvsales
# mke2fs -j /dev/vg01/lvmp3s
Notice the path to the new volume? /dev/volumegroupname/logicalvolumename
Create our new folders and mount our new space to them:
# mkdir /sales
# mkdir /mp3s
# mount /dev/vg01/lvsales /sales
# mount /dev/vg01/lvmp3s /mp3s
A verbose vgdisplay will give you all the info about your volume groups and logical volumes:
# vgdisplay -v vg01 (you may have to scroll up to see all the info)
Scenario 3: As is the norm, the sales department has outgrown their space, so in this example, we will add a new drive, and then grow the now existing lvsales logical volume by 20Gigs.
NOTE: This process is sometimes destructive!! Always perform quality backups prior to any changes to volumes or partition sizes!!!
Again, we add the new drives or LUN's per other documentation and boot up our server. We will assume we have added an additional 72Gig drive, as the first 72Gig drive was carved up into a sales volume and an mp3 volume and is now full. This will populate at /dev/cciss/c0d2 (NOTE the 2!)
We cannot resize a mounted partition, so we first unmount the sales folder, which will obviously take the data offline during this process. It is sometimes possible to extend these volumes without unmounting them, but that is not covered here.
# umount /sales
Now, lets walk through creating the new space:
Create a partition on the new drive
# fdisk /dev/cciss/c0d2
From the partitioning menu's, create a new partition spanning the entire drive.
Change the partitions system ID from its default to 8e (a Linux LV).
Save and exit the fdisk utility by pressing w.
Now we need to create a physical volume on that partition
# pvcreate -v /dev/cciss/c0d2p1
This prepares the new partition for logical volumes.
Here is the deviation from the previous scenario:
We need to extend the existing volume group (vg01) to include this new physical volume.
# vgextend -v vg01 /dev/cciss/c0d2p1
A vgdipslay -v vg01 command should now show a lot more Free PE / Size to it. Since we max’d out vg01 in the previous scenario, there should be around 72Gigs free since that is the size of the space we just added.
We now need to stretch our filesystem over our new space:
(we are sometimes forced to check out the filesystem first. Do so with:
# e2fsck –f /dev/vg01/lvsales)
Now that our vg01 contains more formated free space, let’s extend the lvsales volume by another 20Gigs.
# lvextend -v -L +20G /dev/vg01/lvsales
Now that the logical volume has been extended, we need to stretch filesystem (or format) across the new space:
# resize2fs /dev/vg01/lvsales
The above command has some options to it, however, with non indicated, resize2fs assume’s the entire space.
A quick vgdisplay –v command will show you the new space assigned to lvsales.
# mount -a will remount all the file systems in the /etc/fstab, including our /sales folder.
# df -h will list all the directory size's and free space. Our sales folder should now be 40Gigs in size and have 20Gigs free.
# vgdisplay –v vg01 should also report 20Gigs missing out of vg01, leaving around 50Gigs available (or Free).
Last edited by happybunny; 10-12-2005 at 09:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|