/dev/sda1 not in a volume group, and vgextend doesn't work

13,993

Solution 1

Whilst I have no beef with either of the existing answers, I'm not sure I see any reason to complicate this with LVM, given that you don't currently have it. If you're not planning on doing an extension like this again, it may not be worth the pain of introducing LVM now.

An alternative, which is fiddly but doesn't involve rebuilding the machine unless you stuff it up, is to:

  1. Roll back the LVM setup you've done, then do a complete backup
  2. Delete the partition /dev/sda3
  3. Stop the existing swap space with swapoff, then delete the /dev/sda[25] partitions
  4. Recreate the /dev/sda1 partition to span all the existing disc, less some swap space at the top. Do not change the start block of the partition.
  5. Create a /dev/sda2 at the top of the disc, tag it swap, make sure your /etc/fstab reflects the change from sda5 to sda2.
  6. Reboot, then use resize2fs to grow the root file system in situ to fill the new, larger /dev/sda1.

Solution 2

At this specific time and with how you've described your setup, I'm afraid that the answer is "sorry, can't be done". At least not in the way you describe it.

But the real question isn't "how can I extend sda1" - it's "how can I increase the space available for my users given that the server was installed without volume groups". That is a question that can be answered in several ways. I'm giving you two answers that don't involve e.g. a NAS/SAN or other external storage system.

Before you do any of the below, make sure that you have a current backup of your system. Be aware that there will be downtime involved!

The easy way is to look at what directories exist on the current /dev/sda1 disk. You may have e.g.

/var
/home
/usr

all on the same disk. One thing you can do is to copy all data from e.g. /home to the new disk, and then mount that new disk as /home. (This obviously needs to be done at a time that there are no users logged on to the machine - preferably, it should be booted in single user mode!)

When the copying is finished, reboot the system with /dev/sda3 mounted as /home. Verify that everything works as designed. Then unmount /dev/sda3 and delete all directories under /home on the old disk.

The downside is that you will now be locked into a limited amount of space, except that now you have two non-extendable disks instead of one, so it will take a while before you hit the ceiling next time.

Edited the below since /boot is on /dev/sda1 so the original solution doesn't work.

The harder way is to do a reinstall. When reinstalling, create a VG on /dev/sda3 only. Don't partition or touch /dev/sda1 in any way.

Once the system is up, you mount /dev/sda1 on a new mountpoint (e.g. /mnt/olddisk). Then copy all data from that disk (this should be everything except the actual operating system). Once that is done, you can extend the VG onto the old /dev/sda1. You will now have a system that can be extended by adding more disks to the volume group.

Solution 3

You can only create or extend LVM volume groups onto physical volumes.

To resolve the issue, create an LVM physical volume on the desired partition.

pvcreate /dev/sda1

NOTE: This operation destroys all data on the named partition.

You can then extend the volume group onto the physical volume.


