VirtualBox: extend partition

前端 未结 8 1304
渐次进展
渐次进展 2021-01-30 07:34

I have virtualbox-4.1.0 with centos-5.6 installed in. Now I would like to extend the VM image, which I previously allocated for virtual machine installation, it was 8Gb, that\'s

8条回答
  •  渐次进展
    2021-01-30 07:54

    I'm using a CentOS7 virtualbox, and I finally enlarged my partition /dev/mapper/centos-root - gparted doesn't work for me because I do not have a desktop on CentOS7 virtualbox.

    1. Power off your CentOS virtual machine
    2. Go into the directory of your *.vdi image. If you don't know where it is, look at your Virtualbox Manager GUI virtualbox -> settings -> storage -> *.vdi -> location e.g. mine is located under ~/VirtualBox VMs/CentOS7/CentOS.vdi
    3. Back up your image just in case anything goes wrong

      $ cp CentOS7.vdi CentOS7.backup.vdi

    4. Resize your virtual storage size, e.g. 200 GB

      $ VBoxManage modifyhd CentOS7.vdi --resize 204800

    5. Power on your CentOS virtual machine, issue

      $ sudo fdisk -l

       Device Boot      Start         End      Blocks   Id  System
        /dev/sda1   *        2048     1026047      512000   83  Linux
        /dev/sda2         1026048   209715199   104344576   8e  Linux LVM
    
    1. Use fdisk utility to delete/create partitions

      $ sudo fdisk /dev/sda

    2. You are in the fdisk utility interactive mode, issue following commands: (mostly just follow the default recommendation)

      d - delete a partition

      2 - select a partition to delete (/dev/sda2 here)

      n - create a new partition

      p - make it a primary partition

      2 - make it on the same partition number as we deleted

      - set the starting block (by default)

      - set end ending block (by default)

      w - write the partition and leave the fdisk interactive mode

    3. Reboot your CentOS machine

      $ sudo reboot

    4. Resize the physical volume and verify the new size

      $ sudo pvresize /dev/sda2

      $ sudo pvscan

    5. Take a look at your logical mapping volume to see what volume you want to enlarge, in my case, /dev/mapper/centos-root

    6. Resize the file system by adding -r option, it will take care of resizing for you

      $lvextend -r -l +100%FREE /dev/mapper/centos-root

    7. Resize the file system:

      $resize2fs /dev/mapper/fedora-root

      For CentOS 7: $xfs_growfs /dev/mapper/fedora-root

    8. Last check:

      $df -h.

    Reference:https://blog.jyore.com/2013/06/virtualbox-increase-size-of-rhelfedoracentosscientificos-guest-file-system/#comment-2879

提交回复
热议问题