1

Context

I have a remote Linux CentOS VM on Azure which hosts a MYSQL database. I just finished upgrading the disk size from 30GB to 100GB. Problem is that extra space wasn't added to the partition.

$ parted

(parted) print free
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  31.2GB  31.2GB  primary  ext4            boot
 2      31.2GB  32.2GB  1049MB  primary  linux-swap(v1)
        32.2GB  107GB   75.2GB           Free Space

$ lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0      2:0    1    4K  0 disk
sda      8:0    0  100G  0 disk
├─sda1   8:1    0   29G  0 part /
└─sda2   8:2    0 1000M  0 part
sdb      8:16   0   50G  0 disk
└─sdb1   8:17   0   50G  0 part /mnt/resource

$ df

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       29822848 25241412   3043440  90% /
devtmpfs         1752756        0   1752756   0% /dev
tmpfs            1761624        0   1761624   0% /dev/shm
tmpfs            1761624     8440   1753184   1% /run
tmpfs            1761624        0   1761624   0% /sys/fs/cgroup
/dev/sdb1       51472864    53276  48781868   1% /mnt/resource
tmpfs             352328        0    352328   0% /run/user/1000

Question

Obviously, I need to extend partition 1 (/dev/sda) to include the free space. Using this post, I tried

sudo resize2fs /dev/sda 100G

but it gets rejected with

Device or resource busy while trying to open /dev/sda`.

I think this means that I can't extend the partition while it's in use, which makes sense to me given my experience doing the same on windows. If that is the case, then how do I extend the partition on a remote azure VM?

Note: I only shell into the VM, therefore I cannot boot an external program, use a GUI, or simply mount the drive onto another machine.

OS Details

  Static hostname: PMCTMYSQL
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 99f30b6b81444d47a888f0313c428bd8
           Boot ID: 444cc3a5a22b4e53a947e06af2d9b4d2
    Virtualization: microsoft
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.36.3.el7.x86_64
      Architecture: x86-64

More Research

I checked other threads suggested by SU, but they don't apply for a variety of reasons:

Suggests GUI tools

  1. How to extend partition size in linux(ubuntu 9.04)?
  2. How to extend a Linux ext3 partition?
  3. How to extend a Mint Linux partition on a dual boot config with Windows 8.1?
  4. How to resize extended partition?

Uses VMware

  1. How to extend partition size in linux(ubuntu 9.04)?

Uses external tools (boot disk) How to Extend primary partition(/dev/sda1) in linux?

  1. https://www.howtoforge.com/linux_resizing_ext3_partitions
2
  • Do you mean you want to extend /dev/sda2 to 100G?
    – Jason Ye
    Commented Jun 29, 2017 at 1:26
  • no. /dev/sda1 needs to be extended to 100G. I've updated the answer to include lsblk and df results. Commented Jun 29, 2017 at 16:38

2 Answers 2

1

You can use Gparted, as you are using centOS you can install it by:

yum install epel-release
yum install gparted

Here is some information on how to use it:

http://gparted.org/display-doc.php%3Fname%3Dmoving-space-between-partitions

0

Do you want to extend /dev/sda2 to 100G? like this:

[root@jason ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs       100G  1.2G   99G   2% /
devtmpfs       devtmpfs  828M     0  828M   0% /dev
tmpfs          tmpfs     839M     0  839M   0% /dev/shm
tmpfs          tmpfs     839M  8.3M  830M   1% /run
tmpfs          tmpfs     839M     0  839M   0% /sys/fs/cgroup
/dev/sda1      xfs       497M   62M  436M  13% /boot
/dev/sdb1      ext4       69G   53M   66G   1% /mnt/resource
tmpfs          tmpfs     168M     0  168M   0% /run/user/1000

If yes, we can use shell to extend /dev/sda2 to 100G. (centos 7.3)

[root@jason ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
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 label type: dos
Disk identifier: 0x000bd020

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64        3917    30944256   83  Linux

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First cylinder (64-13054, default 64): 
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-13054, default 13054): 
Using default value 13054
Partition 2 of type Linux and of size 99.5 GiB is set

Command (m for help): a
Partition number (1,2, default 2): 2

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
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 label type: dos
Disk identifier: 0x000bd020

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2   *          64       13054   104343231   83  Linux

Command (m for help): w
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.
[root@jason ~]# reboot

After reboot completed, we should use this command to extend it xfs_growfs -d /dev/sda2(centos 7), centos 6 we should use sudo resize2fs /dev/sda2

[root@jason ~]# xfs_growfs -d /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=1934016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7736064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3777, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7736064 to 26085807
[root@jason ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs       100G  1.2G   99G   2% /

More information about extend OS disk, please refer to this link.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .