I’m adding a new hard disk to an Ubuntu 12.04.3 LTS system that is using LVM2. I had to pull my sources from a few different sites, so I figured I’d post my steps for easier reading later. The short 6-step process boils down to this:
- Add and Scan for the new Physical Volume
echo "- - -" > /sys/class/scsi_host/host#/scan
- Partition the new physical volume for use by LVM (type = 8e)
- Enable the Partition as a Physical Volume in LVM
- Add the new LVM Physical Volume to the Volume Group
vgextend [VGNAME] [PARTITION]
- Extend the Logical Volume to include the new Physical Volume
lvextend -l +100%FREE [LVNAME]
- Extend the Filesystem of the Logical Volume
fsadm resize [LVNAME]
For a deeper explanation, read on!
Add and Scan for the Physical Volume.
If your system is capable of hot-adding storage devices, add your new drive now. If you’re not sure, shut down the machine, add the drive, and start it back up. I’m using VMware ESXi, so I just hot-added the virtual drive. Get root!
sudo su -
Scan for the drive so it shows up in fdisk -l. First, ls the scsi_host to see how many hosts you’ll be scanning.
That will give you the names of the hosts to scan. I had host0, host1, and host2. So my scan for new devices was 3 lines as shown below.
echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan
After the scans complete (this should be fast), fdisk -l and notice your new device name. It’s likely an increment up from your last storage device. In my examples, my new drive is /dev/sdd.
root@.:~# fdisk -l Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 cylinders, total 167772160 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000754c1 Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 167770111 83634177 5 Extended /dev/sda5 501760 167770111 83634176 8e Linux LVM
Disk /dev/sdd: 1099.5 GB, 1099511627776 bytes 173 heads, 2 sectors/track, 6206600 cylinders, total 2147483648 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x5005ed36 Disk /dev/sdd doesn't contain a valid partition table
You’ll see that it “doesn’t contain a valid partition table”. That means it’s time for the next step…
Partition the drive for use by LVM
Keep in mind my new device is /dev/sdd. FDISK is all it takes to partition the drive.
fdisk /dev/sdd n 1 [enter] [enter] t 8e w
Verify the name of the new partition.
root@.:~# fdisk -l Disk /dev/sdd: 1099.5 GB, 1099511627776 bytes 173 heads, 2 sectors/track, 6206600 cylinders, total 2147483648 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x5005ed36 Device Boot Start End Blocks Id System /dev/sdd1 2048 2147483647 1073740800 8e Linux LVM
For me, it’s /dev/sdd1.
Enable the Physical Volume for use in LVM
Take that newly minted partition and add it as a physical volume in LVM.
Add the new LVM Partition to the existing Volume Group
We need to know the VG Name of the Volume Group we’re adding the new partition to. To do this read the output of the vgdisplay command.
root@.:~# vgdisplay --- Volume group --- VG Name storage System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 2.00 TiB PE Size 4.00 MiB Total PE Alloc PE / Size / 2.00 TiB Free PE / Size 0 / 0 VG UUID pCCxdT-RDIB-kVJt-BjNC-TIQX-DE3Y-f0ZHr5
We see in the “VG Name” field that it’s ‘storage’ for my server. You’ll also notice there’s a line for VG Size that’s currently 2 TiB. Let’s fix that!
vgextend storage /dev/sdd1
Type the vgdisplay again to verify the new storage is available to the VG. You’ll probably notice the Free PE / Size output shows the extended amount.
Extend the Logical Volume
We’ve got to make the Logical Volume utilize all the new space available on the Volume Group. For this we need to know the LV Name we’re extending.
root@.:~# lvdisplay --- Logical volume --- LV Name /dev/storage/media VG Name storage LV UUID 4vu0nU-3b9w-9cCD-rpP8-Pm8Z-bgcU-UKsZxE LV Write Access read/write LV Status available # open 1 LV Size 2.00 TiB Current LE 786429 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0
For myself, the LV Name that I’m extending is “/dev/storage/media”.
lvextend -l +100%FREE /dev/storage/media
Expand the Filesystem
The underlying filesystem is still only formatted for the pre-expansion LV size, so we need to tell the filesystem to expand itself to fill. We can do that with fsadm as long as you remember the LV Name from the last step.
fsadm resize /dev/storage/media
By default (without any switches or options) this command resizes to fit 100% of the available free space on the volume. This command may take awhile depending on the size of your new expansion, but when it’s done you’ve got more space on your LVM mount point ready to go!