内容简介:After you increase the size of disk volume (such as AWS ESB and Disks under Google cloud and others service providers), you must use file system–specific commands to extend the file system to the larger size. In this tutorial, I am using Google cloud with
I increased the size of the volume in Linux using my cloud service providers’ online tool. My original disk size was 200GB, and I grew to 400GB. However, I only able to use 200GB and not 400GB. How do I resizing my disk and extend the file system resizing a disk volume?
After you increase the size of disk volume (such as AWS ESB and Disks under Google cloud and others service providers), you must use file system–specific commands to extend the file system to the larger size. In this tutorial, I am using Google cloud with the XFS file system, and we will extend a Linux File System after resizing a volume. The following instructions were tested on CentOS, RHEL, Ubuntu, and Debian Linux but should work with other Linux distros too.
Linux extend file system after resize disk volume
First you need to find information about the disks. As soon as Linux detects disk size change, you will see a message in your log as follows using the dmesg command:
sudo dmesg sudo dmesg | more
[ 12.834446] bpfilter: Loaded bpfilter_umh pid 1037 [ 12.917195] new mount options do not match the existing superblock, will be ignored [262733.527584] sd 0:0:2:0: [sdb] 838860800 512-byte logical blocks: (429 GB/400 GiB) [262733.527587] sd 0:0:2:0: [sdb] 4096-byte physical blocks [262733.528263] sdb: detected capacity change from 214748364800 to 429496729600
Please note down the disk name sdb.
Warning: Before you type any one of the following commands, make a backup of all your data. It is crucial to create a snapshot of the disk and backup data somewhere else safely. The author and nixCraft site is not responsible for data loss caused when you extend a Linux file system after resizing a block storage/volume.
Verify new disk size
Type the following fdisk command:
sudo fdisk -l /dev/sdb
Sample outputs:
Disk /dev/sdb: 400 GiB, 429496729600 bytes, 838860800 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: dos Disk identifier: 0xd3a4f1f7 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 419430399 419428352 200G 83 Linux
How to list block devices
One can run the following lsblk command to show information about the block devices attached to your cloud VM:
sudo lsblk
Find the current disk size and partiton type
Run the following df command and file command:
df -HT df -HT | grep /backup1 df -HT | grep /dev/sdb1 sudo file -s /dev/sdb*
/dev/sdb: DOS/MBR boot sector; partition 1 : ID=0x83, ... /dev/sdb1: SGI XFS filesystem data
So now we know that xfs is the file system for /dev/sdb1 partition.
Unmount the partition if mounted
Run the following command:
sudo umount /dev/sdb1
Extending a Linux partition
Since our resized volume has a partition and the partition does not reflect the new size (400 GB) of the disk volume, we use the growpart command on Linux to extend the partition size.
How to use growpart to resize your image partition
The syntax is:
growpart /dev/DEVICE_NAME PARTITION_NUMBER
Please note that there is a space between the DEVICE_NAME and the PARTITION_NUMBER . For example:
sudo growpart --dry-run /dev/sdb 1
Sample outputs:
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
The --dry-run option only reports what would be done. To resize it, run:
sudo growpart /dev/sdb 1
You can verify that the partition size increased using the lsblk command command again:
sudo lsblk
Mount the file system again
Execute the following command:
sudo mount /dev/sdb1 /backup1/
Verify disk size:
df -H
Sample outputs:
Filesystem Size Used Avail Use% Mounted on udev 501M 0 501M 0% /dev tmpfs 103M 938k 102M 1% /run /dev/sda1 11G 3.1G 7.2G 30% / tmpfs 515M 0 515M 0% /dev/shm tmpfs 5.3M 0 5.3M 0% /run/lock tmpfs 515M 0 515M 0% /sys/fs/cgroup /dev/sda15 110M 3.8M 106M 4% /boot/efi tmpfs 103M 0 103M 0% /run/user/1001 /dev/sdb1 215G 36G 180G 17% /backup1
Extending the file system
As you can size mounted file system still shows 200GB total size for the /dev/sdb1 partition.
How to extend the XFS file system on Linux
The syntax is:
sudo xfs_growfs /mount_point sudo xfs_growfs /backup1/
How to extend the ext4 file system on Linux
The syntax is:
sudo resize2fs /dev/DEVICE_NAME_PARTITION_NUMBER
## note /dev/sdb1 must be unmouted ##
sudo resize2fs /dev/sdb1
Verification – Extending a Linux file system after resizing a disk volume
Simply run the df command to verify that your disk sized increased from 200GB to 400GB:
df -HT
Conclusion
Most cloud service provider allows you to add storage capacity to your VM. One can extend such block storage under Linux when the need arises as your business grows. You learned how to resize the disk volume of an instance from 200 GB to 400 GB using various Linux command-line options.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
百度SEO一本通
潘坚、李迅 / 电子工业出版社 / 2015-6 / 59.00元
《百度SEO一本通》通过浅显易懂的叙述方式,以及大量的图示,详细介绍了SEO的关键技术要点,对于搜索引擎优化中重要的关键词优化、链接优化,以及百度推广中的推广技巧都进行了详细的介绍。 《百度SEO一本通》共分为11章,首先让大家了解SEO存在的原因,然后对网页、网站、空间和程序与SEO的关系展开了细节上的讨论,最后几章深入介绍了百度推广的相关概念、设置、技巧和实操,让读者可以轻松上手操作,易......一起来看看 《百度SEO一本通》 这本书的介绍吧!