0

I would like to extend /dev/sda2 with the free space on /dev/sda without using a CD.

fdisk -l output

[root@ip126 ~]# fdisk -l

Disk /dev/sda: 26.8 GB, 26843545600 bytes
64 heads, 32 sectors/track, 25600 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00086c7a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       10240     9972736   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 9168 MB, 9168748544 bytes
255 heads, 63 sectors/track, 1114 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 1040 MB, 1040187392 bytes
255 heads, 63 sectors/track, 126 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

pvdisplay output

[root@ip126 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               9.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2434
  Free PE               0
  Allocated PE          2434
  PV UUID               2lmvRB-u3AL-DYAX-2Azh-HsHE-skwW-3hewTE

vgdisplay output

[root@ip126 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.51 GiB
  PE Size               4.00 MiB
  Total PE              2434
  Alloc PE / Size       2434 / 9.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               tp0a2o-Hkup-3V0m-01K1-udfY-Y2l2-gTMHjg

lvdisplay output

[root@ip126 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                9xV22O-69gz-fib7-t3tF-ksqc-LWhj-KLYful
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-05-23 09:31:01 -0400
  LV Status              available
  # open                 1
  LV Size                8.54 GiB
  Current LE             2186
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                0iRAF9-rF8Y-kpn2-rPyV-fnAW-Q2vq-aK2ODT
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-05-23 09:31:02 -0400
  LV Status              available
  # open                 1
  LV Size                992.00 MiB
  Current LE             248
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
2
  1. Make sure that you have up to date backups of the data which you may want to keep. Never mess with filesystems, logical volumes, volume groups, physical volumes and partitions without having a backup of the data.

    Then read and understand the manual pages for the utilities mentioned in this answer. Only proceed when you are confident that you understood the process.

    What you really want is to extend the filesystem. In order to extend the filesystem you must extend the logical volume on which it resides. In order to extend the logical volume you must extend the volume group.

  2. You have two options; you can either make a new physical volume and add it to the volume group, or you can extend the partition and resize the physical volume.

    • Using fdisk or parted or gparted or whatever make a new partition covering the free space on the disk.

    • Create a new LVM physical volume on the new partition using pvcreate. Check that you did it correctly using pvs or pvdisplay.

    • Add the new physical volume to the volume group using vgextend. Check that you did it correctly using vgs or vgdisplay.

    Or, if you prefer, you can extend the partition and the physical volume:

    • Extend the partition to the end of the disk using parted:

      sudo parted /dev/sda resizepart 2 -1s

    • Extend the physical volume to cover the newly extended partition using pvresize.

  3. Extend the logical volume using lvextend. Check that you did it correctly using lvs or lvdisplay.

  4. If needed, extend the filesystem into the newly available space. Use the appropriate utility for the specific filesystem; for example, for Ext4 you would use resize2fs.

  • You could also use the -r flag with lvextend, this would automatically extend the file system at the same time as the lv, removing the requirement to run resize2fs or equivalent command. – Tim Brandrick May 26 '18 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.