We were struggling with the disk capacity of a necessary Ubuntu VM. We started building something on a Dev VM but decided to move it to production later on. But we never imagined the disk capacity would appear as a bottleneck later.
We had two options to get rid of this:
- Build a new VM with the required specifications — but we wanted to have the following option
- Resize the primary partition from 16GB to 30G; it was easy to extend the partition.
Dependencies We Have
We needed the ‘parted’ package in ubuntu; it was a preinstalled tool for us. If you do not have it, install it:
server:/$ sudo apt-get install parted
- If SSH is not enabled in the ESXi, then activate SSH from the UI:
2. Log in to the ESXi and run the vmkfstools command to extend the disk capacity:
#cd /vmfs/volumes/datastore1/slack-server/ # ls -l slack-server-flat.vmdk slack-server.vmx vmware-2.log slack-server.nvram vmware-3.log slack-server.vmdk vmware.log slack-server.vmsd vmware-1.log # vmkfstools -X 30G slack-server.vmdk Grow: 100% done.
- Do not use the ‘*-flat.vmdk’ file for the vmkfstools command
- Always provide the final disk size after the ‘vmkfstools -X’ command. We needed to extend from 16GB to 30GB, and we used 30G as the last disk size.
3. Check in the ESXi, the disk capacity will show 30GB now:
4. Log in to Ubuntu and extend the partition using the parted:
server:/$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.5G 0 1.5G 0% /dev tmpfs 301M 1.1M 300M 1% /run /dev/sda2 16G 13G 2.4G 84% / tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/loop0 91M 91M 0 100% /snap/core/6350 tmpfs 301M 0 301M 0% /run/user/1000
Now extend the partition:
server:/$ sudo parted [sudo] password for username: GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: VMware Virtual disk (scsi) Disk /dev/sda: 32.2GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 17.2GB 17.2GB ext4 (parted) resizepart 2 Warning: Partition /dev/sda2 is being used. Are you sure you want to continue? Yes/No? Yes End? [17.2GB]? 32.2GB (parted) q Information: You may need to update /etc/fstab.
5. Thereafter, grow the filesystem using the resize2fs:
server:/$ sudo resize2fs /dev/sda2 resize2fs 1.44.1 (24-Mar-2018) Filesystem at /dev/sda2 is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/sda2 is now 7860816 (4k) blocks long.
Finally, the disk capacity has increased:
server:/$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.5G 0 1.5G 0% /dev tmpfs 301M 1.1M 300M 1% /run /dev/sda2 30G 15G 14G 53% / tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/loop0 91M 91M 0 100% /snap/core/6350 tmpfs 301M 0 301M 0% /run/user/1000
You may imagine the workloads behind the simple and straightforward work. What if, this task is performed by a single click. WatchMyDC can help to build an automation playbook for this task. Then you start the task with a single click in the playbook, or triggered from the Facebook Messenger. Is not that cool?