• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

阿里云扩容系统盘

未分类 小杰 3个月前 (09-20) 129次浏览 已收录 0个评论

If you clone your VPS to a server with a larger disk, or something goes wrong when expanding your available disk space you may have a situation where your root partition on /dev/vda1 is not taking up all the space available.

For example, here we have a root partition of 10G  on a 30G disk  (commands entered are shown starting with #, notable parts in bold):

 

To expand /dev/vda1 so that it takes up the full 30G available, there are three steps to take:

  1. Take a backup.  While always a good idea, editing the partition table incorrectly will mess up the disk.
  2. Modify the partition table so that /dev/vda1 is 30G in size
  3. Resize the ext3/ext4 partition so that it takes up the new, full size of /dev/vda1

Modify the Partition Table

(Please note: these instructions are based on typical Binary Lane server, with a single partition.)
Start by checking the current partition layout:

 

Confirm we have a single partition, and importantly it is marked as boot and starts at sector 2048 (which is the standard value for Binary Lane). This information is crucial later, so copy it to your notepad.

Next we use the fdisk tool to temporarily ‘delete’ partition /dev/vda1, before immediately recreating it with the same size, type, and start location. This is safe when accomplished within a single use of fdisk tool, because it does not actually write changes until requested.  Here is the full process, with my fdisk input in bold (press enter after each input):

 

There are a few steps here, so breaking it down:

  1. First we enter d to delete a partition. As there is only one partition (/dev/vda1) it is automatically selected.
  2. Next we create a new partition.
    • n to start the new partition function
    • p for a primary partition
    • 1 to create /dev/vda1
    • 2048 as our start sector (remember, we we pulled this value from “fdisk -l” earlier)
    • Press Enter (blank input) to select the default last sector, which will be the end of the disk
  3. The type should be set to match what it was previously (which from fdisk -l, we can see was ID 83).  Press t to set partition type, then enter 83 to set it to Linux.
  4. We can see in the initial “fdisk -l” output an asterisk under boot, meaning the partition was marked bootable. To set the bootable flag, press a for the boot function and enter 1 if prompted for partition number.
  5. Now check your work.  Enter p command to print the new (in-memory) partition table, and compare the last line of output to what is in your notepad.   Everything should be the same except for the “end”, “sectors”, and “size” .
  6. Finally, w to write new partition table to disk.
In the last few lines of output, we can see a problem: Re-reading the partition table failed.: Device or resource busy  along with the suggested solution. Run partprobe on /dev/vda to tell the linux kernel to load the new partition table:

 

On success there is no output.

Resizing /dev/vda1 filesystem

At this point if we re-check the root filesystem, it is the same size as before:

 

This is because we have expanded the partition (the area of disk that the filesystem is located in) but the filesystem has not been expanded to fll it.  Correct this with the resize2fs tool:

 

And confirm that it worked:

 

The root filesystem size has grown to 30G, using all the space available on /dev/vda.


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:阿里云扩容系统盘
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址