This morning I tried to install Debian 7.6 64bit on the DELL PC, but it failed due to some hardware problems. Then I installed LinuxMint 17 Xfce 64bit on this machine, and partition disk following Xen Project Beginners Guide:
chad@chadpc ~ $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 276M 45M 218M 17% /boot /dev/sda2 15G 4.1G 9.8G 30% / ...
where /dev/sda1 is formated as ext2, and /dev/sda2 is formated as ext3, and leave /dev/sda4 unused.
After reboot and login LinuxMint, modify apt mirror list according to Official Archive Mirrors for Ubuntu, adding the following lines into /etc/apt/sources.list:
deb http://mirrors.zju.edu.cn/ubuntu/ trusty main
deb-src http://mirrors.zju.edu.cn/ubuntu/ trusty main
deb http://ubuntu.cnssuestc.org/ubuntu/ trusty main
deb-src http://ubuntu.cnssuestc.org/ubuntu/ trusty main
Then run commands as root:
apt-get update
apt-get install openssh-server
apt-get install lvm2
pvcreate /dev/sda4
vgcreate vg0 /dev/sda4
apt-get install bridge-utils
brctl addbr xenbr0
brctl addif xenbr0 eth0
dhclient xenbr0
aptitude -P install xen-system # not xen-linux-system
dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
update-grub
reboot
# you can find now "Ubuntu GNU/Linux, with Xen hypervisor" is the default startup item in grub boot menu
Build DomU
apt-get install xen-tools
Using xen-create-image
xen-create-image --hostname=ch1 --memory=1024gb --vcpus=2 --lvm=vg0 --dhcp --pygrub --dist=wheezy
Using xl
Follow Debian Guest Installation Using Debian Installer.
Here we download 2 net-install disk (which is very small) and install the guest system via Internet. So the host machine need to connected with Internet, or can connect to another machine which can access Internet, and defining a proxy when installing.
Select a mirror ftp.cn.debian.org/debian/ in Debian worldwide mirror sites. And download vmlinuz and initrd.gz (from http://ftp.cn.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/xen/) to local folder /home/chad/warez/xen-images-debian.
Create a config file /root/deb.cfg:
name = "debian-installer"
memory = 1024
disk = ['phy:/dev/vg0/debian-installer,xvda,w']
vif = [' ']
kernel = "/home/chad/warez/xen-images-debian/vmlinuz"
ramdisk = "/home/chad/warez/xen-images-debian/initrd.gz"
extra = "debian-installer/exit/always_halt=true -- console=hvc0"
Then run following commands as root:
lvcreate -L 4G -n debian-installer /dev/vg0
xl create -c /root/deb.cfg
Once installation has completed the guest will shutdown and exit. Remove the kernel, initrd and extra lines from the guest configuration, here remove the last 3 lines in deb.conf and replace them with simply:
bootloader = "pygrub"
Now the deb.conf became:
name = "debian-installer"
memory = 1024
disk = ['phy:/dev/vg0/debian-installer,xvda,w']
vif = [' ']
bootloader = "pygrub"
Startup the guest system with xl create -c deb.cfg.
List all running vms with xl list in dom0.
Connect this vm with xl console debian-installer.
List all available subcommands of xl with xl help.
Shutdown this vm with xl shutdown debian-installer
Post installation
The "brctl" and "dhclient" commands above only build the network interface during system session. After system reboot, the bridge interface disappears, thus startup vm will failed. So we need define the bridge in /etc/network/interfaces, add the following lines into this file:
auto eth0
iface eth0 inet dhcp
auto xenbr0
iface xenbr0 inet dhcp
bridge_ports eth0
If after reboot, the eth0 can't get IP address, use ifdown eth0 and ifup eth0 to refresh eth0.
Update 2014.10.31: these settings cause network connection failed. After removing "auto xenbr0..." section, everything goes fine.
So use brctl and dhclient to setup bridge after system startup.
Notes:
-
Use
lsblk -fto see the volume group and logical volumes. -
pvcreate means "create physical volume", vgcreate means "create volume group", lvcreate means "create logical volume".
-
Use
lvremove /dev/vg0/debian-installerto remove the logical volume created before. -
Use
dpkg-divert --listto list all diversions, anddpkg-divert --remove /etc/grub.d/20_linux_xento remove a diversion.
Ref: