As noted in a previous article I have been working on a couple new Linux servers with a minimal install of CentOS on them. The /var, /usr, and / directories each were configured with 2GB of space within a logical volume group that has 1TB of space available. I first expanded the /var and /usr directory from 2GB to 20GB and then expanded the root, or /, directory from 2GB to 30GB. Once all three of these directories were expanded I next needed to create a new logical volume group and a partition to hold PostgreSQL data. Use the information below to create a new logical volume, format it with the ext3 file system, mount it, and configure it to be mounted automatically upon the next boot of the server.
List Logical Volume Group Details:
- [root@dev ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sda3
- VG Name VG0
- PV Size 918.87 GB / not usable 28.23 MB
- Allocatable yes
- PE Size (KByte) 32768
- Total PE 29403
- Free PE 4763
- Allocated PE 24640
- PV UUID TooGFc-fffP-hkqs-uEDo-77Q1-QQwc-33EWU0
- [root@dev ~]#
The information above is not accurate because I forgot to note the output of the pvdisplay command before I created the new logical volume but I wanted to include it so you could see how to find out the details of a logical volume group. This way you can determine how much space is left for you to create the new logical volume. Once you decide on the amount of space you want to use for your new logical volume issue a command similar to the below to begin the process.
Create New Logical Volume In Existing Logical Volume Group:
- [root@dev lib]# lvcreate -L 500G -n VG0_pgsql VG0
- Logical volume "VG0_pgsql" created
- [root@dev lib]#
As you can see above we created a new logical volume called VG0_pgsql that is 500GB in size. This reserves 500GB out of the logical volume group for this logical volume. Now use lvscan to list the current logical volumes on the Linux server.
List Logical Volumes On Linux Using lvscan:
- [root@dev lib]# lvscan
- ACTIVE '/dev/VG0/VG0_root' [30.00 GB] inherit
- ACTIVE '/dev/VG0/VG0_usr' [20.00 GB] inherit
- ACTIVE '/dev/VG0/VG0_var' [20.00 GB] inherit
- ACTIVE '/dev/VG0/VG0_pgsql' [500.00 GB] inherit
- [root@dev lib]#
Notice the new logical volume at the end of the list of logical volumes in the example output above. After creating the logical volume you need to format it with the file system of your choice which will likely be ext3. This can be done using the mkfs command as shown below.
Format Logical Volume With EXT3 File System On CentOS Linux:
- [root@dev ~]# mkfs -t ext3 -v /dev/VG0/VG0_pgsql
- mke2fs 1.39 (29-May-2006)
- Filesystem label=
- OS type: Linux
- Block size=1024 (log=0)
- Fragment size=1024 (log=0)
- 131072 inodes, 524288 blocks
- 26214 blocks (5.00%) reserved for the super user
- First data block=1
- Maximum filesystem blocks=67633152
- 64 block groups
- 8192 blocks per group, 8192 fragments per group
- 2048 inodes per group
- Superblock backups stored on blocks:
- 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
- Writing inode tables: done
- Creating journal (16384 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 30 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- [root@dev ~]#
Once the file system has been built the logical volume is now ready to be mounted as a partition. First create the directory where the new partition will be mounted such as something similar to the below example. After creating the directory mount the new partition using the second example command below.
Make A Directory As A Mount Point For New Partition:
- [root@dev ~]# mkdir /mnt/test
Mount New Partition To New Directory On Linux Server:
- [root@dev ~]# mount /dev/VG0/VG0_pgsql /mnt/test
Now the partition should be available to write data to. This can be verified by again issuing the “df -kh” command to show all of the available partitions. Once you have verified the partition is functioning properly you should modify /etc/fstab to make sure the directory is automatically mounted next time the server reboots. The below example line is what would be added to /etc/fstab for the partition created above.
Example fstab Entry For New EXT3 Partition On Linux Server:
- /dev/VG0/VG0_pgsql /mnt/test ext3 defaults 1 2
Save the changes to /etc/fstab and you should now have a fully functional ext3 partition on your Linux server.