Difference between revisions of "Expand Ubuntu Server Partition"

From RHS Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
a) Connect to the VMware ESXi 5 server using the vShpere Client. Edit the VM's properties to increase the hard disk size (VM has  to be off) - I won't get into details on that, if you have the experience on managing ESXi you know what to do... I'm  assuming the process is the same for ESXi 4. Now restart the VM.  
+
# Connect to the VMware ESXi 5 server using the vShpere Client. Edit the VM's properties to increase the hard disk size (VM has  to be off) - I won't get into details on that, if you have the experience on managing ESXi you know what to do... I'm  assuming the process is the same for ESXi 4. Now restart the VM.  
  
b) Login via SSH to the VM and follow this process.   
+
# Login via SSH to the VM and follow this process.   
- First list all partitions:   
+
* First list all partitions:   
$ ls -al /dev/sda*   
+
$ ls -al /dev/sda*   
  
- Create new partition using fdisk:   
+
* Create new partition using fdisk:   
$ fdisk /dev/sda   
+
$ fdisk /dev/sda   
 
Then:   
 
Then:   
 
     type p - to list all your partitions   
 
     type p - to list all your partitions   
Line 17: Line 17:
 
     type p - to list the new partition table   
 
     type p - to list the new partition table   
 
     type w - to write changes and exit
 
     type w - to write changes and exit
- Reboot server:   
+
* Reboot server:   
$ reboot   
+
$ reboot   
  
- Assuming you created partition /dev/sda3, let's now create the physical volume in that partition:   
+
* Assuming you created partition /dev/sda3, let's now create the physical volume in that partition:   
$ pvcreate /dev/sda3   
+
$ pvcreate /dev/sda3   
 
   
 
   
- Now let's extend the server's Volume Group to that physical volume.   
+
* Now let's extend the server's Volume Group to that physical volume.   
$ vgdisplay   
+
$ vgdisplay   
 
This will give you the info on your current Volume Group. Note down the entry next to "VG Name". That's your Volume Group name.   
 
This will give you the info on your current Volume Group. Note down the entry next to "VG Name". That's your Volume Group name.   
$ vgextend EnterVolumeGroupNameHere /dev/sda3   
+
$ vgextend EnterVolumeGroupNameHere /dev/sda3   
  
 
Keep in mind   
 
Keep in mind   
 
If you get a message saying /dev/sda3 could not be added to your Volume Group, you need to remove the physical volume and  recreate it. Metadata might have gotten corrupt and thus the volume cannot be added to your Volume Group. So just do:   
 
If you get a message saying /dev/sda3 could not be added to your Volume Group, you need to remove the physical volume and  recreate it. Metadata might have gotten corrupt and thus the volume cannot be added to your Volume Group. So just do:   
$ pvremove /dev/sda3   
+
$ pvremove /dev/sda3   
 
And then again:   
 
And then again:   
$ pvcreate /dev/sda3   
+
$ pvcreate /dev/sda3   
 
   
 
   
- Since we're (essentially) extending the main logical volume, let's get the name of that:   
+
* Since we're (essentially) extending the main logical volume, let's get the name of that:   
$ lvdisplay   
+
$ lvdisplay   
 
and note down the entry next to "LV Name". This is your logical volume's name (e.g. /dev/srv/root), which you'll now extend to  the newly added partition/physical volume.   
 
and note down the entry next to "LV Name". This is your logical volume's name (e.g. /dev/srv/root), which you'll now extend to  the newly added partition/physical volume.   
  
- Extend the logical volume by X GBs:   
+
* Extend the logical volume by X GBs:   
$ lvextend -L +XG yourLogicalVolumeName   
+
$ lvextend -L +XG yourLogicalVolumeName   
 
Make sure you replace X above with the actual number of GBs you've added in your VM's settings. So if you increased your VM by  20GBs, the command becomes:   
 
Make sure you replace X above with the actual number of GBs you've added in your VM's settings. So if you increased your VM by  20GBs, the command becomes:   
$ lvextend -L +20G yourLogicalVolumeName   
+
$ lvextend -L +20G yourLogicalVolumeName   
 
   
 
   
- Finally, let's resize the file system to the new allocated space:   
+
* Finally, let's resize the file system to the new allocated space:   
$ resize2fs yourLogicalVolumeName   
+
$ resize2fs yourLogicalVolumeName   
 
(this may take some time depending on number of GBs added to the file system.   
 
(this may take some time depending on number of GBs added to the file system.   
 
   
 
   
- Check the new file system sizes:   
+
* Check the new file system sizes:   
$ df -hT   
+
$ df -hT   
 
You should now see an increased disk space for your primary logical volume.   
 
You should now see an increased disk space for your primary logical volume.   
 
   
 
   
- Reboot and you're set :)
+
* Reboot and you're set :)

Latest revision as of 08:37, 3 March 2016

  1. Connect to the VMware ESXi 5 server using the vShpere Client. Edit the VM's properties to increase the hard disk size (VM has to be off) - I won't get into details on that, if you have the experience on managing ESXi you know what to do... I'm assuming the process is the same for ESXi 4. Now restart the VM.
  1. Login via SSH to the VM and follow this process.
  • First list all partitions:
$ ls -al /dev/sda*  
  • Create new partition using fdisk:
$ fdisk /dev/sda  

Then:

   type p - to list all your partitions  
   type n - to create a new partition  
   type l - for "logical"  
   then give it a number (e.g. if you got 2 partitions listed as /dev/sda1 & /dev/sda2, for the new partition simply type "3"   to create /dev/sda3)   
   type t - to change the partition type to "Linux LVM"  
   provide the partition number you previously created  
   type 8e - for the "Linux LVM" type  
   type p - to list the new partition table  
   type w - to write changes and exit
  • Reboot server:
$ reboot  
  • Assuming you created partition /dev/sda3, let's now create the physical volume in that partition:
$ pvcreate /dev/sda3  

  • Now let's extend the server's Volume Group to that physical volume.
$ vgdisplay  

This will give you the info on your current Volume Group. Note down the entry next to "VG Name". That's your Volume Group name.

$ vgextend EnterVolumeGroupNameHere /dev/sda3  

Keep in mind If you get a message saying /dev/sda3 could not be added to your Volume Group, you need to remove the physical volume and recreate it. Metadata might have gotten corrupt and thus the volume cannot be added to your Volume Group. So just do:

$ pvremove /dev/sda3  

And then again:

$ pvcreate /dev/sda3  

  • Since we're (essentially) extending the main logical volume, let's get the name of that:
$ lvdisplay  

and note down the entry next to "LV Name". This is your logical volume's name (e.g. /dev/srv/root), which you'll now extend to the newly added partition/physical volume.

  • Extend the logical volume by X GBs:
$ lvextend -L +XG yourLogicalVolumeName  

Make sure you replace X above with the actual number of GBs you've added in your VM's settings. So if you increased your VM by 20GBs, the command becomes:

$ lvextend -L +20G yourLogicalVolumeName  

  • Finally, let's resize the file system to the new allocated space:
$ resize2fs yourLogicalVolumeName  

(this may take some time depending on number of GBs added to the file system.

  • Check the new file system sizes:
$ df -hT  

You should now see an increased disk space for your primary logical volume.

  • Reboot and you're set :)