unable to resize root partition on EC2 centos

风格不统一 提交于 2019-12-18 11:20:53

问题


i created my EC2 Machine using Community Image of Centos 6.3 x64. i have added a 35 GB disk. Now when i do #df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.2G  6.4G  16% /
tmpfs                 7.3G     0  7.3G   0% /dev/shm

my disk is 35GB but its showing 8 GB in root and 7 as tmpfs.

i tried to use resize2fs but it didnt work on centos. disk has ext4 partation..

# resize2fs /dev/xvda
resize2fs 1.41.12 (17-May-2010)
resize2fs: Device or resource busy while trying to open /dev/xvda
Couldn't find valid filesystem superblock.

or even if i tried resize2fs /dev/xvda1 it says device has nothing to do.

any idea or other way, its my root disk(/). so cant unmount it.


回答1:


i found a way to do that, resize2fs not working in case not sure why but it says device or resource busy. i found a very good article on resizedisk using fdisk we can increase block size by deleting and creating it and Make the partition bootable. all it requires is a reboot. it wont effect your data if you use same start cylinder.

# df -h  <<1>>

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      6.0G  2.0G  3.7G  35% / 
tmpfs            15G     0   15G   0% /dev/shm

# fdisk -l  <<2>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders
Units = cylinders of 1649 * 512 = 844288 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           2        7632     6291456   83  Linux

# fdisk /dev/xvda  <<3>>

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): u  <<4>>
Changing display/entry units to sectors

Command (m for help): p  <<5>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders, total 41943040 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: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    12584959     6291456   83  Linux

Command (m for help): d  <<6>>
Selected partition 1

Command (m for help): n  <<7>>
Command action
   e   extended
   p   primary partition (1-4)
p  <<8>>
Partition number (1-4): 1  <<9>>
First sector (17-41943039, default 17): 2048  <<10>>
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): <<11>>
Using default value 41943039

Command (m for help): p <<12>>

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
97 heads, 17 sectors/track, 25435 cylinders, total 41943040 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: 0x0003b587

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048    41943039    20970496   83  Linux

Command (m for help): a  <<13>>
Partition number (1-4): 1  <<14>>


Command (m for help): w  <<15>>
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.

# reboot  <<16>>

<wait>

# df -h  <<17>>
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  2.0G   17G  11% / 
tmpfs            15G     0   15G   0% /dev/shm

# resize2fs /dev/xvda1  <<18>>
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 5242624 blocks long.  Nothing to do!



回答2:


The following steps very simple works very well for me:

# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk 
└─xvda1 202:1    0   8G  0 part /

Perform the following command as root:

# yum install cloud-utils-growpart

# growpart /dev/xvda 1

# reboot

After the reboot:

# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk 
└─xvda1 202:1    0  30G  0 part /



回答3:


I got the same problem. All I need to do is

  1. reboot the instance
  2. run the command

    sudo resize2fs -f /dev/xxxx
    

and it works well for me.




回答4:


An Addition to Adeel Ahmad's Answer:

If you are attempting to start an instance from an AMI with a swap partition, then additional steps will have to be performed.

For example, if the ami contains as follows:

# fdisk -l
Disk /dev/xvde: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe211223f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1   *           1        1291    10369926   83  Linux
/dev/xvde2            1292        1305      112455   82  Linux swap / Solaris

If I have to upgrade my capacity to 20GB, i will create an AMI and try to launch another instance with 20GB space. After this, if i try the above steps, the disk space wont increase as there is a xvde2 partition in-between the xvde1 and the new space.

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvde1            9.8G  7.5G  1.8G  81% /

$ fdisk -l

Disk /dev/xvde: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe211223f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1   *           1        1291    10369926   83  Linux
/dev/xvde2            1292        1305      112455   82  Linux swap / Solaris

$ resize2fs /dev/xvde1 
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 2592481 blocks long.  Nothing to do!

In this case do the following

  1. Delete both the partitions
  2. Create new Primary partition with the new required size minus the size for swap space
  3. Add bootable flag for this partition
  4. Create second partition
  5. Mark it as swap
  6. write changes and reboot
  7. Extend partition 1
  8. Setup swap OR

Deleting partition 1 Selected partition 1

Command (m for help): d  <<6>>
Partition number (1-4): 1 <<6.0.1>> 

Deleting partition 2 Selected partition 2

Command (m for help): d  <<6.2>>

Creating resized primary partition 1

Command (m for help): n  <<7>>
Command action    
e   extended    
p   primary partition (1-4) 
p  <<8>> 
Partition number (1-4): 1  <<9>> 
First sector (17-41943039, default 17): 2048  <<10>> 
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):<<NEW_UPPER_LIMIT>> <<11>>

TAKE CARE : 2048 should be replaced by your original starting sector or the system wont boot. NEW_UPPER_LIMIT will be the new sector number for upper limit and the rest will be left for swap. For maintaining the same swap space, Subtract the original start and end sector numbers and then subtract the result from 41943039(or your upper limit)

Creating swap partition

Command (m for help): n  <<12>>
Command action    
e   extended    
p   primary partition (1-4) 
p  <<13>>
Partition number (1-4): 2  <<14>> 
First sector (<<NEW_UPPER_LIMIT+1>>-41943039, default <<NEW_UPPER_LIMIT+1>>): <<USE_DEFAULT>>  <<15>> 
Last sector, +sectors or +size{K,M,G}(<<NEW_UPPER_LIMIT+1>>-41943039,default 41943039):<<USE_DEFAULT>> <<16>>
Using default value 41943039

Adding bootable bit for partition 1

Command (m for help): a  <<17>>
Partition number (1-4): 1  <<18>>

Marking partition 2 as swap

Command (m for help): l <<19>>

Now you will see a list of filesystems. Note the one corresponding to Linux swap (say 82)

Command (m for help): t <<20>>
Partition number (1-4): 2 <<21>>
Hex Code (type l to list codes) : 82 <<22>>

Write changes and reboot

Command (m for help): w  <<23>> The partition table has been altered!
....

$ sudo reboot

After reboot run

resize2fs /dev/xvde1

This will resize your fs

Now to use the second partition as swap

$ mkswap /dev/<<SECOND SWAP PARTITION(run fdisk -l to get the name)>>
$ swapon /dev/<<SECOND SWAP PARTITION(run fdisk -l to get the name)>>

You can check the /proc/swaps file to verify

$ cat /proc/swaps

Now add the following to the /etc/fstab for these changes to be persistent

At the end of /etc/fstab (open with nano or vi etc)

/dev/<<SECOND SWAP PARTITION>>   swap    swap   defaults   0 0

Save and Exit

Reboot and check




回答5:


I had faced the same issue with my Debian 8 ec2 instance and getting below error

FAILED: failed to get CHS from /dev/xvda

Solution:

$ sudo parted /dev/xvda resizepart 1
Warning: Partition /dev/xvda1 is being used. Are you sure you want to continue?
Yes/No? yes                                                             
End?  [8588MB]? 100                  
$ sudo resize2fs /dev/xvda1
$ lsblk
$ df -h 

you will see that ebs volume has increased now.



来源:https://stackoverflow.com/questions/24014493/unable-to-resize-root-partition-on-ec2-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!