Cannot resize AWS EBS root volume or create larger swap partition [closed]

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

I have a Amazon Web Services EC2 Debian 8.0 instance with an Elastic Block Storage (EBS) volume of 35GB. fdisk correctly shows the size but my root partition is still at 7.8G, although I tried to execute resize2fs.

root@ip-10-0-3-164:/home/admin# fdisk -l  Disk /dev/xvda: 35 GiB, 37580963840 bytes, 73400320 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 Disklabel type: dos Disk identifier: 0x7d936f86  Device     Boot Start      End  Sectors Size Id Type /dev/xvda1 *     4096 16773119 16769024   8G 83 Linux  root@ip-10-0-3-164:/home/admin# df -h Filesystem      Size  Used Avail Use% Mounted on /dev/xvda1      7.8G  2.1G  5.3G  29% / udev             10M     0   10M   0% /dev tmpfs           200M  4.3M  196M   3% /run tmpfs           500M     0  500M   0% /dev/shm tmpfs           5.0M     0  5.0M   0% /run/lock tmpfs           500M     0  500M   0% /sys/fs/cgroup  root@ip-10-0-3-164:/home/admin# resize2fs /dev/xvda1 resize2fs 1.42.12 (29-Aug-2014) The filesystem is already 2096128 (4k) blocks long.  Nothing to do!  root@ip-10-0-3-164:/home/admin# fdisk /dev/xvda  Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.   Command (m for help): p Disk /dev/xvda: 35 GiB, 37580963840 bytes, 73400320 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 Disklabel type: dos Disk identifier: 0x7d936f86  Device     Boot Start      End  Sectors Size Id Type /dev/xvda1 *     4096 16773119 16769024   8G 83 Linux   Command (m for help): n Partition type    p   primary (1 primary, 0 extended, 3 free)    e   extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (2048-73400319, default 2048): 2048 Last sector, +sectors or +size{K,M,G,T,P} (2048-4095, default 4095):   Created a new partition 2 of type 'Linux' and of size 1 MiB.  Command (m for help): p Disk /dev/xvda: 35 GiB, 37580963840 bytes, 73400320 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 Disklabel type: dos Disk identifier: 0x7d936f86  Device     Boot Start      End  Sectors Size Id Type /dev/xvda1 *     4096 16773119 16769024   8G 83 Linux /dev/xvda2       2048     4095     2048   1M 83 Linux  Partition table entries are not in disk order.  Command (m for help): t    Partition number (1,2, default 2): 2 Hex code (type L to list all codes): L   0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris          1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-  2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-  3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-  4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx           5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data      6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .  7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility     8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt           9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access       a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O          b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor        c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs          e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT              f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/ 10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b 11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor       12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor       14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary   16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS     17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE  18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto 1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep         1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT             1e  Hidden W95 FAT1 80  Old Minix       Hex code (type L to list all codes): 82  Changed type of partition 'Linux' to 'Linux swap / Solaris'.  Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: 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).  root@ip-10-0-3-164:/home/admin# fdisk /dev/xvda  Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.   Command (m for help): p Disk /dev/xvda: 35 GiB, 37580963840 bytes, 73400320 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 Disklabel type: dos Disk identifier: 0x7d936f86  Device     Boot Start      End  Sectors Size Id Type /dev/xvda1 *     4096 16773119 16769024   8G 83 Linux /dev/xvda2       2048     4095     2048   1M 82 Linux swap / Solaris  Partition table entries are not in disk order. 

As you see, the resize2fs does not have effect. I also cannot create a swap partition with more space than 1M.

This problem occurs on all my instances. Although they all have 30-35GB EBS volumes, I cannot resize them and they stay at 8GB. When I attach just an additional volume besides the root mounted one, it works fine.

Can you help me?

回答1:

Forget the other answers. I just spent 3 days figuring out the root cause and a simple workaround:

https://serverfault.com/questions/748063/debian-8-ami-only-using-8gb-partition



回答2:

unattach the volume for xvda. Attach it to another instance but don't mount it on the volume. Then use fdisk to delete the first partition and re add it with all of the available space. Set the bootable flag and ensure that the filesystem type is still 83. write the fdisk partition table and exit fdisk. Run e2fsck and resize2fs on the new first partition

Unattach the disk from the other instance and reattach it to the original instance.

When the original instance restarts with the modified volume you should see the 35GB

