Update menu help and info

This commit is contained in:
MacRimi 2025-05-06 20:42:12 +02:00
parent d93759d31a
commit 2f81ed14fb
3 changed files with 144 additions and 63 deletions

View File

@ -272,6 +272,7 @@ show_storage_commands() {
echo -e "20) ${GREEN}pvesm scan <storage>${NC} - $(translate 'Scan storage for new content')" echo -e "20) ${GREEN}pvesm scan <storage>${NC} - $(translate 'Scan storage for new content')"
echo -e "21) ${GREEN}qm importdisk <vmid> <img> <storage>${NC} - $(translate 'Import disk image to VM')" echo -e "21) ${GREEN}qm importdisk <vmid> <img> <storage>${NC} - $(translate 'Import disk image to VM')"
echo -e "22) ${GREEN}qm set <vmid> -<bus><index> <disk>${NC} - $(translate 'Add physical disk to VM via') passthrough" echo -e "22) ${GREEN}qm set <vmid> -<bus><index> <disk>${NC} - $(translate 'Add physical disk to VM via') passthrough"
echo -e "23) ${GREEN}qemu-img convert -O <format> <input> <output>${NC} - $(translate 'Convert disk image format')"
echo -e " ${DEF}0) $(translate ' Back to previous menu or Esc + Enter')" echo -e " ${DEF}0) $(translate ' Back to previous menu or Esc + Enter')"
echo echo
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter a number, or write or paste a command: ') ${CL}" echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter a number, or write or paste a command: ') ${CL}"
@ -315,84 +316,146 @@ show_storage_commands() {
read -r store read -r store
cmd="pvesm scan $store" cmd="pvesm scan $store"
;; ;;
21) 21)
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter VM ID: ')${CL}" echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter VM ID: ')${CL}"
read -r vmid read -r vmid
echo -e "\n${YELLOW}$(translate 'Available images in /var/lib/vz/images/:')${NC}" echo -e "\n${YELLOW}$(translate 'Available images in /var/lib/vz/images/:')${NC}"
images=$(find /var/lib/vz/images/ -type f \( -iname "*.img" -o -iname "*.qcow2" -o -iname "*.vmdk" -o -iname "*.raw" \)) images=$(find /var/lib/vz/images/ -type f \( -iname "*.img" -o -iname "*.qcow2" -o -iname "*.vmdk" -o -iname "*.raw" \))
if [[ -z "$images" ]]; then if [[ -z "$images" ]]; then
echo -e "${RED}$(translate 'No disk images found in /var/lib/vz/images/. Please add an image first.')${NC}" echo -e "${RED}$(translate 'No disk images found in /var/lib/vz/images/. Please add an image first.')${NC}"
echo echo
msg_success "$(translate 'Press ENTER to return to the menu...')" msg_success "$(translate 'Press ENTER to return to the menu...')"
read -r read -r
continue continue
else else
echo "$images" echo "$images"
fi fi
echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter full path to the disk image (e.g., /var/lib/vz/images/xyz.img): ')${CL}" echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter full path to the disk image (e.g., /var/lib/vz/images/xyz.img): ')${CL}"
read -r image_path read -r image_path
echo -e "\n${YELLOW}$(translate 'Available storage volumes:')${NC}" echo -e "\n${YELLOW}$(translate 'Available storage volumes:')${NC}"
pvesm status | awk 'NR>1 {print " - "$1}' pvesm status | awk 'NR>1 {print " - "$1}'
echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter target storage name (e.g., local-lvm): ')${CL}" echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter target storage name (e.g., local-lvm): ')${CL}"
read -r storage read -r storage
cmd="qm importdisk $vmid $image_path $storage" cmd1="qm importdisk $vmid $image_path $storage"
;; bash -c "$cmd1"
22) echo
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter VM ID: ')${CL}"
read -r vmid
echo -e "\n${YELLOW}$(translate 'Scanning available physical disks...')${NC}" disk_name=$(basename "$image_path")
sleep 1 imported_volume="${storage}:vm-${vmid}-disk-0"
echo -e "\n${YELLOW}$(translate 'Available physical disks for passthrough:')${NC}" echo -e "\n${YELLOW}$(translate 'Select disk interface type:')${NC}"
printf "\n" echo " 1) sata"
echo " 2) scsi"
echo " 3) virtio"
echo " 4) ide"
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter the number or type the interface name: ')${CL}"
read -r iface_type
lsblk -dno NAME,SIZE,MODEL | grep -vE 'boot|rpmb|loop|dm-|zd' | while read -r name size model; do case "$iface_type" in
disk_path="/dev/$name" 1) iface="sata" ;;
by_id=$(find /dev/disk/by-id/ -lname "*$name" | grep -vE 'part[0-9]+$' | head -n1) 2) iface="scsi" ;;
if [[ -n "$by_id" ]]; then 3) iface="virtio" ;;
printf " %-60s (%s %s)\n" "$by_id" "$size" "$model" 4) iface="ide" ;;
fi *) iface="sata" ;;
done esac
echo index=$(qm config "$vmid" | grep -oP "$iface\d+" | awk -F"$iface" '{print $2}' | sort -n | tail -n1)
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter full disk path as shown above (starting with /dev/disk/by-id/xxx...): ')${CL}" index=$((index + 1))
read -r disk_path
echo -e "\n${YELLOW}$(translate 'Select disk interface type:')${NC}" echo -e "\n${YELLOW}$(translate 'Assigning imported disk to VM using the generated command')${NC}"
echo " 1) sata" sleep 1
echo " 2) scsi" echo
echo " 3) virtio" echo -e "\n${GREEN}> $cmd1${NC}\n"
echo " 4) ide" cmd="qm set $vmid -$iface$index $imported_volume"
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter the number or type the interface name: ')${CL}" ;;
read -r iface_type 22)
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter VM ID: ')${CL}"
read -r vmid
case "$iface_type" in echo -e "\n${YELLOW}$(translate 'Scanning available physical disks...')${NC}"
1) iface="sata" ;; sleep 1
2) iface="scsi" ;;
3) iface="virtio" ;;
4) iface="ide" ;;
*) iface="sata" ;;
esac
index=$(qm config "$vmid" | grep -oP "$iface\d+" | awk -F"$iface" '{print $2}' | sort -n | tail -n1) echo -e "\n${YELLOW}$(translate 'Available physical disks for passthrough:')${NC}"
index=$((index + 1)) printf "\n"
echo -e "\n${YELLOW}$(translate 'Adding disk using the generated command to the selected VM')${NC}" lsblk -dno NAME,SIZE,MODEL | grep -vE 'boot|rpmb|loop|dm-|zd' | while read -r name size model; do
sleep 1 disk_path="/dev/$name"
by_id=$(find /dev/disk/by-id/ -lname "*$name" | grep -vE 'part[0-9]+$' | head -n1)
if [[ -n "$by_id" ]]; then
printf " %-60s (%s %s)\n" "$by_id" "$size" "$model"
fi
done
cmd="qm set $vmid -$iface$index $disk_path" echo
echo -e "\n${GREEN}> $cmd${NC}\n" echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter full disk path as shown above (starting with /dev/disk/by-id/xxx...): ')${CL}"
bash -c "$cmd" read -r disk_path
unset cmd echo -e "\n${YELLOW}$(translate 'Select disk interface type:')${NC}"
;; echo " 1) sata"
echo " 2) scsi"
echo " 3) virtio"
echo " 4) ide"
echo -en "${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter the number or type the interface name: ')${CL}"
read -r iface_type
case "$iface_type" in
1) iface="sata" ;;
2) iface="scsi" ;;
3) iface="virtio" ;;
4) iface="ide" ;;
*) iface="sata" ;;
esac
index=$(qm config "$vmid" | grep -oP "$iface\d+" | awk -F"$iface" '{print $2}' | sort -n | tail -n1)
index=$((index + 1))
echo -e "\n${YELLOW}$(translate 'Adding disk using the generated command to the selected VM')${NC}"
sleep 1
cmd="qm set $vmid -$iface$index $disk_path"
;;
23)
echo -e "\n${YELLOW}$(translate 'Convert disk image format using QEMU-IMG')${NC}"
sleep 1
echo -e "\n${YELLOW}$(translate 'Available images in /var/lib/vz/images/:')${NC}"
images=$(find /var/lib/vz/images/ -type f \( -iname "*.img" -o -iname "*.qcow2" -o -iname "*.vmdk" -o -iname "*.raw" -o -iname "*.vdi" -o -iname "*.vpc" -o -iname "*.qed" \))
if [[ -z "$images" ]]; then
echo -e "${RED}$(translate 'No disk images found in /var/lib/vz/images/. Please add an image first.')${NC}"
echo
msg_success "$(translate 'Press ENTER to return to the menu...')"
read -r
continue
else
echo "$images"
fi
echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter full path to the input image (e.g., /var/lib/vz/images/disk.vmdk): ')${CL}"
read -r input_image
echo -e "\n${YELLOW}$(translate 'Available output formats include:')${NC} qcow2, raw, qed"
echo -en "\n${TAB}${BOLD}${YW}${HOLD}$(translate 'Enter the full path to the output image (e.g., /var/lib/vz/images/output.qcow2): ')${CL}"
read -r output_image
valid_formats=("qcow2" "raw" "qed")
output_format=$(echo "$output_image" | awk -F. '{print tolower($NF)}')
if ! [[ " ${valid_formats[*]} " =~ " ${output_format} " ]]; then
echo -e "\n${RED}$(translate 'Unsupported output format:') .$output_format${NC}"
msg_success "$(translate 'Press ENTER to return...')"
read -r
continue
fi
echo -e "\n${YELLOW}$(translate 'Converting image using command:')${NC}"
cmd="qemu-img convert -O $output_format $input_image $output_image"
;;
0) break ;; 0) break ;;
*) cmd="$user_input" ;; *) cmd="$user_input" ;;
esac esac

