Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


EC2 grow disk size

19 Mar 2022 »

not used yum -y install cloud-utils-growpart

[root@controller ~]# fdisk -l
Disk /dev/nvme0n1: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9c7ba3f7

Device         Boot    Start      End  Sectors  Size Id Type
/dev/nvme0n1p1 *        2048 15730687 15728640  7.5G 83 Linux
/dev/nvme0n1p2      15935488 16982015  1046528  511M 82 Linux swap / Solaris
[root@controller ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.6G     0  7.6G   0% /dev
tmpfs           7.6G     0  7.6G   0% /dev/shm
tmpfs           7.6G  8.4M  7.6G   1% /run
tmpfs           7.6G     0  7.6G   0% /sys/fs/cgroup
/dev/nvme0n1p1  7.4G  2.7G  4.4G  38% /
tmpfs           1.6G     0  1.6G   0% /run/user/0

https://superuser.com/questions/541067/how-to-move-a-partition-in-gnu-linux echo ‘+50000M,’ | sfdisk –move-data /dev/nvme0n1 -N 2 –force

Disk /dev/nvme0n1: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9c7ba3f7

Old situation:

Device         Boot    Start      End  Sectors  Size Id Type
/dev/nvme0n1p1 *        2048 15730687 15728640  7.5G 83 Linux
/dev/nvme0n1p2      15935488 16982015  1046528  511M 82 Linux swap / Solaris

/dev/nvme0n1p2: 
New situation:
Disklabel type: dos
Disk identifier: 0x9c7ba3f7

Device         Boot     Start       End  Sectors  Size Id Type
/dev/nvme0n1p1 *         2048  15730687 15728640  7.5G 83 Linux
/dev/nvme0n1p2      118335488 119382015  1046528  511M 82 Linux swap / Solaris

Data move:
 typescript file: /root/sfdisk-nvme0n1p2.move
 old start: 15935488, new start: 118335488 (move 1046528 sectors)

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).
Syncing disks.

https://yabhinav.github.io/cloud/resize-root-partition-on-ec2-centos6hvmami/

after reboot

resize2fs /dev/nvme0n1p1

df -h

[root@controller ~]# fdisk -l
Disk /dev/nvme0n1: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x9c7ba3f7

Device         Boot     Start       End   Sectors  Size Id Type
/dev/nvme0n1p1 *         2048 118130687 118128640 56.3G 83 Linux
/dev/nvme0n1p2      118130688 119177215   1046528  511M 82 Linux swap / Solaris
[root@controller ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.6G     0  7.6G   0% /dev
tmpfs           7.6G     0  7.6G   0% /dev/shm
tmpfs           7.6G  8.4M  7.6G   1% /run
tmpfs           7.6G     0  7.6G   0% /sys/fs/cgroup
/dev/nvme0n1p1   56G  2.7G   51G   5% /