Difference between revisions of "Network/Procedures/Create a new VM"

From Makers Local 256
Jump to: navigation, search
(Testing this as I go ;))
m (minor mistake)
Line 68: Line 68:
 
* If you get this error:
 
* If you get this error:
 
<code>Error: invalid literal for int() with base 10: '256M'</code>
 
<code>Error: invalid literal for int() with base 10: '256M'</code>
Then you need to go edit /etc/xen.d/newvpn.cfg and change 256M to just 256.
+
Then you need to go edit /etc/xen/newvpn.cfg and change 256M to just 256.
  
 
* Copy /etc/xen/newvpn.cfg to the other VM host so that you could start it there if you had to.
 
* Copy /etc/xen/newvpn.cfg to the other VM host so that you could start it there if you had to.
 
* Shell into your new VM and do what you need to do! Use the root password from the xen-create-image tool to log in. Make a username for yourself and then mind-wipe that root password. Enjoy!
 
* Shell into your new VM and do what you need to do! Use the root password from the xen-create-image tool to log in. Make a username for yourself and then mind-wipe that root password. Enjoy!

Revision as of 01:30, 18 August 2014

This setup will create two logical volumes on two different boxes, set up replication between them, create a new VM backed by the replicated storage, and put Debian stable on it. The example hosts I will be using are vm2 and vm3. I will be creating the newvpn VM.

  • Create the block devices (do this on both hosts, so vm2 and vm3 in this case):
vm2$ sudo lvcreate vm2_storage --name newvpn_root --size 10G
vm3$ sudo lvcreate vm3_storage --name newvpn_root --size 10G
  • Create the drbd resource config on both boxes; for example, /etc/drbd.d/newvpn_root:
 resource newvpn_root { #change this to match the name of the volume
        protocol C;
        meta-disk internal;
        device /dev/drbd_newvpn_root minor 13; #change this. I like to make it match the IP the box will have
        syncer {
                verify-alg sha1;
                rate 5M;
        }
        net {
                allow-two-primaries;# yes;
                cram-hmac-alg sha1;
                shared-secret "newvpn_root"; #change this
                after-sb-0pri discard-zero-changes;
                after-sb-1pri consensus;
                after-sb-2pri disconnect;
        }
        on vm3 {
                disk /dev/vm3_storage/newvpn_root; #change this
                address 10.56.0.30:7813; #change the port and such. I use 78xx where xx is the minor
        }
        on vm2 {
                disk /dev/vm2_storage/newvpn_root; #change this
                address 10.56.0.20:7813; #should match the other host, but address different
        }
}
  • Set up the drbd resource (do this on both hosts):
sudo drbdadm create-md newvpn_root #creates metadata on underlying slice
sudo drbdadm attach newvpn_root #opens the underlying block device for drbd usage
sudo drbdadm connect newvpn_root #connect to the other box
sudo drbd-overview | grep newvpn_root #make sure the states are Secondary/Secondary indicating connection
  • On only one of the hosts, invalidate the current state of the volume:
sudo drbdadm invalidate newvpn_root
  • Then, only on the other host, set the volume to primary:
sudo drbdadm primary newvpn_root

The volume will start replicating between hosts.

  • On the host you selected as primary, debootstrap a new install using xen-tools.
sudo xen-create-image --fs=ext4 --genpass_len=64 --image-dev=/dev/drbd_newvpn_root --memory=256M --pygrub --bridge=br.200 --ip=10.56.0.13 --gateway=10.56.0.1 --netmask=255.255.255.0 --hostname=newvpn --noswap

This part takes a LONG time (like 10-30 minutes depending on Internet download speeds). Note the root password provided!

  • Now the box exists. Try to start it:
sudo xm create newvpn.cfg
  • If you get this error:

Error: invalid literal for int() with base 10: '256M' Then you need to go edit /etc/xen/newvpn.cfg and change 256M to just 256.

  • Copy /etc/xen/newvpn.cfg to the other VM host so that you could start it there if you had to.
  • Shell into your new VM and do what you need to do! Use the root password from the xen-create-image tool to log in. Make a username for yourself and then mind-wipe that root password. Enjoy!