PVE下命令行pvesh,zfs,qm,qemu-img使用

pvesh & qm

1. 获取所有虚拟机列表

 1 root@pve:~# pvesh get /cluster/resources
 2 ┌───────────────────────┬─────────┬─────────────┬───────────────────┬────────┬────────────┬─────────┬───────┬────────┬────────────┬───────────┬────────────┬───────────────
 3id                    │ type    │ cgroup-mode │ content           │    cpu │       disk │ hastate │ level │ maxcpu │    maxdisk │    maxmem │        mem │ name          
 4 ╞═══════════════════════╪═════════╪═════════════╪═══════════════════╪════════╪════════════╪═════════╪═══════╪════════╪════════════╪═══════════╪════════════╪═══════════════
 5 │ node/pve              │ node    │           2 │                   │ 18.85% │  22.24 GiB │         │       │      493.93 GiB │ 31.14 GiB │  22.51 GiB │               
 6 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
 7 │ qemu/100              │ qemu    │             │                   │  4.73% │     0.00 B │         │       │      25.00 GiB │  4.00 GiB │ 412.20 MiB │ ikuai         
 8 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
 9 │ qemu/101              │ qemu    │             │                   │  3.27% │     0.00 B │         │       │      2520.00 MiB │  2.00 GiB │ 462.71 MiB │ openwrt       
10 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
11 │ qemu/102              │ qemu    │             │                   │  0.00% │     0.00 B │         │       │      4160.00 MiB │  4.00 GiB │     0.00 B │ DS918         
12 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
13 │ qemu/103              │ qemu    │             │                   │ 11.70% │     0.00 B │         │       │      461.00 GiB │  6.00 GiB │   3.14 GiB │ centos-master 
14 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
15 │ qemu/104              │ qemu    │             │                   │  3.49% │     0.00 B │         │       │      461.00 GiB │  6.00 GiB │   2.01 GiB │ centos-node   
16 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
17 │ storage/pve/local     │ storage │             │ backup,vztmpl,iso │        │  22.24 GiB │         │       │        │  93.93 GiB │           │            │               
18 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
19 │ storage/pve/local-lvm │ storage │             │ images,rootdir    │        │   9.71 GiB │         │       │        │ 349.31 GiB │           │            │               
20 ├───────────────────────┼─────────┼─────────────┼───────────────────┼────────┼────────────┼─────────┼───────┼────────┼────────────┼───────────┼────────────┼───────────────
21 │ storage/pve/zfs       │ storage │             │ rootdir,images    │        │ 125.83 GiB │         │       │        │ 230.62 GiB │           │            │               
22 └───────────────────────┴─────────┴─────────────┴───────────────────┴────────┴────────────┴─────────┴───────┴────────┴────────────┴───────────┴────────────┴──────────────
1 root@pve:~# qm list
2       VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID       
3        100 ikuai                running    4096               5.00 1598      
4        101 openwrt              running    2048               0.51 1703      
5        102 DS918                stopped    4096               0.16 0         
6        103 centos-master        running    6144              61.00 161186    
7        104 centos-node          running    6144              61.00 62651  

2. 启停虚拟机

1 pvesh create /nodes/pve/qemu/103/status/stop
2 pvesh create /nodes/pve/qemu/103/status/start
1 root@pve:~# qm start 102
2 WARN: no efidisk configured! Using temporary efivars disk.
3 Task finished with 1 warning(s)!

 

3. 导入qcow2虚拟磁盘

1 qm importdisk 10152 /home/qcow2/openmanage_enterprise.qcow2  local-lvm
2 qm importdisk id /home/qcow2/openmanage_enterprise.qcow2  储存的目录,默认是 local-lvm

zfs

1. 创建池子和磁盘

要使用 ZFS 实现 RAID0,只需创建一个普通的池

1 zpool create your-pool /dev/sdc /dev/sdd
2 zfs create -o mountpoint=/export/zfs tank/home

 

2. 查看池子和磁盘

1 root@pve:~# zpool list
2 NAME   SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
3 zfs    238G  16.2G   222G        -         -     1%     6%  1.00x    ONLINE  -
4 root@pve:~# zfs list
5 NAME                USED  AVAIL     REFER  MOUNTPOINT
6 zfs                 126G   105G       96K  /zfs
7 zfs/vm-103-disk-0  62.9G   159G     8.55G  -
8 zfs/vm-104-disk-0  62.9G   160G     7.63G  -

3. 销毁磁盘

销毁不掉的时候,关闭所有虚拟机,重启系统就可以销毁了

1 zfs destroy [-f] [-r] [-R](若有间接依赖项) tank/home

qemu-img

压缩、转换为其他格式的虚拟磁盘

1 qemu-img convert -c -O qcow2 /kvm/sys/centos7.6-kvm.qcow2 ccx_centos76.qcow2

 

posted @ 2022-11-23 20:05  风吹过的绿洲  阅读(3844)  评论(0编辑  收藏  举报