#!/bin/bash
# - bof - #



<<'comment'

# - Configured - #


rm -rf ~/.bashrc;
vim ~/.bashrc;

rm -rf ~/.zshrc;
vim ~/.zshrc;

ssh-keygen -R 192.168.1.1

# - On client - #
cd ~/.ssh;
ssh-keygen -t rsa;

cat ~/.ssh/id_rsa.pub;

# - On server - #
vim ~/.ssh/authorized_keys;



xdg-user-dirs-update;
sudo apt install dialog duf curl figlet git lolcat neovim pv webapp-manager -y;
sudo apt install dialog duf curl figlet git htop inxi lolcat net-tools neovim pv webapp-manager -y;

# -  - #
# - Timezone setting - #
sudo timedatectl set-timezone America/New_York;
timedatectl;



cd ~/; rm -rf ~/bEtcher.sh; vim ~/bEtcher.sh;
Copy & paste this content
chmod +x ~/bEtcher.sh; ~/./bEtcher.sh;

comment



The proxmox instance is making backups of my ubuntu server VM and is taking in consideration the empty spaces of the VMs. 
I needed to create a lot of ollama backups for tests and I think that used the space that needed to use for the backups, 
but when I erased the redundant backups and the VM left the empty space in the VMs machine. How do eliminate that empty 
space in the VMs so when proxmox make the VMs backup doesn't see the empty space for the backup?



You are correct—after deleting files inside a VM, Proxmox backups can still be large because the virtual 
disk retains the space previously occupied by those files as "empty space" without telling the underlying 
storage it can be reclaimed . This happens because the VM’s filesystem marks blocks as free, but the virtual 
disk does not automatically shrink. The solution is to use the Discard option combined with the TRIM command 
inside your Ubuntu VM.


⚙️ Step 1: Enable "Discard" on the VM's Hard Disk
First, you need to configure the VM's virtual hardware to pass along discard/TRIM commands.

  Requirements:
    VirtIO SCSI controller

    Shut down your Ubuntu VM (This is strongly recommended for safety).
    In the Proxmox web interface, select your VM, go to Hardware.
    Select the hard disk (e.g., scsi0) and click Edit.

      Discard -> Enable
      SSD Emulation -> Enable for better TRIM support.

    Note on Controller: For these options to work effectively, 
    your VM's disk must be attached to a VirtIO SCSI controller, 
    not the older VirtIO Block .



🖥️ Step 2: Run TRIM Inside the Ubuntu VM
Now, go inside your running Ubuntu VM and tell it to scan the filesystem 
and inform the virtual disk which blocks are truly empty.

    Open terminal in uServer.

    sudo fstrim -av;

    This command checks all mounted filesystems that support discard and sends 
    the "unused blocks" information down to the Proxmox host .



📉 Step 3: Verify the Effect on Proxmox Storage
After running fstrim, the change should be reflected in your Proxmox storage.

    Go to Datacenter > Storage > your_storage (e.g., local-lvm).
    You should see the "Used" space for your VM's disk decrease immediately.

    Your next Proxmox backup will now be significantly smaller, 
    as it will no longer read and store those blocks of "empty space" .



📌 Troubleshooting & Common Issues
If you don't see the space reclamation you expected, check the following:

    If your disk is RAW format on LVM: 
      The fstrim command will free space at the storage level, 
      but it might not show up in the backup size due to how LVM handles snapshots. 
      The space will be usable, but the backup may still read the full allocated size.

    If fstrim doesn't work: Double-check that the Discard option is enabled. 
    A quick way to test if TRIM commands are passing through is to run the following 
    on your Proxmox host while the VM is running after a manual fstrim:
    
    Proxmox terminal:

    qm status <VMID> -verbose | grep running;

    (Look for any block statistics indicating writes, though this is more for verification).

    Automating the process: You can set up a weekly fstrim using a systemd timer to keep space automatically reclaimed. 
    In uServer terminal:
    
    ssh into uOllama

      sudo systemctl enable fstrim.timer
      sudo systemctl start fstrim.timer

Once you've completed these steps, your future backups will be lean and efficient, 
ignoring the empty space you cleared out.



# - eof - #