(And you probably don't mean /dev/sda1 because that's usually the /boot partition. Since this is destructive, be absolutely sure what you're doing.)

Share:
13,993

Related videos on Youtube

steffen
Author by

steffen

Updated on September 18, 2022

Comments

  • steffen
    steffen over 1 year

    I've got several virtual machines which I access through a VMWare vSphere client (v 5.1.0). One ran out of space and I'm trying to give it some more space.

    What I've done so far:
    - Increased provisioned size using "Edit Settings" in the "Summary" tab.
    - Created a new partition (/dev/sda3) with Linux LVM system.

    The problem is that there's no volume group on the machine earlier, so I can't follow the normal tutorials that tells me to just

    vgextend VolGroup00 /dev/sda1
    

    when I do, I get the error:

    No physical volume label read from /dev/sda1
    Can't open /dev/sda1/ exclusively. Mounted filesystem?
    Unable to add physical volume '/dev/sda1' to volume group 'VolGroup00'.
    

    I've googled all day, but can't find out how to add /dev/sda1 to my volume group. It's not in any volume group at all...

    Anyone got any hints or pointers?

    EDIT: Some additional data:

    # fdisk -l
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    255 heads, 63 sectors/track, 5221 cylinders
    Units = cylinders of 16065 * 512 = 822580 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optional): 512 bytes / 512 bytes
    Disk identifier: 0x000d2064
    
    Device    Boot Start   End    Blocks   Id  System
    /dev/sda1   *      1  1998  16043008   83  Linux
    /dev/sda2       1998  2089    731137    5  Extended
    /dev/sda3       2089  5221  25161490+  8e  Linux LVM
    /dev/sda5       1998  2089    731136   82  Linux swap / Solaris
    
    
    # df -h
    Filesystem  Size  Used  Avail  Use%  Mounted on
    /dev/sda1    16G   14G   754M   95%  /
    tmpfs       4.0G     0   4.0G    0%  /lib/init/rw
    udev        4.0G  104K   4.0G    1%  /dev
    tmpfs       4.0G     0   4.0G    0%  /dev/shm
    
    
    # lbslk
    -bash: lsblk: command not found
    
    
    # pvs
    PV         VG           Fmt  Attr   PSize   PFree
    /dev/sda3  VolGroup00  lvm2  a-     23.99g  23.99g
    
    
    # vgs
    VG          #PV  #LV  #SN  Attr    VSize   VFree
    VolGroup00    1    0    0  ws--n-  23.99g  23.99g
    
    
    # lvs
    #
    (no output)
    
    • steffen
      steffen over 10 years
      He'll be back at the office tomorrow, gonna run an interrogation then :) But you're saying we basicly have to do a complete reinstall to increase the disk size since it's already in use?
    • Michael Hampton
      Michael Hampton over 10 years
      Or migrate the existing data into a new LVM LV, but it's effectively a reinstall anyway since you have to be down. So you may as well reinstall and do it right (hint: Guided - use entire disk and set up LVM).
    • MadHatter
      MadHatter over 10 years
      Just for completeness, could you edit into your question the outputs of pvs, vgs, and lvs? I see an LVM partition, but it's not clear that there's anything under LVM control right now. And can you confirm I'm right in thinking that you always had /dev/sda, but it's recently got bigger - which is the space you've declared as /dev/sda3?
    • steffen
      steffen over 10 years
      Michael Hampton: That's what I was leaning towards anyways, but wanted to check here if anyone knew a quicker fix. Thanks for all your help. MadHatter: Done. And yes, your assumtions are correct.
  • steffen
    steffen over 10 years
    First of all, thanks for taking a look at my issue. Second, I do mean /dev/sda1, but this is the volume I'm trying to extend. If this is a physical volume or not, I'm not sure. These are all virtual machines, so I'm not 100% sure how vSphere treats them. I'm assuming the diskspace provisioned on first installation went into creating /dev/sda1 and treating it as a physical volume. What I'm trying to do now is to extend it with the additional provisioned space I've put in /dev/sda3. However, without volume groups it seems I can't.
  • Michael Hampton
    Michael Hampton over 10 years
    If your extra space is in /dev/sda3 then that's what you want to use.
  • steffen
    steffen over 10 years
    /dev/sda1 has only 16GB and is 99% full, /dev/sda1 has additional space and is 0% empty. My question is this: how can I extend /dev/sda1 to get the additional space from /dev/sda3? Basicly...how do I use it? I might be missing something obvious (and some caffeine), but I really appriciate any help.
  • Michael Hampton
    Michael Hampton over 10 years
    Perhaps you should (edit your question and) explain how the filesystems are currently set up.
  • steffen
    steffen over 10 years
    On it. What information do you need? I'm usually a Windows guy.
  • Michael Hampton
    Michael Hampton over 10 years
    The output of lsblk should be sufficient, I think.
  • steffen
    steffen over 10 years
    Running Debian and the util-linux package doesn't contain lsblk
  • Michael Hampton
    Michael Hampton over 10 years
    You forgot about /boot, which he still has under / and not in a separate partition. This just makes it even more complicated.
  • Jenny D
    Jenny D over 10 years
    grf So I did. Fixing the answer...
  • steffen
    steffen over 10 years
    So basically I install the OS on /dev/sda3 now that it's in a VG and boot up that, leaving /dev/sda1 available to add with vgextend?
  • Jenny D
    Jenny D over 10 years
    Almost - what you do is when you install, you create the VG during the installation process (as should have been done from the start). That is if you want the disk to be extendable in the future - otherwise go with @MadHatter's answer instead.
  • steffen
    steffen over 10 years
    Thanks for the suggestion! We might end up doing this, but as I prefer scalability I'm leaning towards just introducing LVM as soon as possible.
  • MadHatter
    MadHatter over 10 years
    As long as his VPS provider only ever makes a bigger sda available, both solutions are equally extensible. I do think LVS is a good skill for the OP to master in the long run, though.
  • Random
    Random over 8 years
    You may also have to change type of sda2 (in fdisk) while recreating swap (t => 82 => w) then reboot. Worked like a charm for me.