Linux Host, deleting disk

Discussions about using Linux guests in VirtualBox.
Post Reply
Host2626
Posts: 4
Joined: 29. Apr 2015, 09:01

Linux Host, deleting disk

Post by Host2626 »

Hello,

I have a Linux OEL 7.4 host on a Windows 10 PC. I have two dynamic disks, *-disk2.vmdk and *-disk3.vmdk that are too large and I'd like to shrink them, or maybe even remove and re-create. I've googled a bit but am only finding hints about how to remove them from the interface, or tricks with zerofree+VBoxManage that I can't use since my disks are formatted with LVM, one PV and one VG and one LV on each.

I've tried to vgremove and pvremove on each of them, but then linux won't boot with the 3 vmdk still attached to the VM, it gets stuck in rescue mode. Predictably, simply removing the disks in the VirtualBox interface has the same results.

Any ideas?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Linux Host, deleting disk

Post by mpack »

Host2626 wrote: I have a Linux OEL 7.4 host on a Windows 10 PC.
The host is the physical PC. I think you have a Windows 10 host and a Linux guest. So, moving this topic to "Linux Guests" because I don't think any of the issues involved relate to the host or even to VirtualBox.

AFAIK you can't shrink LVM disks, not in any useful sense anyway. The very concept of a discrete disk is downplayed in LVM. I can't even think of a workaround - unless you count: offload important files, then delete the VM and start again.

I would never choose anything like LVM myself, so I'm curious: how would it cope with the loss of a physical drive? I assume there is no RAID5-like redundancy across drives.

In any normal filesystem with identifiable partitions, you would first use a partition manager to shrink the partition. You'd then move the partition image onto a smaller drive. I don't think those concepts apply to LVM, but I could be wrong.
Host2626
Posts: 4
Joined: 29. Apr 2015, 09:01

Re: Linux Host, deleting disk

Post by Host2626 »

Yes, Linux GUEST, sorry about that.

LVM would cope with the loss of a physical drive the same way as it would for a non-LVM disk. But I am not trying to make it lose a disk. I've worked plenty with LVMs at the office. , but there is something here that I don't understand. Normally you remove a volume group then a physical disk with a vgremove and pvremove. Technically LVM doesn't even need or even know of that /dev/sdc. On other systems, not virtualbox, after that I can physically remove the hard drive and all will be well. But here after a pvremove the OS is stuck in recovery mode, even though the vmdk is still part of the machine config in settings.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Linux Host, deleting disk

Post by mpack »

I don't know what your problem is, since as mentioned I don't use LVM myself, but I can tell you that the guest OS is not modifying it's behaviour because it's running in a VirtualBox VM, because it has no idea that is the case. Nor could any VirtualBox bug affect data structures that the guest OS writes to the disk (if such a bug existed then all of us would know). So if you were thinking in terms of VirtualBox bugs, I'd say to stop, and think instead about configuration issues, or issues with identifying which disks are which (e.g. if the drives were cloned and then more than one such clone is attached to a single VM).
fth0
Volunteer
Posts: 5678
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Linux Host, deleting disk

Post by fth0 »

Host2626 wrote:I have two dynamic disks, *-disk2.vmdk and *-disk3.vmdk that [...] are formatted with LVM, one PV and one VG and one LV on each.
I don't understand this part of your setup, especially the mismatch between two virtual disk images and one PV. Or do you mean that you simply have two independent virtual disk images?

If I wanted to experiment with LVM, I would create a VM with two virtual disk images, which are the equivalent of two physical hard disks, and possibly partition them. Then I would take some of those partitions or whole disks, create PVs from them, combine the PVs to a VG, and then create LVs inside of this VG. In this case I'd have no less than two PVs.

In any case, if you shrink the LVs, create an additional LV, fill it with zeros and remove it again, convert the VMDK images to dynamically allocated VDI images and then compact them, you should get what you want. If the virtual disk images have sectors that no OS is ever going to write to (again), they will never need space on you disk drive (again).

If I didn't understand your problem correctly, please try and explain it in more detail, especially the layout of the VMDKs, PVs, VGs and LVs.
mooren
Posts: 1
Joined: 9. Apr 2020, 16:56

Re: Linux Host, deleting disk

Post by mooren »

What's the file system for your LVM ? XFS is the default (and might be the only file system you can have. . ).

You can't run zerofree on the LVM/XFS, look at the centos forums, topic 59546 (I can't post links, even though I've have had an oracle acct for a while :/ )

There are hints from stack exchange (super user dot com) titled "how-to-compact-virtualboxs-vdi-file-size" / question 529149 , one answer gives specific LVM instructions. That said, I have not had luck running fstrim in my VM :(
Post Reply