Virt-install usage example
From Newroco Tech Docs
Revision as of 12:01, 15 May 2018 by Marian.maireanu (talk | contribs) (Created page with "<pre> #!/bin/bash #####Setup up for the guest host_name='peon04' user_name='mmaireanu' password='parolamea' virt_ram='1024' disk_path='/var/lib/kvm' disk_size='9' virt_cpu...")
#!/bin/bash #####Setup up for the guest host_name='peon04' user_name='mmaireanu' password='parolamea' virt_ram='1024' disk_path='/var/lib/kvm' disk_size='9' virt_cpu='1' network_bridge="br0" # virbr0 ip_adress='192.168.0.207' netmask='255.255.255.0' gateway='192.168.0.1' nameservers='192.168.0.1' ##### Change variable into the preseed.cfg file sed -i "s|^d-i netcfg/get_hostname string.*|d-i netcfg/get_hostname string $host_name|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i netcfg/get_domain string.*|d-i netcfg/get_domain string $host_name|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i netcfg/get_ipaddress string.*|d-i netcfg/get_ipaddress string $ip_adress|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i netcfg/get_netmask string.*|d-i netcfg/get_netmask string $netmask|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i netcfg/get_gateway string.*|d-i netcfg/get_gateway string $gateway|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i netcfg/get_nameservers string.*|d-i netcfg/get_nameservers string $nameservers|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i passwd/user-fullname string.*|d-i passwd/user-fullname string $user_name|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i passwd/username string.*|d-i passwd/username string $user_name|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i passwd/user-password password.*|d-i passwd/user-password password $password|" /home/mmaireanu/virt-install/preseed.cfg sed -i "s|^d-i passwd/user-password-again password.*|d-i passwd/user-password-again password $password|" /home/mmaireanu/virt-install/preseed.cfg ##### Create folder where disk will be stored mkdir -p /var/lib/kvm/${host_name} #### Run virt-install command virt-install \ --name $host_name \ --ram $virt_ram \ --disk path=${disk_path}/${host_name}/${host_name}.qcow2,size=${disk_cpu},format=qcow2,bus=virtio \ --vcpus ${virt_cpu} \ --os-type linux \ --os-variant ubuntu16.04 \ --autostart \ --network bridge=$network_bridge \ --graphics none \ --console pty,target_type=serial \ --location 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/' \ --initrd-inject=/home/mmaireanu/virt-install/preseed.cfg \ --extra-args 'locale=en_US auto=true priority=critical console=ttyS0,115200n8 serial file=file:/preseed.cfg'