====== Linux resize a disk with or without LVM ======
===== Disk without partitions =====
Find the paths to the LUN:
# multipath -ll
[...]
mpathc (200255c3a11080003) dm-38 NEC,DISK ARRAY
size=120G features='1 queue_if_no_path' hwhandler='1 alua' wp=rw
|-+- policy='round-robin 0' prio=50 status=active
| |- 1:0:2:0 sdm 65:32 active ready running
| `- 2:0:2:0 sdo 65:64 active ready running
`-+- policy='round-robin 0' prio=10 status=enabled
|- 1:0:3:0 sdn 65:16 active ready running
`- 2:0:3:0 sdp 65:48 active ready running
Rescan the paths:
# echo 1 > /sys/block/sdm/device/rescan
# echo 1 > /sys/block/sdo/device/rescan
# echo 1 > /sys/block/sdn/device/rescan
# echo 1 > /sys/block/sdp/device/rescan
# Resize the multipath device:
# multipathd -k 'resize map mpathc'
Now if you have an unpartitionned disk, just rezise the pv and vg
# partprobe -s
# pvresize /dev/mpathc
# vgresize myvg
Else use one of the next steps
===== Disk with partitions =====
==== Add a new partition on the disk ====
**This is the most safe way**
# fdisk /dev/mpathc
The number of cylinders for this disk is set to 2480.
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/mpathc: 20.4 GB, 20401094656 bytes
255 heads, 63 sectors/track, 2480 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/mpathc1 * 1 33 265041 83 Linux
/dev/mpathc2 34 1958 15462562+ 8e Linux LVM
# Let's create a new partition. In our case, we'll create partition # 3
# (primary Linux LVM partition). For the first and last cylinder usually default values
# will be ok; if not, choose carefully the beginning and the end of the new partition to
# avoid
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1959-2480, default 1959):
Using default value 1959
Last cylinder or +size or +sizeM or +sizeK (1959-2480, default 2480):
Using default value 2480
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 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.
Rescan disks
# partprobe -s
If you get a warning: Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdc (Device or resource busy).
As a result, it may not reflect all of your changes until after reboot.
The use following command instead:
# partx -a /dev/mpathc
Then you can add the new partition to the VG
# vgextend myvg /dev/mpathc3
==== How to use growpart to resize your partition online (disk) ====
The syntax is:
growpart /dev/DEVICE_NAME PARTITION_NUMBER
growpart is part of the package **cloud-utils-growpart**
Please note that there is a space between the DEVICE_NAME and the PARTITION_NUMBER. For example:
# growpart --dry-run /dev/sdb 1
CHANGE: partition=1 start=2048 old: size=419428352 end=419430400 new: size=838858719,end=838860767
# === old sfdisk -d ===
label: dos
label-id: 0xd3a4f1f7
device: /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size= 419428352, type=83
# === new sfdisk -d ===
label: dos
label-id: 0xd3a4f1f7
device: /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size= 838858719, type=83
To apply the change:
# growpart /dev/sdb 1
CHANGE: partition=1 start=2048 old: size=419428352 end=419430400 new: size=838858719,end=838860767
==== increase partition size online (disk) ====
:!: Can be dangerous !
1. delete partition table
fdisk /dev/sdb
d
w
2. recreate partition table
fdisk /dev/sdb
n
1
enter
p
enter
t
8e (for LVM)
w
3. rescan
rescan-scsi-bus.sh
4.
kpartx -av /dev/mapper/sdb1
5. resize PV
resizepv /dev/sdb1
==== increase partition size online (disk) ====
You must resize the LVM physical volume after you have reduced the partition on the filesystem with fdisk.
I have not the possibility to confirm the exact steps right now, so you should get someone to review the steps before you perform them.
In case something goes wrong, make sure you have your data backed up.
2. Resize the filesystem
resize2fs -p /dev/VolGroup00/LogVol00 50GB
3. Resize the logical volume
lvresize -L50G /dev/VolGroup/LogVol00
4. Backup partition table
sfdisk -d /dev/sda > /var/tmp/partition-table.txt
5. Delete /dev/sda2 partition
Use fdisk to delete the partition /dev/sda2
6. Create a new /dev/sda2 partition
Create a new partion with the exact same starting offset as your former partition (this should be default) and make it only 50G
7. Resize the LVM Physical Volume
pvresize /dev/sda2