View File

@ -89,7 +89,7 @@ export default function HelpAndInfoPage() {
<p className="text-black"> <p className="text-black">
Each category contains carefully selected commands with descriptions, making it easier to find exactly what Each category contains commands with descriptions, making it easier to find exactly what
you need when you need it. This eliminates the need to remember complex command syntax or search through you need when you need it. This eliminates the need to remember complex command syntax or search through
documentation when performing administrative tasks. documentation when performing administrative tasks.
</p> </p>

View File

@ -52,6 +52,14 @@ export default function StorageCommandsPage() {
{ command: "pvesm scan <storage>", description: "Scan storage for new content" }, { command: "pvesm scan <storage>", description: "Scan storage for new content" },
], ],
}, },
{
title: "Disk Actions",
commands: [
{ command: "qm importdisk <vmid> <image_path> <storage>", description: "Attach disk image to VM" },
{ command: "qm set <vmid> -<bus><index> <disk_path>", description: "Assign physical disk to VM (passthrough mode)" },
{ command: "qemu-img convert -O <format> <input> <output>", description: "Convert disk image format)" },
],
},
] ]
return ( return (
@ -184,8 +192,18 @@ export default function StorageCommandsPage() {
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">/path</code> with the directory you want to <code className="bg-gray-100 px-1 py-0.5 rounded text-black">/path</code> with the directory you want to
check check
</li> </li>
<li>
Replace placeholders like <code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;vmid&gt;</code>,{" "}
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;bus&gt;&lt;index&gt;</code>,{" "}
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;disk&gt;</code>,{" "}
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;format&gt;</code>,{" "}
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;input&gt;</code> and{" "}
<code className="bg-gray-100 px-1 py-0.5 rounded text-black">&lt;output&gt;</code> with the actual values you
intend to use.
</li>
</ul> </ul>
</div> </div>
</div> </div>
) )
} }