3

I want to run an idea by you... I have an Ubuntu 16.04.3 with an LVM on a second drive I would like to extend. I want to complete this only using this CLI, no GUI. I have put my steps below how I complete this using gparted, if we can mimic these steps in the CLI.

I think what I am missing is honestly just whatever is the CLI equivalent to "Right-Click and extending it in gparted"

Here is a quick over of my setup view. In attempt to save some time and space I shortened some items. My steps will follow:

fdisk:

Disk /dev/sdb: 170 GiB, 182536110080 bytes, 356515840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7fbfd5c7

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sdb2       1001470 293601279 292599810 139.5G  5 Extended
/dev/sdb5       1001472 293601279 292599808 139.5G 8e Linux LVM


Disk /dev/mapper/nextcloud--vg-root: 137.5 GiB, 147660472320 bytes, 
288399360 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/nextcloud--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 
sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

vgdisplay:

  --- Volume group ---
  VG Name               nextcloud-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  7
  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               139.52 GiB
  PE Size               4.00 MiB
  Total PE              35717
  Alloc PE / Size       35717 / 139.52 GiB
  Free  PE / Size       0 / 0
  VG UUID               huX2Hk-jG98-HieD-bAuV-Z0Wi-mAMi-nRGwDI

lvdisplay:

  --- Logical volume ---
  LV Path                /dev/nextcloud-vg/root
  LV Name                root
  VG Name                nextcloud-vg
  LV UUID                TPebe1-nMhS-5kse-OR9G-IlGA-CBIc-QERaVE
  LV Write Access        read/write
  LV Creation host, time nextcloud, 2016-07-27 13:27:51 -0400
  LV Status              available
  # open                 2
  LV Size                137.52 GiB
  Current LE             35205
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/nextcloud-vg/swap_1
  LV Name                swap_1
  VG Name                nextcloud-vg
  LV UUID                90e1zB-ZuSK-2wiV-webN-55Of-fD6H-8ex5M7
  LV Write Access        read/write
  LV Creation host, time nextcloud, 2016-07-27 13:27:52 -0400
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

cat /proc/mounts | grep '^/':

  /dev/mapper/nextcloud--vg-root / ext4 rw,relatime,errors=remount ro,data=ordered 0 0
  /dev/sda1 /boot ext4 rw,relatime,data=ordered 0 0

pvs:

  PV         VG           Fmt  Attr PSize   PFree
  /dev/sdb5  nextcloud-vg lvm2 a--  169.52g    0   

All of this appears simple enough:

  1. Boot to an ISO
  2. Run gparted
  3. Right-click "Deactivate" /dev/sdb5 (Sometimes I have to click this 2 or 3
  4. times to make the key actually go away and allow changes. No errors are ever thrown) < Is this normal?
  5. Click "Apply"
  6. Right-click, resize/move and extend the partition /dev/sdb2,
  7. Right-click resize/move and extend the partition /dev/sdb5
  8. Click "Apply"
  9. lvextend –l +​100%FREE /dev/nextcloud-vg/root
  10. reboot the machine
  11. resize2fs /dev/nextcloud-vg/root

And I'm good.

EDIT - 1/3/18

If I try and accomplish the same thing through fdisk and CLI I cannot create the logical partition from the same sector. Details below

root@nextcloud:/home/ncadmin# fdisk /dev/sdb

Command (m for help): d
Partition number (2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (1-4, default 1): 2
First sector (2048-367001599, default 2048): 1001470
Last sector, +sectors or +size{K,M,G,T,P} (1001470-367001599, default         367001599):

Created a new partition 2 of type 'Extended' and of size 174.5 GiB.

Command (m for help): n
Partition type
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (1003518-367001599, default 1003520):
Last sector, +sectors or +size{K,M,G,T,P} (**1003520**-367001599, default     367001599):
11
  • "with an LVM on a second drive" No, there's only one LVM and it's in the OS. Dec 4, 2017 at 18:31
  • Only extending the partitions needs to be done with an external boot. The rest has been doable inside the OS for... at least the better part of a decade. Dec 4, 2017 at 18:34
  • @IgnacioVazquez-Abrams I mean second drive as in a second "physical" disk in VMware. /dev/sda just holds the MBR . I am good with booting to an ISO, no quarrels there. I would just like to do this without gparted...
    – ahoward
    Dec 4, 2017 at 19:46
  • So then use fdisk. Or sfdisk. Or whatever it is the cool kids are using these days. Dec 4, 2017 at 19:47
  • I would if I understood how. If I try and use fdisk or cfdisk, there isn't an extend option. From I have read you can just delete the partition, then create new one, then write the changes. However, that deletes the lvm /dev/sda5.
    – ahoward
    Dec 4, 2017 at 20:55

1 Answer 1

-1

umount the partition

umount /dev/sdb5

change the size of /dev/sdb2 and sdb5 (or use fdisk; https://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/ )

cfdisk /deb/sdb

navigate with to delete sdb2 and sdb5.

Now you have to create a new (larger) extendet partition, sdb2 with the same start sector 1001470 (default value) and the new maximum size (default value). Create now a new sdb5 inside of the new sdb2 and use in your case again the default values. Change the type of sdb5 to 8e (linux lvm). Until you don't use write is nothing changed on your disk. After the changes, write it down to disk.

reload the partition tables with

partprobe

load/scan the lvm in your live system with (probably done automaticly by your system)

pvscan --verbose
vgscan --verbose
lvscan --verbose

now you can extend your physical volume for lvm with

pvresize --verbose /dev/sdb5

now you should see the new free PE with vgdisplay, if not scan again. And now you can do the last step, resize your logical volume.

lvextend --resizefs -l +100%FREE --verbose /dev/nextcloud-vg/root
reboot
6
  • Ok thanks for the reply! I was apparently missing the idea of deleting the partition and re-creating it bigger. I am now running into an issue where I cannot create the logical partition at the correct sectors. I use fdisk /dev/sdb > delete sdb2 > create a new extended partition at sector 1001470 (not the default value) which works fine. However, when I go to create the logical partition I do not get the option of creating it at 1001472 (my current start sector) I only have the option to start it at sector 1003518.
    – ahoward
    Jan 3, 2018 at 21:45
  • @FaxMaxAdded a copy and paste from my CLI as an edit at the end of my original post
    – ahoward
    Jan 3, 2018 at 21:57
  • @ahoward i dont have a idea why you cant do it. But you can extend your lvm if you simple create a new primary partition /dev/sdb3 and add this device to your logical volume group.
    – FaxMax
    Jan 12, 2018 at 11:36
  • @FaxMaxI appreciate all the input. I understand I could extend the volume group over to another primary partition but those are limited.
    – ahoward
    Jan 12, 2018 at 18:40
  • 1
    It does not have to be a primary partition: LVM can use logical partitions just fine.
    – telcoM
    Jul 24, 2019 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .