How can I extend disk space (logical and physical) on Ubuntu 14.04?

I have a Linux Virtual Machine Server with Ubuntu 14.04, without free space, and I want to extend my disk.

$ df -h
File system                   Dim. Usati Dispon. Uso% Montato su
/dev/root                      21G   20G    1,3M 100% /
none                          4,0K     0    4,0K   0% /sys/fs/cgroup
udev                          2,0G  4,0K    2,0G   1% /dev
tmpfs                         396M  924K    395M   1% /run
none                          5,0M     0    5,0M   0% /run/lock
none                          2,0G     0    2,0G   0% /run/shm
none                          100M     0    100M   0% /run/user
/dev/sda1                     236M   39M    185M  18% /boot

I added 15Gb to physical disk, but I cannot add to logical volume.

With parted I can see the free space:

Modello: VMware Virtual disk (scsi)
Disco /dev/sda: 37,6GB
Dimensione del settore (logica/fisica): 512B/512B
Tabella delle partizioni: msdos

Numero  Inizio  Fine    Dimensione  Tipo      File system    Flag
        32,3kB  1049kB  1016kB                Free space
 1      1049kB  256MB   255MB       primary   ext2           boot
        256MB   257MB   1048kB                Free space
 2      257MB   26,8GB  26,6GB      extended
 5      257MB   26,8GB  26,6GB      logical                  lvm
        26,8GB  37,6GB  10,7GB                Free space

Output of lsblk command:

NAME                          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                             8:0    0    35G  0 disk 
├─sda1                          8:1    0   243M  0 part /boot
├─sda2                          8:2    0     1K  0 part 
└─sda5                          8:5    0  24,8G  0 part 
  ├─--vg-root (dm-0)   252:0    0  20,8G  0 lvm  /
  └─vg-swap_1 (dm-1) 252:1    0     4G  0 lvm  [SWAP]
sr0       11:0    1  1024M  0 rom  

To extend the virtual disk I try this way:

 $ sudo lvextend -L+10G /dev/root
      Extending logical volume root to 30,76 GiB
      Insufficient free space: 2560 extents needed, but only 0 available

I think that the problem is to see the unmount free space added.

What's wrong?


Solution 1:

Try these steps:

  1. To check if you have some free space: sudo parted
  2. Then run cfdisk to create a new partition (primary or logical), so choose write and then restart your server
  3. Check your new partition: fdisk -l /dev/sda
  4. We suppose that your new partition is sda3, so create the physical volume: pvcreate /dev/sda3
  5. pvdisplay to show the physical volumes
  6. vgextend YOUR_VOLUME_GROUP /dev/sda3 then if you want check it lvdisplay
  7. lvextend -l+100%FREE /dev/YOUR_VOLUME_GROUP/root
  8. resize2fs /dev/mapper/YOUR_VOLUME_GROUP-root

finally check you new space: df -h