about summary refs log blame commit diff stats
path: root/tools/qemu.html
blob: ce1b66dd2eecbe4690a79289e8ad1b13f826121d (plain) (tree)
1
2
3
4
5
6
7
8
9
10



                              
                           




                                            
                     
 
                                         
 







                                                           




                                    
                                         


                        
                                                                    
                        
                                                                    
                          
                                                       

             



                                                            
                                                     








                                                    
                                              




                                    



                                                              




                                                       

                                    

              


                                      
 




                                      

             
                                  

              
                                    
 
                                     
 

                          
                                                   
                            



                                                                        

             
 
                                    









                                                                               
                                           










                                                         

                                          

                                       













                                                                             








                                                                               
              



                                                                     





                                                                          

              


                                            
                



                                                                                            
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>Qemu</title>
    </head>
    <body>

        <a href="index.html">Tools Index</a>

        <h1>Qemu</h1>

        <h2 id="kern">1. Host System</h2>

        <p>Load modules, in this case kvm of intel cpu;</p>

        <pre>
        # modprobe -a kvm-intel tun virtio
        </pre>

        <p>Add users to kvm group;</p>

        <pre>
        # usermod -a -G kvm c9admin
        # usermod -a -G kvm username
        </pre>

        <h2 id="disk">2. Disk images</h2>

        <dl>
            <dt>img</dt>
            <dd>Raw disk image, allows dd to a physical device.</dd>
            <dt>raw</dt>
            <dd>Raw disk image, allows dd to a physical device.</dd>
            <dt>qcow2</dt>
            <dd>Qcow disk image file used by qemu.</dd>
        </dl>

        <p>Create hard disk image, there is different types,
        this describes how to create a qcow2 type;</p>

        <pre>
        $ qemu-img create -f qcow2 crux-img.qcow2 15G
        </pre>

        <p>You can mount disk image;</p>

        <pre>
        $ sudo modprobe nbd
        $ sudo qemu-nbd -c /dev/nbd0 /crux-img.qcow2
        </pre>

        <p>To disconnect image disk (ndb);</p>

        <pre>
        $ sudo qemu-nbd -d /dev/nbd0
        </pre>

        <p>Information about preparing
        <a href="../core/install.html#step2">partitions</a>
        and <a href="storage.html">storage</a> administration.
        You can use image as a normal disk, example how
        to use parted to create a gpt system table;</p>

        <pre>
        # parted /dev/nbd0
        (parted) mklabel gpt
        (parted) mkpart ext4 0% 100%
        (parted) set 1 boot on
        </pre>

        <pre>
        # kpartx -a -s -l -u /dev/nbd0
        </pre>

        <pre>
        # mkfs.ext4 /dev/mapper/nbd0p1
        </pre>

        <p>Mount partition;</p>

        <pre>
        # mount /dev/mapper/nbd0p1
        </pre>

        <h2 id="net">2. Network</h2>

        <p>Network configuration;</p>

        <dl>
            <dt>slirp</dt>
            <dd>Default virtual NAT'd network.</dd>
            <dt>tun/tap</dt>
            <dd>Good performance to create virtually any type of network
            topology.</dd>
            <dt>vde</dt>
            <dd>The VDE networking backend.</dd>
        </dl>


        <h3>2.1. Tap interfaces</h3>

        <pre>
        KERNEL=="tun", GROUP="kvm", MODE="0660", OPTIONS+="static_node=net/tun"
        </pre>

        <p>Automatic creation of tap interface with
        correct permissions set for user and group,
        you can set only user or group;</p>

        <pre>
        # tunctl -u username -g kvm -t tap0
        </pre>

        <p>Set permissions to existing tap interface;</p>

        <pre>
        # tunctl -u username -t tap0
        </pre>


        <p>Manual creation of tap interface;</p>

        <pre>
        # ip tuntap add name tap0 mode tap
        # chmod 0666 /dev/tap0
        # chown root:username /dev/tap0
        </pre>

        <pre>
        # ip addr add 10.0.2.1/24 dev tap0
        # ip link set dev tap0 up
        # ip link show
        </pre>

        <pre>
        # sysctl -w net.ipv4.ip_forward=1
        # iptables -t nat -A POSTROUTING -s 10.0.2.0/24 -o eth0 -j MASQUERADE
        </pre>

        <h2 id="guest">Guest System</h2>

        <p>Start qemu with 512 of ram, mydisk.img as disk and boot from iso</p>

        <pre>
        $ qemu-system-x86_64 \
        -enable-kvm \
        -m 512 \
        -boot d -cdrom image.iso \
        -hda mydisk.img
        </pre>

        <p>Start qemu with 1024 of ram, network configured using tap0
        interface device no host and boot from crux.qcow2;</p>

        <pre>
        $ qemu-system-x86_64 \
        -enable-kvm \
        -m 1024 \
        -hda c9/local/crux.qcow2 \
        -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no
        </pre>

        <a href="index.html">Tools Index</a>
        <p>This is part of the c9 Manual.
        Copyright (C) 2016
        c9 team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>
    </body>
</html>