Ubuntu 18.04
When Cloning Hosts:
to change Hostname
hostnamectl set-hostname u1804-nixcraft
then change the /etc/hosts file:
sudo nano /etc/hosts
then change this flag preserve_hostname: true
sudo nano /etc/cloud/cloud.cfg
to regenearate SSH keys:
/bin/rm -v /etc/ssh/ssh_host_*
then
dpkg-reconfigure openssh-server
change network config:
/etc/netplan/50-cloud-init.yaml
Ubuntu 18.04 default lvm layout comes with only a 4 GB root partition. Here we will extend it to occupy the full free space in the volume group:
sudo lvextend -l 100%FREE --resizefs /dev/ubuntu-vg/ubuntu-lv
vagrant with proxy
stackoverflow.com/questions/19872591/how-to-use-vagrant-in-a-proxy-environment
If your proxy requires authentication it is better to set the environment variable rather than storing your password in the Vagrantfile. Also your Vagrantfile can be used by others easily who are not behind a proxy.
For Mac/Linux (in Bash)
export http_proxy="http://user:password@host:port" export https_proxy="http://user:password@host:port" vagrant plugin install vagrant-proxyconf then
export VAGRANT_HTTP_PROXY=${http_proxy} export VAGRANT_NO_PROXY="127.0.0.1" vagrant up For Windows use set instead of export.
set http_proxy=http://user:password@host:port set https_proxy=%http_proxy% vagrant plugin install vagrant-proxyconf then
set VAGRANT_HTTP_PROXY="%http_proxy%" set VAGRANT_NO_PROXY="127.0.0.1" vagrant up setup Ubuntu 18.04.1
sudo apt update
sudo apt dist-upgrade
sudo apt autoremove -y
sudo reboot
sudo apt install qemu-kvm libvirt-bin bridge-utils cpu-checker
systemctl enable libvirtd
systemctl start libvirtd
virsh list --all
Network Configuration with Bridges:
networkctl status -a
vim /etc/netplan/50-cloud-init.yaml
network:
ethernets:
eno1:
dhcp4: false
eno2:
dhcp4: false
enp10s0:
addresses: []
dhcp4: true
enp8s0:
addresses: []
dhcp4: true
optional: true
bridges:
br0:
interfaces:
- eno1
addresses:
- 192.168.0.38/23
dhcp4: false
gateway4: 192.168.0.1
nameservers:
addresses:
- 192.168.0.4
- 192.168.0.5
search:
- nikoz.org
br1:
interfaces:
- eno2
dhcp4: true
version: 2
netplan --debug try
Net Time setup:
cd /etc/
vim systemd/timesyncd.conf
add:
NTP=192.168.0.5
FallbackNTP=192.168.0.4
timedatectl set-ntp false
timedatectl set-ntp true
for Virt-manager:
sudo apt-add-repository multiverse && sudo apt-get update
apt install virt-manager
Desktop network with bridge:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp1s0:
dhcp4: false
bridges:
br0:
dhcp4: yes
interfaces:
- enp1s0
KVM Qemu Images
modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 image.qcow2 partprobe /dev/nbd0 mount /dev/nbd0p1 /mnt/image
fdisk /dev/nbd0 Command (m for help): p Disk /dev/nbd0: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders, total 8388608 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000183ca Device Boot Start End Blocks Id System /dev/nbd0p1 * 2048 499711 248832 83 Linux /dev/nbd0p2 501758 8386559 3942401 5 Extended /dev/nbd0p5 501760 8386559 3942400 8e Linux LVM
umount /mnt/image qemu-nbd -d /dev/nbd0
killall qemu-nbd
Convert XEN Vm to Vmware (redhat5 /centos5)
on the source:
yum install kernel-2.6.18-194.el5 (kernel version found with yum search kernel)
check Grub configuration:
/boot/grub/grub.conf
must boot from the new kernel (without xen) should be like this:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-194.el5.img
title CentOS (2.6.18-53.el5xen)
root (hd0,0)
kernel /vmlinuz-2.6.18-53.el5xen ro root=/dev/VolGroup00/LogVol00 console=xvc0
initrd /initrd-2.6.18-53.el5xen.img
after that make the conversion (with Vmware converter or with qemu(?))
start the new Vm machine with the Centos(Redhat) setup DVD and chose: Linux rescue
follow the wizard:
- disable network;
- mount drives in /mnt/sysimage
on the shell:
chroot /mnt/sysimage
Modify /etc/modprobe.conf to add the proper SCSI and network card modul
alias eth0 xennet
alias scsi_hostadapter xenblk
will be replaced by
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
Modify /etc/inittab by removing the # in front of the getty and puting a comment in front of the line containg the xen console:
1:2345:respawn:/sbin/mingetty --noclear tty1
2:2345:respawn:/sbin/mingetty
3:2345:respawn:/sbin/mingetty
4:2345:respawn:/sbin/mingetty
5:2345:respawn:/sbin/mingetty
6:2345:respawn:/sbin/mingetty
finally:
mkinitrd -v -f /boot/initrd-2.6.18-194.el5.img 2.6.18-194.el5
exit
reboot
http://www.howtoforge.com/how-to-convert-a-xen-virtual-machine-to-vmware
Xen -> VMware VM Migration Steps (Kernel Step)
The kernel on the VM to be migrated must support fully virtualized operation. The kernels used for para-virtulized machines using RHEL/Fedora/CentOS as a guest do not support fully virtualized operation by default. The best way to deal with this is to also install a standard kernel in the machine, port the machine and finally remove the Xen kernel.
1. Since this is a highly risky procedure, FIRST CREATE A BACK-UP OF YOUR VIRTUAL MACHINE!!!
2. Download a kernel with the same version number and architecture as the Xen kernel, except it should be the a generic one. Use the distribution CD/DVD or any other repository to get it.
3. Use RPM tools to install the kernel.
4. Modify /etc/modprobe.conf to add the proper SCSI and network card modules:
alias eth0 xennet alias scsi_hostadapter xenblk
will be replaced by
alias eth0 pcnet32 alias scsi_hostadapter mptbase alias scsi_hostadapter1 mptspi alias scsi_hostadapter2 ata_piix
Modify /etc/inittab by removing the # in front of the getty and puting a comment in front of the line containg the xen console:
1:2345:respawn:/sbin/mingetty --noclear tty1 2:2345:respawn:/sbin/mingetty 3:2345:respawn:/sbin/mingetty 4:2345:respawn:/sbin/mingetty 5:2345:respawn:/sbin/mingetty 6:2345:respawn:/sbin/mingetty
This is a one way action. Once modified the kernel modules, you won'tbe able to properly start the machine, and you will receive a Kernel panic error message.
Xen - > VMware VM Migration Steps (Disk Step)
To convert a XEN machine in a .vmdk format to be used with VMware, a tool called qemu will be used. QEMU is a generic and open source machine emulator and virtualizer. It is also a fast processor emulator using dynamic translation to achieve good emulation speed.
1. Download qemu from DAG repository. Use the EL5 package for any Fedora/RHEL5/CentOS5 that you use.
http://dag.wieers.com/rpm/packages/qemu/
2. Convert the XEN machine to VMware:
qemu-img convert <source_xen_machine> -O vmdk <destination_vmware.vmdk> <dest_vmware.vmdk>
3. At this point, we have a valid VMware Server 1.xx disk image. This can be powered on onto any VMware Server. We need to do it anyway in order to build a .VMX file that will be later used. This stage also confirms whether the newly machine runs properly. </dest_vmware.vmdk>
3.1 Create a new virtual machine. Do not create a new HDD, but use the previously created vmdk.
3.2 Power it on in order to validate that it is usable and to allow the machine to reconfigure itself.
4. Move the VMware Server virtual machine to a Windows workstation running VMwareConverter.
5. Using VMware Converter, convert the VMware Server virtual machine to VMware ESXi.
Xen -> VMware VM Migration Steps (ESX Step)
1. Configure the virtual machine to boot first from CD-ROM drive.
2. Modify the machine's HDD SCSI controller type from BUS Logic to LSI Logic.
Edit Virtual Machine Settings > SCSI Controller 0 > Change type > LSI Logic.
3. Boot using Knoppix or the distribution's first CD.
4. Mount the VM's disk and chroot to it.
5. Get the disk architecture using fdisk -l, and modify /etc/fstab accordingly.
6. Create a new initrd image. You also must know the version of the running kernel. For example, if you are running kernel 2.6.18-1234, then the initrd command would look like this:
# mkinitrd -v -f /boot/initrd-2.6.18-1234.img 2.6.18-1234
7. Edit /boot/grub/menu.lst to boot from this initrd.
8. Keep your fingers crossed and reboot the machine.
Don't forget to re-configure your network card.
External references:
Configure two network bridge
CentOS 5.5
http://idolinux.blogspot.com/2008/08/xen-add-network-bridge-for-eth1.html
su -
vim /etc/xen/xend-config.sxp
#(network-script network-bridge)
(network-script twoNetBridge)
vim twoNetBridge
#!/bin/sh
/etc/xen/scripts/network-bridge "$@" vifnum=0 bridge=xenbr0 netdev=eth0
/etc/xen/scripts/network-bridge "$@" vifnum=1 bridge=xenbr1 netdev=eth1
service xend restart
Ubuntu 8.04
sudo vim /etc/xen/xend-config.sxp
#(network-script network-bridge)
(network-script twoNetBridge)
sudo vim /etc/xen/scripts/twoNetBridge
#!/bin/sh
/etc/xen/scripts/network-bridge "$@" netdev=eth0
/etc/xen/scripts/network-bridge "$@" netdev=eth1
service xend restart
creazione macchina
mkdir hylafax
cd hylafax/
mv /root/58.59.tgz .
dd if=/dev/zero of=hylafax.img bs=1k seek=4048k count=1
dd if=/dev/zero of=hylafax.swp bs=1k seek=1048k count=1
mkfs.ext3 hylafax.img
mkswap hylafax.swp
mount -o loop hylafax.img /mnt/
cd /mnt/
tar xfpvz /root/Desktop/hylafax/58.59.tgz
cd /mnt/
mkdir proc
mkdir sysfs
mkdir mnt
mkdir tmp
chmod +rwxt tmp/
chmod ugo+rwx tmp/
vim etc/fstab
reset
vim etc/sysconfig/network-scripts/ifcfg-eth0.bak
etc/sysconfig/network-scripts/ifcfg-eth0.bak etc/sysconfig/network-scripts/ifcfg-eth0
rm etc/sysconfig/network-scripts/ifcfg-eth1
rm etc/sysconfig/network-scripts/ifcfg-eth0.bak
vim etc/sysconfig/network-scripts/ifcfg-eth0
cp -av /lib/modules/2.6.16.46-0.12-xen/ /mnt/lib/modules/
/etc/xen/vm/hylafax.cfg
###############################################
kernel = "/boot/vmlinuz-2.6.16.46-0.12-xen"
ramdisk = "/boot/initrd-2.6.16.46-0.12-xen"
memory = 1024
name = "hylafax"
vif=[ 'mac=00:16:3e:4f:bd:c8,bridge=xenbr0', ]
#vcpus=2
#disk = ['tap:aio:dev/loop10,sda1,w', 'tap:aio:dev/loop10,sda2,w', ]
disk = ['file:/root/Desktop/hylafax/hylafax.img,sda1,w','file:/root/Desktop/hylafax/hylafax.swp,sda2,w',]
root = "/dev/sda1 ro"
extra = ' xencons=tty ROOT=/dev/sda1 single'
#apic=0
#acpi=0
pci=['00,1d,3']
on_crash="destroy"
on_poweroff="destroy"
on_reboot="restart"
localtime=0
#serial="pty"
###############################################
xm create /etc/xen/vm/hylafax -c
UBUNTU 8.04 HowTo
Based on:
http://www.howtoforge.com/high-performance-xen-on-ubuntu-8.04-amd64
and
http://www.howtoforge.com/perfect-server-ubuntu8.04-lts
Install OS (host) and SSH server
aptitude update
aptitude safe-upgrade
aptitude install openssh-server
Install Xen Kernel and utils
aptitude install xen-utils-3.2 ubuntu-xen-server
reboot
Checks
uname -a
Linux itb-s0030 2.6.24-26-xen #1 SMP Tue Dec 1 19:54:57 UTC 2009 x86_64 GNU/Linux
xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1879 4 r----- 720.6
Create VM WebServer
sudo -s
mkdir -p /opt/xen/vm
cd /opt/xen/vm
Create VM disks
dd if=/dev/zero of=webServerRoot.img bs=1k seek=8048k count=1
1+0 records in
1+0 records out
1024 bytes (1,0 kB) copied, 0,000115246 s, 8,9 MB/s
dd if=/dev/zero of=webServerSwap.img bs=1k seek=2048k count=1
1+0 records in
1+0 records out
1024 bytes (1,0 kB) copied, 0,00010514 s, 9,7 MB/s
dd if=/dev/zero of=webServerOpt.img bs=1k seek=8048k count=1
1+0 records in
1+0 records out
1024 bytes (1,0 kB) copied, 0,000115246 s, 8,9 MB/s
ls -al
total 10104
drwxr-xr-x 2 root root 128 2009-12-11 16:50 .
drwxr-xr-x 3 root root 72 2009-12-11 16:49 ..
-rw-r--r-- 1 root root 8438940672 2009-12-11 16:49 webServerRoot.img
-rw-r--r-- 1 root root 2147484672 2009-12-11 16:50 webServerSwap.img
Create filesystems on Images
mkfs.ext3 webServerRoot.img
mke2fs 1.40.8 (13-Mar-2008)
webServerRoot.img is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
516096 inodes, 2060288 blocks
103014 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2109734912
63 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
mkfs.ext3 webServerOpt.img
mkswap webServerSwap.img
Setting up swapspace version 1, size = 2147479 kB
no label, UUID=59fd6b42-207f-40d1-baaf-4df3a21eaaa8
mount root image
mount -o loop webServerRoot.img /mnt/
if beyound a proxy
export http_proxy=http://10.18.3.39:8080/
Install ubuntu 8.04 with debootstrap
debootstrap --arch amd64 hardy /mnt http://it.archive.ubuntu.com/ubuntu
Mount service directory (dev proc)
mount --bind /dev /mnt/dev
mount proc /mnt/proc -t proc
Copy network configuration/apt configuration files
cp /etc/resolv.conf /mnt/etc/resolv.conf
cp /etc/network/interfaces /mnt/etc/network/
cp /etc/apt/sources.list /mnt/etc/apt/sources.list
cp /etc/apt/apt.conf /mnt/etc/apt/
Create and populate modules dir for guest
mkdir -p /mnt/lib/modules/2.6.24-26-xen/
cp -R /lib/modules/2.6.24-26-xen/* /mnt/lib/modules/2.6.24-26-xen/
or
mkdir /mnt/lib/modules/`uname -r`
cp -R /lib/modules/`uname -r`/* /mnt/lib/modules/`uname -r`/
Enter in chroot on guest
chroot /mnt /bin/bash
update repository index and system
apt-get update
apt-get upgrade
Starting Up from debbootstrap it's necessary to setup language packs:
sudo apt-get install --reinstall openssh-server bash-completion language-pack-en language-pack-it vim ssh nfs-common mc
Create User (sudoer) and group:
useradd -m nikoz
passwd nikoz
groupadd admin
usermod -a -G admin,adm nikoz
check /etc/passwd that shell for nikoz is BASH and not SH
Modify fstab:
vim /etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/hda1 / ext3 defaults 1 2
proc /proc proc defaults 0 0
/dev/hdb1 none swap sw 0 0
/dev/hdc1 /opt/ ext3 defaults 1 2
10.18.3.44:/var/others /media/nfs_44 nfs auto,defaults,nolock 0 0
10.18.3.2:/opt /media/nfs_32 nfs auto,defaults,nolock 0 0
Modify /etc/network/interfaces and change the IP address of the guest OS
iface eth0 inet static
address 10.18.3.22 <---
Exit chroot:
exit
Copy sudoers file:
cp /etc/sudoers /mnt/etc/
umount /mnt/dev /mnt/proc /mnt
Create Vm configuration file:
mkdir /etc/xen/vm
vim /etc/xen/vm/webserver.cfg
kernel = '/boot/vmlinuz-2.6.24-26-xen'
ramdisk = '/boot/initrd.img-2.6.24-26-xen'
memory = '512'
#
# Disk device(s).
#
root = '/dev/hda1 ro'
disk = ['tap:aio:/opt/xen/vm/webServerRoot.img,hda1,w',
'tap:aio:/opt/xen/vm/webServerSwap.img,hdb1,w',
'tap:aio:/opt/xen/vm/webServerOpt.img,hdc1,w',]
#disk = ['phy:/dev/sda2,hda1,w',]
#
# Hostname
#
name = 'domu1'
#
# Networking
#
vif = [ 'mac=00:16:EF:FE:00:11' ]
#
# Behaviour
#
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
vcpus = '2'
extra = 'xencons=tty1'
Start the Vm:
xm create /etc/xen/vm/webserver.cfg -c
Start Vm at boot time:
ln -sf /etc/xen/vm/webserver.cfg /etc/xen/vm/auto
Setup Web Server:
Change hostname:
vim /etc/hostname
itb-s00322
vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
10.18.3.22 ITB-S00322
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
for a centralized nfs server apt archive
cd /var/cache/apt/
mv archives/ archives.local
ln -sf /media/nfs_32/archives/server/8.04/64/ archives
Install all Packages:
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
