Appliance: disk increase

Run all commands as root (su -):

  1. Check current disk size (default is 200 GiB):
    fdisk -l /dev/sda
      Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
    
  2. Increase virtual hard disk capacity in vCenter (500 GiB in this case):
    VMware disk increase
  3. Reboot virtual machine

  4. Log in as root and check disk size again, you should see new size, partitions still use old size:
    fdisk -l /dev/sda
      Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
      Disk model: Virtual disk    
      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: 0x563c66d6
    
      Device     Boot     Start       End   Sectors  Size Id Type
      /dev/sda1  *         2048 417429503 417427456  199G 83 Linux
      /dev/sda2       417431550 419428351   1996802  975M  5 Extended
      /dev/sda5       417431552 419428351   1996800  975M 82 Linux swap / Solaris
    
    # turn off swap partition
    swapoff -a
    
    # now let's define new partition table
    fdisk -u /dev/sda
    
    # first delete all existing partitions (type d [Enter] three times):
      Command (m for help): d
      Partition number (1,2,5, default 5): 
    
      Partition 5 has been deleted.
    
      Command (m for help): d
      Partition number (1,2, default 2): 
    
      Partition 2 has been deleted.
    
      Command (m for help): d
      Selected partition 1
      Partition 1 has been deleted.
    
    # time to create new primary partition with command n (8 GiB at the end of disk space will be reserved for swap in this example)
    # use default values (just type [Enter]), except for Last sector:
      Command (m for help): n
      Partition type
         p   primary (0 primary, 0 extended, 4 free)
         e   extended (container for logical partitions)
      Select (default p):
    
      Using default response p.
      Partition number (1-4, default 1):
      First sector (2048-1048575999, default 2048): 
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575999, default 1048575999): -8G
    
      Created a new partition 1 of type 'Linux' and of size 492 GiB.
      Partition #1 contains a ext4 signature.
    
      Do you want to remove the signature? [Y]es/[N]o: n
    
    # create swap partition at the end of disk space
      Command (m for help): n
      Partition type
         p   primary (1 primary, 0 extended, 3 free)
         e   extended (container for logical partitions)
      Select (default p): 
    
      Using default response p.
      Partition number (2-4, default 2): 
      First sector (1031798784-1048575999, default 1031798784): 
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (1031798784-1048575999, default 1048575999): 
    
      Created a new partition 2 of type 'Linux' and of size 8 GiB.
    
    # change 2nd partition type to swap
      Command (m for help): t
      Partition number (1,2, default 2): 
      Hex code or alias (type L to list all): 82
    
      Changed type of partition 'Linux' to 'Linux swap / Solaris'.
    
    # check partition table before saving, it should look like this
    
      Command (m for help): p
      Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
      Disk model: Virtual disk    
      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: 0x563c66d6
      
      Device     Boot      Start        End    Sectors  Size Id Type
      /dev/sda1             2048 1031798783 1031796736  492G 83 Linux
      /dev/sda2       1031798784 1048575999   16777216    8G 82 Linux swap / Solaris
    
    # write new partition table and exit fdisk
      Command (m for help): w
      The partition table has been altered.
      Syncing disks.
    
    # try to force kernel to use new partition table
    partx /dev/sda
      If that fails, you'll need to reboot. The system should boot just fine.
    
  5. Then, resize the filesystem so it spreads to the extent of the enlarged partition
    resize2fs /dev/sda1
    
  6. Enjoy new filesystem space:
    df -h
      Filesystem      Size  Used Avail Use% Mounted on
      udev             12G     0   12G   0% /dev
      tmpfs           2.4G  668K  2.4G   1% /run
      /dev/sda1       484G  6.3G  456G   2% /
    
  7. Reactivate swap
    mkswap /dev/sda2
    swapon /dev/sda2
    
    List current disk UUIDs:
    blkid
      /dev/sda1: UUID="a15a90d8-1e99-42c1-bfb5-6b98b781067f" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="563c66d6-01"
      /dev/sda2: UUID="804f08d6-65e9-4c10-9cf5-8ad0e5748aa3" TYPE="swap" PARTUUID="563c66d6-02"
    
    Edit /etc/fstab and replace existing swap partition UUID with the current one shown by blkid command
    # swap was on /dev/sda5 during installation
    UUID=804f08d6-65e9-4c10-9cf5-8ad0e5748aa3 none            swap    sw              0       0