Hi,
I have an old broken proxmox system, with a few good VMs and CTs to save and a bunch that I don't remember what they are...
So I need an easy way to mount them and unmount them.
And I didn't want to inspect them on what was inside, just single command that takes care of sole partitions or multiple partition volumes.
So far I came up with this
mounting
unmounting
Here is how that works for a single filesystem in an lvm
and here is how that works for a partition table in the lvm
This won't mount swap partition
It's not perfect however, it doesn't seem to work with EFIDISKS
EFIDISKS, not mounting
Also in the example with partition above, the partition
/dev/thinvg/vm-110-disk-1p2 1026048 1288191 262144 128M Microsoft reserved
did not mount
But still this was good enough for me for now !
I hope this is useful to you !
I have an old broken proxmox system, with a few good VMs and CTs to save and a bunch that I don't remember what they are...
So I need an easy way to mount them and unmount them.
And I didn't want to inspect them on what was inside, just single command that takes care of sole partitions or multiple partition volumes.
So far I came up with this
mounting
Code:
mountlvm() { LVFULL="$1"; losetup -D; fdisk -l "/dev/$LVFULL"; LOOP=$(losetup --find --show "/dev/$LVFULL"); partx -l "$LOOP" &>/dev/null && partx -a "$LOOP"; for DEV in "$LOOP" ${LOOP}p*; do TYPE=$(blkid -s TYPE -o value "$DEV"); [ "$TYPE" = "swap" ] || [ -z "$TYPE" ] && continue; MNT="/mnt/${LVFULL//\//,}${DEV#$LOOP}"; mkdir -p "$MNT" && mount "$DEV" "$MNT" && echo "Mounted $DEV to $MNT"; done; }
unmounting
Code:
umountlvm() { LVFULL="$1"; LOOP=$(losetup -j "/dev/$LVFULL" | head -n1 | cut -d: -f1); for DEV in "$LOOP" ${LOOP}p*; do MNT="/mnt/${LVFULL//\//,}${DEV#$LOOP}"; mountpoint -q "$MNT" && umount "$MNT" && rmdir "$MNT" && echo "Unmounted $DEV from $MNT"; done; partx -d "$LOOP" 2>/dev/null; losetup -d "$LOOP"; }
Here is how that works for a single filesystem in an lvm
Code:
root@proxmox:/mnt# mountlvm thinvg/vm-101-disk-0
Disk /dev/thinvg/vm-101-disk-0: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 524288 bytes
Mounted /dev/loop0 to /mnt/thinvg,vm-101-disk-0
root@proxmox:/mnt# ls
thinvg,vm-101-disk-0
root@proxmox:/mnt# ls thinvg,vm-101-disk-0/
BepInEx boot etc just_start_valheim.sh lib32 lost+found mnt proc run srv sys usr valheim-mods-download var
bin dev home lib lib64 media opt root sbin start_modded_flisholand.sh tmp valheim valheim_worlds
root@proxmox:/mnt# umountlvm $LVFULL
Unmounted /dev/loop0 from /mnt/thinvg,vm-101-disk-0
root@proxmox:/mnt#
and here is how that works for a partition table in the lvm
Code:
root@proxmox:/mnt# mountlvm thinvg/vm-110-disk-1
Disk /dev/thinvg/vm-110-disk-1: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 524288 bytes
Disklabel type: gpt
Disk identifier: FC845519-5018-45E5-A622-CB46D0C0D52D
Device Start End Sectors Size Type
/dev/thinvg/vm-110-disk-1p1 2048 1026047 1024000 500M EFI System
/dev/thinvg/vm-110-disk-1p2 1026048 1288191 262144 128M Microsoft reserved
/dev/thinvg/vm-110-disk-1p3 1288192 2312191 1024000 500M Windows recovery environment
/dev/thinvg/vm-110-disk-1p4 2312192 67106815 64794624 30.9G Microsoft basic data
Mounted /dev/loop0p1 to /mnt/thinvg,vm-110-disk-1p1
Mounted /dev/loop0p3 to /mnt/thinvg,vm-110-disk-1p3
Mounted /dev/loop0p4 to /mnt/thinvg,vm-110-disk-1p4
root@proxmox:/mnt# ls
thinvg,vm-110-disk-1p1 thinvg,vm-110-disk-1p3 thinvg,vm-110-disk-1p4
root@proxmox:/mnt# ls thinvg,vm-110-disk-1p1/
EFI 'System Volume Information'
root@proxmox:/mnt# ls thinvg,vm-110-disk-1p3/
'System Volume Information'
root@proxmox:/mnt# ls thinvg,vm-110-disk-1p4/
'$Recycle.Bin' DumpStack.log.tmp PerfLogs 'Program Files' Recovery 'System Volume Information' Windows
'Documents and Settings' pagefile.sys ProgramData 'Program Files (x86)' swapfile.sys Users
root@proxmox:/mnt# df -h | grep 110
/dev/loop0p1 496M 27M 470M 6% /mnt/thinvg,vm-110-disk-1p1
/dev/loop0p3 500M 13M 488M 3% /mnt/thinvg,vm-110-disk-1p3
/dev/loop0p4 31G 13G 18G 42% /mnt/thinvg,vm-110-disk-1p4
root@proxmox:/mnt# umountlvm $LVFULL
Unmounted /dev/loop0p1 from /mnt/thinvg,vm-110-disk-1p1
Unmounted /dev/loop0p3 from /mnt/thinvg,vm-110-disk-1p3
Unmounted /dev/loop0p4 from /mnt/thinvg,vm-110-disk-1p4
root@proxmox:/mnt# ls
root@proxmox:/mnt# df -h | grep 110
root@proxmox:/mnt#
This won't mount swap partition
It's not perfect however, it doesn't seem to work with EFIDISKS
EFIDISKS, not mounting
Code:
root@proxmox:/mnt# mountlvm thinvg/vm-110-disk-0
Disk /dev/thinvg/vm-110-disk-0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 524288 bytes
root@proxmox:/mnt# ls
root@proxmox:/mnt# umountlvm $LVFULL
root@proxmox:/mnt# fdisk -l /dev/thinvg/vm-110-disk-0
Disk /dev/thinvg/vm-110-disk-0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 524288 bytes / 524288 bytes
root@proxmox:/mnt# blkid /dev/thinvg/vm-110-disk-0
Also in the example with partition above, the partition
/dev/thinvg/vm-110-disk-1p2 1026048 1288191 262144 128M Microsoft reserved
did not mount
But still this was good enough for me for now !
I hope this is useful to you !