This is an old revision of the document!


expand hard disk in linux vm

-merge all checkpoints -shutdown VM -make a copy of your virtual hard drive and store in another location just in case -rightclick VM, seetings, edit -virtual hard drive from left menu -edit -click next -choose expand, click next -select new size, click finish, click OK -start VM

-ssh to VM -sudo fdisk /dev/sda -p to list partitions -d to delete the partitions, then 1, d, 2, etc (data will not be lost) -n for a new partition -p for primary, 1 for 1st, 2048 for starting sector, largest possible for last sector -if asked partition contains ext4 signare do you want to remove? choose no -p to verify partitions and size -a to make the partition bootable -w to write changes. may get a message about re-reading the table failed. this is ok. -sudo reboot -wait (it takes time to apply the changes, so if ssh doesn't work immediately, wait. connecting through hyperv to watch the messages will show it is working). -sudo resize2fs /dev/sda1 (this expands the partition to use the rest of the space we just reated) -df -h to confirm

-if your swap partition was deleted, create a swap file -sudo fallocate -l 512M /swapfile -sudo chmod 600 /swapfile -sudo mkswap /swapfile -sudo swapon /swapfile -sudo swapon –show to verify -sudo cp /etc/fstab /etc/fstab.bak to backup the fstab -echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab to make your swap perminant -sudo nano /etc/sysctl.conf -add to the end: vm.swappiness=10 vm.vfs_cache_pressure=50 -save

go back into fstab and remove old swap partition uuid

references:

https://www.zubairalexander.com/blog/how-to-expand-hard-drives-in-hyper-v-virtual-machines

https://askubuntu.com/questions/116351/increase-partition-size-on-which-ubuntu-is-installed

https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04

Discussion

Enter your comment. Wiki syntax is allowed:
 
Last modified: le 2021/07/15 19:18