Skip to content

Instantly share code, notes, and snippets.

@levid0s
Last active April 13, 2024 10:39
Show Gist options
  • Save levid0s/738fda1e099370bacab6bff1ec294e59 to your computer and use it in GitHub Desktop.
Save levid0s/738fda1e099370bacab6bff1ec294e59 to your computer and use it in GitHub Desktop.
Proxmox Extend Host Disk
###
### Extend Host Disk Partition
###
# https://command-not-found.com/growpart
# https://forum.proxmox.com/threads/change-host-disks-how-resize-partition.90729/
apt-get install cloud-utils
growpart /dev/sda 3
pvresize /dev/sda3
# Extend Data LVM-Thin
lvextend -l +50%FREE pve/data
# Extend Root "Directory"
lvextend -L +20G pve/root
resize2fs /dev/pve/root
###
### Extend VM Disk
###
# https://pve.proxmox.com/wiki/Resize_disks#qm_command
GUI: VM > Hardware > Hard Disk > Disk Action > Resize
# - or -
qm disk resize <vmid> <disk> <size>
qm disk resize 100 virtio0 +5G
# VM should auto extend the disk locally after a reboot.
# Other ways to extend but not the best: v
# Don't forget to ensure there's enough space on lvm-thin
lvextend -L +12.7G /dev/pve/vm-100-disk-1
# Resize2f needs to be run from inside the VM
# In the case of HomeAssistant, the disk gets extended automatically at boot.
###
### Disk Management 101
###
# https://www.tecmint.com/extend-and-reduce-lvms-in-linux/
fdisk -l /dev/sda
lsblk
pvs
pvs --segments -v
pvscan
vgs
vgdisplay
lvs
lvs -v
lvs --segments (-v)
lvdisplay
lvdisplay -m # show Segments
lvdisplay /dev/pve/vm-100-disk-1
sfdisk -l /dev/pve/vm-100-disk-1
sfdisk -d /dev/pve/vm-100-disk-1
# Extend Volume Group size
vgextend vg_tecmint /dev/sda1
pvcreate /dev/sda1
# Check fs for errors
e2fsck -n /dev/pve/vm-100-disk-1 # Don't make changes
e2fsck -ff /dev/vg_tecmint_extra/tecmint_reduce_test
# lvextend is used specifically to increase the size of a logical volume.
lvextend -L +20G /dev/vgname/lvname
# Reducing size
lvreduce --resizefs -L 7.2G /dev/pve/vm-100-disk-1
lvreduce -L -8G /dev/vg_tecmint_extra/tecmint_reduce_test
# lvresize: Can increase & decrease. Very versatile but dangeruos!
lvresize -L -20G /dev/vgname/lvname # reduce size with 20GB
# List VM disk partitions
sfdisk -l /dev/pve/vm-100-disk-1
# Backup VM partition table
sfdisk -d /dev/pve/vm-100-disk-1 > partition-table-backup.txt
# Restore VM partition layout
sfdisk /dev/pve/vm-100-disk-1 < partition-table-backup.txt
# LVM Table Backups
ls -l /etc/lvm/archive
# Manual Backup
vgcfgbackup -f /root/current_pve_config.vg pve
# Restore
vgcfgrestore -f /etc/lvm/archive/pve_00013-1137415304.vg pve
# Deactivate LVM Disk (useful before backup/restore VG or partition table)
lvchange -an /dev/pve/vm-100-disk-1
# Reactivate LVM Disk
lvchange -ay /dev/pve/vm-100-disk-1
# Create & Delete VM disk
lvcreate -L <Size> -n vm-101-disk-0 pve
dd if=/path/to/vm-101-disk-0.img of=/dev/pve/vm-101-disk-0 bs=4M # Restore data to disk
lvremove /dev/pve/vm-101-disk-0-snapshot
###
### Backup & Restore VM disk to Image
### [ Manual mode, not recommended ]
###
# Backup VM disk to image file
dd if=/dev/pve/vm-101-disk-0 of=/var/lib/vz/images/vm-101-disk-0.img bs=4M
# Restore
lvcreate -L 2G -n vm-101-disk-0 pve
dd if=/root/vm-101-disk-0.img of=/dev/pve/vm-101-disk-0 bs=4M
###
### VM & LXC Configuration
###
vim /etc/pve/nodes/dell-5070/qemu-server/100.conf
# ^- disk size configured here
vim /etc/pve/nodes/dell-5070/lxc/101.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment