after extend the LUN size , sometimes we need to extend the partition before resize the filesystem .
we give an example how to extend the disk partition . now we try to extend the /dev/sdb1
1. the current size (10000000 - 2048) sectors , but the /dev/sdb total has 20971520 sectors , now we need to extend the sectors to 20971520
Suse:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 38G 20G 17G 55% /
udev 934M 132K 933M 1% /dev
tmpfs 934M 720K 933M 1% /dev/shm
/dev/sdb1 4.7G 138M 4.4G 4% /new
Suse :~ # fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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: 0x000598d9
Device Boot Start End Blocks Id System
/dev/sda1 2048 4208639 2103296 82 Linux swap / Solaris
/dev/sda2 * 4208640 83886079 39838720 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
121 heads, 11 sectors/track, 15756 cylinders, total 20971520 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: 0x577ef331
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10000000 4998976+ 83 Linux
2. change the /dev/sdb1 to 20971520 sectors
Suse :~ # fdisk /dev/sdb
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
Suse:~ # fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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: 0x000598d9
Device Boot Start End Blocks Id System
/dev/sda1 2048 4208639 2103296 82 Linux swap / Solaris
/dev/sda2 * 4208640 83886079 39838720 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
26 heads, 9 sectors/track, 89621 cylinders, total 20971520 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: 0x577ef331
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux
as we can see , the current sectors already extend 20971219 , but it doesn't take effect . we need to reboot the server or run "partprobe" command to refresh the disk .
Suse:~ # partprobe /dev/sdb
after the above operation , we can resize the filesystem .
Suse :~ # resize2fs /dev/sdb1
resize2fs 1.41.9 (22-Aug-2009)
Resizing the filesystem on /dev/sdb1 to 2621184 (4k) blocks.
The filesystem on /dev/sdb1 is now 2621184 blocks long.
Suse:~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 38G 20G 17G 55% /
udev 934M 132K 933M 1% /dev
tmpfs 934M 720K 933M 1% /dev/shm
/dev/sdb1 9.9G 139M 9.3G 2% /new