summaryrefslogtreecommitdiff
path: root/others/vm3/docs
blob: ca8ec36a4e7b3d91553801d8db93350baa296fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

todo
  make theseediso cloud init stuff happen inside the vm storage directory so that multiple poeple can use it ast the same time on the same system
  fedora debian freebsd opensuse
  change deployment for non-fedora to manually make a base image and copy ssh stuff over, then duplicate it however you want



vm compute create name1 -os fedora -vcpu 1 -ram 1 -disk 10 -s.pool storage1 -add-disk 200 storage2 -add-network nw3 # default fedora 4,4,20
  # fedora not available. available os: listed down
  # storage not available. please create it
  # nw3 not available. create y/n?
vm network create <name> 192.168.100.1 /32
vm network create <name> (auto)
vm storage create <name> /dev/
vm storage create <name2> /dir/

  
vm/
  ./vm.sh                     # Single entry point. one vm at a time(except for compute delete-all)
  .config/  # all config files
    init/  # run this everytime. try to think of a way to set a flag that says this device has been initialised
      install_packages.sh 
      make_rootkey.sh  # in /root/k/k1. can also add keys in here
    /var/lib/libvirt/images/.image_store/  # stores the images
    /var/lib/libvirt/images/.temp/  # for user-data, meta-data, and seed.iso(has ud and md inside) need to delete after initialising a new vm
  image/  # vm cloud init templates to make user-data, meta-data, and seed.iso
    fedora.sh <vm name> # images in /var/lib/libvirt/images/.image_store/ and in images/.temp
    opensuse.sh
    debian.sh
    freebsd.sh
    list-all-images.sh
  compute/               
    create.sh         
      # default vcpu ram disk storage pool network
      # allow specification of storage pool and network. 
      # auto list all available images, storage pools, networks. on no argument. just call stroage/network list.sh
    delete.sh    and all associated virtual machines and block devices on all storage device
    start.sh   before starting the vm, make sure the cloud init seed.iso is not attached anymore.
    shutdown.sh  
    list.sh  # list by (sorted by) network group, ip address, then cpu ram disk, total disk(incl all attachedvols), name
  network/            
    attach.sh        # one click, so if vm is running, ask fro permission to shutdown. or if can, live attach
    list.sh
    detach.sh 
    create.sh  # allow specifying the ip address range. auto make uuid
    delete.sh
  disk/          
    attach.sh
    detach.sh
    create.sh
      list all available storage hardware devices on no argument. just call list.sh
      make directory linking from /var/lib/libvirt/images/${VM_NAME}-vm-disks/ to the actual storage device
    delete.sh
      delete all blocks. all the linking if can. may not be able to link like that idk. list all mounts and delete the originla and the links
    list.sh #list storage pools and include --all to view all blocks and their sizes
  device/
    usb/
      attach.sh
      detach.sh
      view.sh # usbs of all the vms

# No arguments shows available options
./vm compute create
Available networks:
  prod-net     192.168.1.0/24
  dev-net      192.168.2.0/24
  test-net     192.168.3.0/24

Available storage pools:
  prod-store   2TB free
  dev-store    500GB free
  backup       1TB free

Available images:
  fedora40(41)


Usage: ./vm compute create <name> <os> --vcpu 4 --ram 8 --disk 40 --storage-pool prod-store --network prod-net

# Then use directly
./vm compute create myvm fedora40 prod-net prod-store 



os
  for debian12,
  sudo dnf install libguestfs libguestfs-tools libvirt virt-install virt-manager guestfs-tools
  sudo virt-customize -a /var/lib/libvirt/images/.image_store/debian12.qcow2 --root-password password:yourpassword
  sudo apt update && sudo apt install -y ssh cloud-init

  console works but no ssh, and the generic cloud ssh fails after editing the password(not sure if this is the reason)
  try to find out how to execute commands in sudo virsh console t1 in a bash script 
  not sure if cloud init can work after this but

  currently only fedra works fully, debian can work and login after editing the root password
  freebsd have not tried editing root password, boots on generic cloud image, no login yet
  ubuntu no boot no login yet.

others
  ssh
  public ssh port like online vps
  this forwards 2222 on the host to port 22
    # 1. First, check your VM's IP address (from inside the VM)
    ip addr show
    # 2. Set up port forwarding in libvirt
    virsh net-list                          # List networks
    virsh net-edit default                  # Edit default network config
    # Add this inside the <network> section:
    <forward mode='nat'>
      <nat>
        <port start='2222' end='2222'>
          <protocol>tcp</protocol>
          <forward address='192.168.122.x' port='22'/>  # Replace x with your VM's last octet
        </port>
      </nat>
    </forward>
    # 3. Restart the network
    virsh net-destroy default
    virsh net-start default
    # 4. Configure firewall on Fedora host
    sudo firewall-cmd --add-port=2222/tcp --permanent
    sudo firewall-cmd --reload
  seed.iso
    move seed.iso to images/vmname/seed.iso
    allows concurrent usage of vm.sh as there will be no conflicts