Archive for category Linux

Linux online resize of LVM disk LUN

You’ll start out with a Disk that looks something like this.
# fdisk -l /dev/sdd
Disk /dev/sdd: 598.9 GB, 598925639680 bytes
255 heads, 63 sectors/track, 72815 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdd1 1 72816 584888319+ 8e Linux LVM

Step 1.

grow the LUN on your array

Step 2.

tell the kernel to scan the device for changes
# echo 1 > /sys/block/sdd/device/rescan

you’ll end up with something like this in the logs:
Jul 3 10:10:21 kernel: SCSI device sdd: 2339551264 512-byte hdwr sectors (1197850 MB)
Jul 3 10:10:21 kernel: sdd: Write Protect is off
Jul 3 10:10:21 kernel: SCSI device sdd: drive cache: write back w/ FUA
Jul 3 10:10:21 kernel: sdd: detected capacity change from 598925639680 to 1197850247168

Create a new partition with the newly available space,  Since I want to use all of the space, fdisk will figure out my start cylinder, and end cylinder for me.  I can just take the defaults.  I’ll have to specify the Linux LVM
# fdisk /dev/sdd

Command (m for help): n
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 2
First cylinder (72816-145630, default 72816):
Using default value 72816
Last cylinder or +size or +sizeM or +sizeK (72816-145630, default 145630):
Using default value 145630

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Next we need to make sure the kernel know about the new partition

# partprobe -s /dev/sdd

/dev/sdd: msdos partitions 1 2

After this, we end up with the LUN having two partitions.  We’ll just add the new one to our existing LVM setup.

add the new partition as a physical volume

# pvcreate /dev/sdd2
Physical volume "/dev/sdd2" successfully created
# pvscan
PV /dev/sdd1 VG u02 lvm2 [557.79 GB / 0 free]
PV /dev/sdd2 lvm2 [557.79 GB]
Total: 2 [1.09 TB] / in use: 1 [557.79 GB] / in no VG: 1 [557.79 GB]

extend the volume group with the new physical volume

# vgextend u02 /dev/sdd2
Volume group "u02" successfully extended

extend the logical volume to use all of the free space in the volume group (and as a bonus re-size the EXT3 filesystem that is mounted currently)

# lvextend --resizefs --extents +100%FREE /dev/u02/sun-2540-lun2
Extending logical volume sun-2540-lun2 to 1.09 TB
Logical volume sun-2540-lun2 successfully resized
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/u02-sun--2540--lun2 is mounted on /u02; on-line resizing required
Performing an on-line resize of /dev/mapper/u02-sun--2540--lun2 to 292442112 (4k) blocks.
The filesystem on /dev/mapper/u02-sun--2540--lun2 is now 292442112 blocks long.

And now we’re done!

# df -h /u02
Filesystem Size Used Avail Use% Mounted on
1.1T 224G 819G 22% /u02

No Comments