Got it

extend the disk partition before resize the filesystem

Latest reply: Aug 9, 2019 04:53:42 1328 6 3 0 1

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


This is the correct operation of expanding the file system.:)
View more
  • x
  • convention:

good :)
View more
  • x
  • convention:

:)
View more
  • x
  • convention:

Love your blog man. Thanks for this stuff.

tweakbox tweakbox tweakbox

This post was last edited by iosman at 2018-10-11 20:05.
View more
  • x
  • convention:

extend the disk partition before resize the filesystem-3029195-1
View more
  • x
  • convention:

Thank you!
In Windows client it is required too. I have to expand VDI virtual HDD time to time. After they are expanded in the virtual machine (I use vmWare) to realize new volume to the filesystem I need to do several steps:
1. Open "computer management".
2. Open "disk management". Often at this step the HDD has not update its size.
3. Rescan the disks. Now the total size of the HDD should update.
4. Extend the partition on the expanded virtual HDD.
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.