The reason to do it this way is that you can't modify the partition table of a running, attached root disk

All this stuff is detailed in the aws documentation



回答3:

Resize partition with resize2fs on Debian 8 Jessie on AWS EC2 + EBS is not working.

My solution was to manually creating a separate volume for this.

I will add here a manual step by step how to do.

First make a backup of your instance, creating an Image AMI or Snapshot Volume.

Creating Image.

Or creating Snapshot.

Now let's create a Debian 8 instance, only to repartition the volume you need.

and finish all the steps of creating the instance until it start.

Access the instance with ssh.

Login as root.

sudo -i 

Now let's set the source.list be able to install the 'parted'.

pico /etc/apt/sources.list 

and update the file with.

########################################################################## deb http://cloudfront.debian.net/debian jessie main contrib non-free deb-src http://cloudfront.debian.net/debian jessie main contrib non-free  deb http://security.debian.org/ jessie/updates main contrib non-free deb-src http://security.debian.org/ jessie/updates main contrib non-free  deb http://cloudfront.debian.net/debian jessie-updates main contrib non-free deb-src http://cloudfront.debian.net/debian jessie-updates main contrib non-free  deb http://cloudfront.debian.net/debian jessie-backports main contrib non-free deb-src http://cloudfront.debian.net/debian jessie-backports main contrib non-free ########################################################################## 

run the apt-get.

apt-get clean && apt-get update && apt-get upgrade 

Now let's install the parted.

apt-get install parted 

Now stop the instance created.

Now let's create a volume from the snapshot backup that you created.

NOTE: Inform the size of the total of the partition you want, here.

Add the volume in /dev/sdf

Now start the instance.

Access the instance with ssh.

Login as root.

sudo -i 

Check partitions

df -h  lsblk 

You will see output like this.

The xvdf with 40G and xvdf1 with 8G.

Now let's run the parted on volume /dev/xvdf.

parted /dev/xvdf 

Within the parted. Set the unit.

(parted) unit s 

Print partition information to see.

(parted) print 

You will see output like this.

Model: Xen Virtual Block Device (xvd) Disk /dev/xvdf: 83886080s Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:  Number  Start  End        Size       Type     File system  Flags  1      1s     16777215s  16777215s  primary  ext4         boot 

Remove the partition. (This will not delete the data, data is retrieved later).

(parted) rm 1 

Now we mount the new partition from begin 1s, to the end 100% of in the volume.

(parted) mkpart primary 1 100%   Warning: The resulting partition is not properly aligned for best performance.  Ignore/Cancel? : Ignore 

Print partition information to see.

(parted) print 

You will see output like this.

Model: Xen Virtual Block Device (xvd) Disk /dev/xvdf: 83886080s Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:  Number  Start  End        Size       Type     File system  Flags  1      1s     83886079s  83886079s  primary               lba 

Now set the partition as bootable.

(parted) set 1 boot on 

And finalize the parted.

(parted) quit 

Ignore information print.

Information: You may need to update /etc/fstab. 

Check partitions

lsblk 

You will see output like this.

See it now that xvdf and xvdf1 has the size 40G. \o/

Now we just need to make e2fsck to check and index the data.

NOTE: e2fsck can take a long time to do the check. You should awaits.

e2fsck -f /dev/xvdf1 

You will see output like this.

e2fsck 1.42.12 (29-Aug-2014) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/xvdf1: 208603/524288 files (0.2% non-contiguous), 1918667/2097151 blocks 

Everything Ok with the partition.

Now make a snapshot backup of the partition, as we did in the beginning tutorial.

Create a new volume with the snapshot created, and add the original instance.

Remember to stop the instance first.

Remove the old volume instance and add the new volume instance.

Attach to (/dev/****) original, im my case is /dev/sda.

Start the instance and all ready! Resized partition. \o/



回答4:

A little more complicated, and assuming that you have just a few easily-identified chunks of "too-big" directory trees (such as /opt and /var/log) would be to create filesystem(s) on the unallocated 28GB, use rsync to copy your working files to the new filesystems, and wipe the obsolete files (to free up diskspace), mounting the new filesystems in their place (by editing /etc/fstab, of course).

If you do this for /var/log, you have to do a reboot immediately after migrating the files, since the system still references the original files. Of course, you might want to practice the procedure on a test-machine.

It would be a lot simpler if Amazon's root volumes used LVM.



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