LVM How-to: Adding a new partition Linux

Initial setup

To begin, let’s define our goals: We have a partition (mounted as /), which we want to extend from 7G to 16G. We will do this by following these steps:

  1. Partition the new disk
  2. Create New Physical Device (pvcreate)
  3. Extend the existing volume group
  4. Extend the logical volume
  5. Extend the filesystem (ext4 in my case)

I am using the Centos 6 release with EXT4 as the filesystem on my virtual machine, but the same steps apply to an EXT3 partition. This is the default layout that centos created for me when I selected the “Use all diskspace and setup LVM” option during the installation:

[email protected]:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
                      7.3G  843M  6.1G  12% /
tmpfs                 502M     0  502M   0% /lib/init/rw
udev                  497M  136K  496M   1% /dev
tmpfs                 502M     0  502M   0% /dev/shm
/dev/sda1             228M   16M  201M   8% /boot

Now we add a new disk to the system. This is done by physically adding a new disk or in my case, by adding a new disk via iSCSI. Using /var/log/messages, we can determine that the new disk is accessible under /dev/sdb. So let’s prepare this new disk…

Prepare new disk

[email protected]:~# fdisk /dev/sdb 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1044, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): 
Using default value 1044

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4fce54ed

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now we have our new partition accessible under /dev/sdb1


next step

mkfs.ext4 /dev/sdb1

Do not forget to add in /etc/fstab


Greetings 🙂

Share Button