Online resize of an iSCSI multipath device with GPT partition. Requires no server restart, but the partition needs to be unmounted and not in use.
The Procedure
- Resize the LUN on a SAN,
- Rescan devices and reload multipath,
- multipath -ll show correct size,
- parted – recreate the partition,
- partprobe – inform the OS of partition table changes,
- e2fsck – check the ext4 filesystem before resizing,
- resize2fs – resize the ext4 filesystem.
Before Resizing the LUN on a SAN
Grab some data. Our multipath device is mpatham and has a size of 20GB. We will extend it by 10GB to 30GB total.
# multipath -ll mpatham mpatham (36000eb3959dd493f000000000001c3db) dm-77 LEFTHAND,iSCSIDisk size=20G features='0' hwhandler='0' wp=rw `-+- policy='round-robin 0' prio=1 status=active |- 93:0:0:0 sdbt 68:112 active ready running `- 94:0:0:0 sdbu 68:128 active ready running
# parted /dev/mapper/mpatham print Model: Linux device-mapper (multipath) (dm) Disk /dev/mapper/mpatham: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 21.5GB 21.5GB ext4 primary
# blockdev --getsz /dev/mapper/mpatham 41943040 # blockdev --getsz /dev/mapper/mpathamp1 41940959
# blockdev --getsz /dev/sdbt 41943040 # blockdev --getsz /dev/sdbt1 41940959
# blockdev --getsz /dev/sdbu 41943040 # blockdev --getsz /dev/sdbu1 41940959
# df -h|egrep "File|mpathamp1|data" Filesystem Size Used Avail Use% Mounted on /dev/mapper/mpathamp1 20G 142M 20G 1% /data
After Resizing the LUN on a SAN
Parted
You should have parted installed on your CentOS 6 system already. Run the following if it’s not the case:
# yum install parted
Rescan Devices
You can rescan the sdbt and the sdbu devices, or you can rescan all running sessions.
Rescan the devices:
# echo 1 > /sys/block/sdbt/device/rescan # echo 1 > /sys/block/sdbu/device/rescan
Alternatively, rescan all running sessions:
# iscsiadm -m session --rescan
Note that if you are creating a new device rather than extending an existing one, then you may need to scan the SAN and login to all discovered targets:
# iscsiadm -m discovery -t sendtargets -p netappsan.local:3260 # iscsiadm -m node -L automatic
Reload the multipath service to pick up the new size:
# /etc/init.d/multipathd reload
The multipath device size is 30GB.
# multipath -ll mpatham mpatham (36000eb3959dd493f000000000001c3db) dm-77 LEFTHAND,iSCSIDisk size=30G features='0' hwhandler='0' wp=rw `-+- policy='round-robin 0' prio=1 status=active |- 93:0:0:0 sdbt 68:112 active ready running `- 94:0:0:0 sdbu 68:128 active ready running
# blockdev --getsz /dev/mapper/mpatham 62914560 # blockdev --getsz /dev/mapper/mpathamp1 41940959
# blockdev --getsz /dev/sdbt 62914560 # blockdev --getsz /dev/sdbt1 41940959
# blockdev --getsz /dev/sdbu 62914560 # blockdev --getsz /dev/sdbu1 41940959
Recreate the GPT Partition
Make sure the multipath device is not mounted:
# umount /dev/mapper/mpathamp1
Run parted on the multipath device:
# parted /dev/mapper/mpatham GNU Parted 2.1 Using /dev/mapper/mpatham Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)? Fix/Ignore/Cancel? Fix Warning: Not all of the space available to /dev/mapper/mpatham appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current setting? Fix/Ignore? Fix Model: Linux device-mapper (multipath) (dm) Disk /dev/mapper/mpatham: 32.2GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 21.5GB 21.5GB ext4 primary (parted) rm 1 (parted) unit Kb (parted) mkpart primary ext4 1049 -1 Warning: You requested a partition from 1049kB to 32212254kB. The closest location we can manage is 1049kB to 32212237kB. Is this still acceptable to you? Yes/No? Yes (parted) p Model: Linux device-mapper (multipath) (dm) Disk /dev/mapper/mpatham: 32212255kB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 32212238kB 32211189kB ext4 primary (parted) q
Reload the Partition Table and Resize the Filesystem
Tell the kernel to reload the partition table. Note that in RHEL 6, partprobe will only trigger the OS to update the partitions on a disk that none of its partitions are in use. If any partition on a disk is in use, partprobe will not trigger the OS to update partitions in the system because it is considered unsafe in some situations.
# partprobe
Check the filesystem before resizing:
# e2fsck -f /dev/mapper/mpathamp1 e2fsck 1.41.12 (17-May-2010) 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/mapper/mpathamp1: 11/1310720 files (0.0% non-contiguous), 118545/5242619 blocks
Resize the filesystem:
# resize2fs /dev/mapper/mpathamp1 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/mpathamp1 to 7864059 (4k) blocks. The filesystem on /dev/mapper/mpathamp1 is now 7864059 blocks long.
Grab some data:
# blockdev --getsz /dev/mapper/mpatham 62914560 # blockdev --getsz /dev/mapper/mpathamp1 62912479
# blockdev --getsz /dev/sdbt 62914560 # blockdev --getsz /dev/sdbt1 62912479
# blockdev --getsz /dev/sdbu 62914560 # blockdev --getsz /dev/sdbu1 62912479
Finally, mount the partition:
# mount /dev/mapper/mpathamp1 /data/
# df -h|egrep "File|mpathamp1|data" Filesystem Size Used Avail Use% Mounted on /dev/mapper/mpathamp1 30G 142M 30G 1% /data
Perfect, thanks.
Maybe should be noted that no data will survive this. For online size increase use parted and its resizepart command.
We are not formatting the disk, therefore all data will stay intact.