2

I have a headless Ubuntu server install inside a VM, running on Hyper-V using lvm. I have full access to the VM, but no access to the Hyper-V environment (so can't boot with a LiveCD).

I need to expand my filesystem as I've already eexpanded my physical disk at the virtual level, but am having issues as sda1-5 are already in use.

Is there anything I can do to make use of the space assigned to the server but not used?

My mounted volumes:

root@SRVLIN01:~# mount | grep --regexp "^//[0-9]" --regexp "^/dev"
/dev/mapper/SRVLIN01--vg-root on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
/dev/sda1 on /boot type ext2 (rw,relatime,block_validity,barrier,user_xattr,acl,stripe=4)
root@SRVLIN01:~#

My logical volumes:

root@SRVLIN01:~# lvdisplay --maps
  --- Logical volume ---
  LV Path                /dev/SRVLIN01-vg/root
  LV Name                root
  VG Name                SRVLIN01-vg
  LV UUID                0GWjvA-b7H7-nLqX-TOtV-VNdR-QFT3-nhucpd
  LV Write Access        read/write
  LV Creation host, time SRVLIN01, 2017-05-04 09:40:59 +0100
  LV Status              available
  # open                 1
  LV Size                117.51 GiB
  Current LE             30083
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Segments ---
  Logical extents 0 to 14722:
    Type                linear
    Physical volume     /dev/sda5
    Physical extents    0 to 14722

  Logical extents 14723 to 14725:
    Type                linear
    Physical volume     /dev/sda5
    Physical extents    15234 to 15236

  Logical extents 14726 to 30082:
    Type                linear
    Physical volume     /dev/sda4
    Physical extents    0 to 15356


  --- Logical volume ---
  LV Path                /dev/SRVLIN01-vg/swap_1
  LV Name                swap_1
  VG Name                SRVLIN01-vg
  LV UUID                KFFa26-3GQY-Fbc3-QIU2-BdRe-h7Af-s16fKE
  LV Write Access        read/write
  LV Creation host, time SRVLIN01, 2017-05-04 09:40:59 +0100
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             511
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

  --- Segments ---
  Logical extents 0 to 510:
    Type                linear
    Physical volume     /dev/sda5
    Physical extents    14723 to 15233

My physical volumes:

root@SRVLIN01:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               SRVLIN01-vg
  PV Size               59.52 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              15237
  Free PE               0
  Allocated PE          15237
  PV UUID               ljFlcO-kfjd-bx2d-74DJ-BY3S-zoKM-dBmfiJ

  --- Physical volume ---
  PV Name               /dev/sda4
  VG Name               SRVLIN01-vg
  PV Size               60.00 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              15360
  Free PE               3
  Allocated PE          15357
  PV UUID               WY90Op-u2Bz-nVTf-D2ed-q4Zu-lEgW-e4ZLfY
Fabby
  • 34,259
c-hri-s
  • 23
  • Welcome to [ubuntu.se]! :-) sda3-sda5 are not mounted. What is preventing you from shrinking sda4 and adding its space to sda5? 0:-) – Fabby Jul 10 '19 at 19:22
  • Thanks :-)

    The honest answer is because I don't know how to ..I'm not even sure how you've determined that sda3-5 aren't mounted?

    – c-hri-s Jul 12 '19 at 07:49
  • I can't see sda3-5 in df -h, so assuming they're not mounted. and sda2 is just an extended partition. Please [edit] your question and provide the output to mount | grep --regexp "^//[0-9]" --regexp "^/dev", then leave a comment @Fabby – Fabby Jul 12 '19 at 08:57
  • I added that data to the original post, thanks – c-hri-s Jul 17 '19 at 07:28
  • Oh, I get it what you're trying to do. Answer coming up. – Fabby Jul 17 '19 at 11:17
  • Thank you for the acceptance! Favour returned and question upvoted. (Under VMWare I would have been able to tell you that you can mount an ISO through vCenter and boot from there, but I don't know Hyper-V, so sorry about that.) – Fabby Jul 22 '19 at 12:06

1 Answers1

2

You are running in a Virtual Machine (VM) using lvm: Logical Volume Manager and the only unused physical partition not under its control is /dev/sda3 which is just 1MB, so that won't help you much.

lvm is really great at handling multiple kinds of storage and can combine multiple disks into one Physical Volume (PV) which can then be (re-)assigned as you need them.

However, you have allocated all (except 1MB) of your physical disks, so now you only have these choices:

  1. add another disk

    • Don't expand existing mounted disks that you cannot dismount to expand in the future.
    • never assign 100% of your disks so you can extend your existing Physical Volumes on the free space you now have with your new disk.
  2. Alternatively, mount a gparted live ISO from within grub if your Hyper-V environment gives you access to that.

    • Take a full snapshot of your VM!!!
    • Download the gparted live iso
    • copy it in /opt/LiveISOs

      sudo mkdir /opt/LiveISOs
      sudo cp ~/Downloads/gparted-live-1.0.0-3-amd64.iso /opt/LiveISOs
      
    • edit /etc/grub.d/40_custom to include the following at the end:

      menuentry "GParted Live ISO" {
        set ISOFile="/opt/Live-ISOs/gparted-live-1.0.0-3-amd64.iso"
        loopback loop ($root)$ISOFile
        linuxefi (loop)/live/vmlinuz boot=live components config findiso=$ISOFile ip=frommedia toram=filesystem.squashfs union=overlay username=user
        initrdefi (loop)/live/initrd.img
      }
      
    • set grub's timeout parameter to anything but 0
    • update the grub config:

      sudo update-grub2
      
    • Reboot to grub

    • Take menu option GParted Live ISO

    Voilà: a virtual USB key has been inserted in your VM virtually and you can now shrink / expand partitions off-line using gparted or using lvm utilities from the command line!

#2 above will not work if the only thing you have is ssh access to your VM...

Fabby
  • 34,259
  • The server is on a virtual host. Within that we have expanded the size of the disk, however we need to expand the partition to make use of that:

    [Disk /dev/sda: 160 GiB, 171798691840 bytes, 335544320 sectors]

    That's where I'm stuck as all the advice I read online talks about either using a LiveCD or creating a new partition in the unused space, which I can't do as I've used all five already.

    – c-hri-s Jul 19 '19 at 08:20
  • @c-hri-s All intermediate comments deleted so that the Q & A can stand all by themselves for the next person that runs into the same issue as you. – Fabby Jul 22 '19 at 12:07