zoukankan      html  css  js  c++  java
  • kickstart+virt-install安装虚拟机

    本文提供的方法适用于在远程服务器的kvm+qemu环境中部署CentOS虚拟机。

    #!/bin/bash
    set -xe
    diskimage=/var/lib/libvirt/images/centosvm.qcow2
    echo "Creating qcow2 disk image.."
    qemu-img create -f qcow2 -o preallocation=metadata $diskimage 40G
    #fallocate -l `ls -al $diskimage | awk '{print $5}'` $diskimage
    echo `ls -lash $diskimage`
    
    
    # [2] Create a minimal kickstart file for Fedora
    
    cat << EOF > fed.ks
    install
    text
    reboot
    lang en_US.UTF-8
    keyboard us
    network --bootproto dhcp
    rootpw abc123
    firewall --enabled --ssh
    selinux --enforcing
    network  --bootproto=static --ip=192.168.122.100 --netmask=255.255.255.0 --gateway=192.168.122.1 --nameserver=223.5.5.5,223.6.6.6 --device=eth0
    timezone --utc Asia/Shanghai
    bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH"
    zerombr
    clearpart --all --initlabel
    autopart
    
    %packages
    @core
    net-tools
    git
    emacs
    mtr
    %end
    EOF
    
    # [3] Create the guest
    
    virt-install --connect=qemu:///system 
        --network network=default 
        --initrd-inject=./fed.ks 
        --extra-args="ks=file:/fed.ks console=tty0 console=ttyS0,115200 serial rd_NO_PLYMOUTH" 
        --name=test 
        --disk path=$diskimage,format=qcow2,cache=none 
        --ram 512 
        --vcpus=2 
        --check-cpu 
        --accelerate 
        --os-type linux 
        --os-variant centos7.0 
        --cpuset auto 
        --hvm 
        --location=CentOS-7-x86_64-Minimal-1804.iso 
        --nographics
    
  • 相关阅读:
    【noip2012】开车旅行
    【AC自动机】专题总结
    【noi2013】【bz3244】树的计数
    BZOJ1069: [SCOI2007]最大土地面积
    BZOJ1185: [HNOI2007]最小矩形覆盖
    BZOJ1047: [HAOI2007]理想的正方形
    BZOJ1801: [Ahoi2009]chess 中国象棋
    BZOJ1925: [Sdoi2010]地精部落
    BZOJ1057: [ZJOI2007]棋盘制作
    BZOJ1217: [HNOI2003]消防局的设立
  • 原文地址:https://www.cnblogs.com/powerrailgun/p/12158037.html
Copyright © 2011-2022 走看看