Expanding an existing LV (logical volume)
In this case we are adding a physical drive to the system. The drive will be used to extend the logical volume /sctratch in the vg (volume group) Ubuntu.
- Start by finding the available disk:
cdelacruz@puck:/$ cat /proc/partitions major minor #blocks name 8 0 244140625 sda 8 1 1 sda1 8 5 192717 sda5 8 6 243946993 sda6 8 16 244140625 sdb 8 17 244131741 sdb1 254 0 1024000 dm-0 254 1 1024000 dm-1 254 2 4096000 dm-2 254 3 4096000 dm-3 254 4 227508224 dm-4 254 5 6197248 dm-5 254 6 243946993 dm-6 254 7 1024000 dm-7 254 8 1024000 dm-8 254 9 227508224 dm-9 254 10 6197248 dm-10 254 11 4096000 dm-11 254 12 4096000 dm-12 254 13 192717 dm-13 254 14 244131741 dm-14
- Partition the disk to be added, in this case it is the second SATA drive labeled sdb:
cdelacruz@puck:/$ sudo fdisk /dev/sdb
- Select 'p' to print existing table information:
The number of cylinders for this disk is set to 30394. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sdb: 250.0 GB, 250000000000 bytes 255 heads, 63 sectors/track, 30394 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 30393 244131741 7 HPFS/NTFS
- Select 'd' to delete existing NTFS partition:
Command (m for help): d Selected partition 1 Command (m for help): p Disk /dev/sdb: 250.0 GB, 250000000000 bytes 255 heads, 63 sectors/track, 30394 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
- Select 'n' to create a new partition:
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-30394, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-30394, default 30394): Using default value 30394
- Select 't' to change partition system ID to 8e (Linux LVM):
Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 250.0 GB, 250000000000 bytes 255 heads, 63 sectors/track, 30394 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 30394 244139773+ 8e Linux LVM
- Select 'w' to write the new table to disk:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
- Create the physical volume:
sudo pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created To see the physical volumes and volume group: cdelacruz@puck:/$ sudo pvscan PV /dev/sda6 VG Ubuntu lvm2 [232.64 GB / 0 free] PV /dev/evms/sdb1 lvm2 [232.83 GB] Total: 2 [465.47 GB] / in use: 1 [232.64 GB] / in no VG: 1 [232.83 GB] cdelacruz@puck:/$ sudo vgs VG #PV #LV #SN Attr VSize VFree Ubuntu 1 6 0 wz--n- 232.64G 0
- Add the physical volume to the VG (Ubuntu in this case):
sudo vgextend Ubuntu /dev/evms/sdb1
- Resize the logical volume:
Use the lvs command to check the logical volumes: cdelacruz@puck:/$ sudo lvs LV VG Attr LSize Origin Snap% Move Log Copy% home Ubuntu -wi-ao 1000.00M root Ubuntu -wi-ao 1000.00M scratch Ubuntu -wi-ao 216.97G swap_1 Ubuntu -wi-ao 5.91G usr Ubuntu -wi-ao 3.91G var Ubuntu -wi-ao 3.91G cdelacruz@puck:/$ Unmount the file system to be modified, in this case we are extending the /scratch lv (logical volume) cdelacruz@puck:/$ sudo umount /dev/Ubuntu/scratch sudo lvs: scratch Ubuntu -wi-a- 216.97G * note the missing 'o' attribute, indicating the device is not open. cdelacruz@puck:/$ sudo pvs PV VG Fmt Attr PSize PFree /dev/evms/sdb1 Ubuntu lvm2 a- 232.83G 232.83G /dev/sda6 Ubuntu lvm2 a- 232.64G 0 * Extend the lv: cdelacruz@puck:/$ sudo lvresize -L +220G /dev/Ubuntu/scratch Extending logical volume scratch to 436.97 GB Logical volume scratch successfully resized * fsck the filesystem: cdelacruz@puck:/$ sudo e2fsck -f /dev/Ubuntu/scratch e2fsck 1.38 (30-Jun-2005) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/Ubuntu/scratch: 80/28442624 files (0.0% non-contiguous), 925380/56877056 blocks * Resize the filesystem: cdelacruz@puck:/$ sudo resize2fs /dev/Ubuntu/scratch resize2fs 1.38 (30-Jun-2005) Resizing the filesystem on /dev/Ubuntu/scratch to 114548736 (4k) blocks. The filesystem on /dev/Ubuntu/scratch is now 114548736 blocks long.
- Verify new size:
cdelacruz@puck:/$ sudo lvs LV VG Attr LSize Origin Snap% Move Log Copy% home Ubuntu -wi-ao 1000.00M root Ubuntu -wi-ao 1000.00M scratch Ubuntu -wi-a- 436.97G swap_1 Ubuntu -wi-ao 5.91G usr Ubuntu -wi-ao 3.91G var Ubuntu -wi-ao 3.91G
