Quantcast
Channel: LVM: How to enlarge the extended partition without data loss? - Super User
Viewing all articles
Browse latest Browse all 3

Answer by user3201982 for LVM: How to enlarge the extended partition without data loss?

$
0
0

I have figured out a practical way to expand my disk, on Ubuntu 12.04 LTS. Perhaps you have noticed that this server has already enabled LVM. That's why the extended partition (sda2) overlaps exactly with the logical partition (sda5).

Firstly I use the 'parted' command to resize the extended partition (sda2), make it full of all the physical disk.

resize NUMBER START END  //NUMBER stands for partition number

Then there is free space for another logical partition, say sda6, inside the extended partition sda2.

See picture, Is there something wrong with my disk partition?

Use 'fdisk' to create a new logical partition. (Choose l instead of p, change type id to 8e, stands for LVM)

Reboot.

Then we begin to configure the LVM. Use 'pvcreate' to create a physical volume by sda6.

'pvdisplay' to show the current physical volumes.

pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               host02-vm-vg
  PV Size               19.76 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5058
  Free PE               0
  Allocated PE          5058
  PV UUID               RsGi6C-g0lm-SzJ1-9rw4-dMEi-Q633-9wo1Gd

  --- Physical volume ---
  PV Name               /dev/sda6
  VG Name               host02-vm-vg
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               194
  Allocated PE          4925
  PV UUID               fFhQbB-L59C-2nE9-Yuo6-CUAr-y6mD-HOMfzQ

Because this server enabled LVM when it was setting up, so when type in 'vgdisplay' and 'lvdisplay', you should see an existing volume group and a logical volume,

02@02-vm:~$ sudo vgdisplay
  --- Volume group ---
  VG Name               02-vm-vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               39.75 GiB
  PE Size               4.00 MiB
  Total PE              10177
  Alloc PE / Size       9983 / 39.00 GiB
  Free  PE / Size       194 / 776.00 MiB
  VG UUID               GFrHkW-EZFQ-vuCo-b4Pp-F1Lm-FV8B-NcbMmD


  02@02-vm:~$ sudo lvdisplay
  --- Logical volume ---
  LV Name                /dev/02-vm-vg/root
  VG Name                02-vm-vg
  LV UUID                vC3dCP-ynJq-qwbf-ZwwX-T1ca-tOo6-5FYVNg
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                37.00 GiB
  Current LE             9472
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

What's left here could be very easy to understand.

vgextend - add physical volumes to a volume group
lvresize - resize a logical volume

Finally you need to resize your filesystem to utilize the new free space from LVM.

resize2fs - ext2/ext3/ext4 file system resized

df:

vm:~$ df
Filesystem                        1K-blocks    Used Available Use% Mounted on
/dev/mapper/02--vm--vg-root  38057472 3501084  32802424  10% /
udev                                1011124       4   1011120   1% /dev
tmpfs                                204196     500    203696   1% /run
none                                   5120       0      5120   0% /run/lock
none                                1020968       0   1020968   0% /run/shm
cgroup                              1020968       0   1020968   0% /sys/fs/cgroup
/dev/sda1                            240972   34482    194049  16% /boot
/dev/loop0                          4872572   32928   4839644   1% /srv/node/vdb

As you can see here, my filesystem is mounted on /dev/mapper/02--vm--vg-root (logical volume). So we need to resize this volume to the maximum.

Reboot, then all done. ^_^


Viewing all articles
Browse latest Browse all 3

Trending Articles