Showing posts with label Virtualization. Show all posts
Showing posts with label Virtualization. Show all posts

Tuesday, July 21, 2015

XenServer and NTP

After spending hours and hours trying to set up the timezone and hwclock via ntp on a Debian 7.8 Wheezy VM on XenServer 6.5 I gave up and ended up setting the timezone to UTC because the clock was only displayed correctly if the tz was UTC (damn bad).

I came up this morning with the idea of checking the time of the XenServer dom0 to see if at least the physical box had its time ok. Big was my surprise when I realized the dom0's time was also skewed just like in the VMs as stated on [1]

I restarted the NTP daemon because I configured it to point to the ntp pool when setting up the box. Big was my surprise when I realized the NTP daemon was starting, but the synchronization was failed:

[root@xenserver ~]# service ntpd restart
Shutting down ntpd:                   [  OK  ]
ntpd: Synchronizing with time server: [FAILED]
Starting ntpd:                        [  OK  ]


I restarted the NTP daemon on the old fashioned way, since the XenServer 6.5 is based on CentOS, that shouldn't be an issue.

[root@xenserver ~]# /bin/bash -vx /etc/init.d/ntpd restart

After some output, I realized the script runs ntpdate to get the synchronization done like this:

ntpd: Synchronizing with time server: + /sbin/ntpdate -U ntp -s -b 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org

After running the command with debug and verbose flags I realized that there was something wrong with using an privileged port and dropping privileges to the ntp user, so turning on the -u flag on /etc/sysconfig/ntpd was the right way to do it. [2] [3]

[root@xenserver ~]# cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -x"

# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=no

# Additional options for ntpdate
NTPDATE_OPTIONS="-u"


After the change everything went smoothly:

[root@xenserver ~]# service ntpd restart
Shutting down ntpd:                   [  OK  ]
ntpd: Synchronizing with time server: [  OK  ]
Starting ntpd:                        [  OK  ]


--
= ^ . ^ =

[1] http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/guest.html#time_linux
[2] https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sect-Date_and_Time_Configuration-Command_Line_Configuration-Network_Time_Protocol.html
[3] http://linux.die.net/man/8/ntpdate

Tuesday, November 15, 2011

zerofree - Zero out space on a virtual machine

Today, I had to shrink a virtual machine size for deployment.

I like the zerofree utility that clears the unallocated blocks in a ext2/ext3/ext4 filesystem.

Take a look at the code snipplet

First go to single user

# init 1

Then do the magic

# for i in `mount | grep sda | grep ext | cut -b 9` ; do mount -o remount,ro /dev/sda$i && zerofree -v /dev/sda$i && mount -o remount,rw /dev/sda$i ; done ;

And here is a sample on a VirtualBox VM



--
= ^ . ^ =

Tuesday, September 27, 2011

Sep 27th 2011 - Transfer data between virtual machine and host without network

Today I needed to transfer data between a virtual machine and the host.

The main problem was the lack of networking support in MINIX v3.1.0 (the virtual machine) so I could not scp or ftp anything between the systems.

I came to rescue the day with the idea of a special sneakernet between the virtual machine and the host.

On the host

  • Create the floppy image on the host.

    % dd if=/dev/zero of=floppy.img bs=1024 count=1440


  • Attach the floppy image to the virtual machine.

    The process depends on the virtualization software so is left as exercise to the reader.


On the virtual machine

  • cd to the data (let's call it payload, shall we?.

    $ cd /home/tonejito/payload


  • tar the relevant files into the floppy device (/dev/fd0)

    $ tar cvvf /dev/fd0 file file file ...


On the host

  • Detach the floppy image from the virtual machine

    Another exercise left to the reader

  • Extract the files
    % tar xvvf floppy.img

  • List the contents

    % ls
    floppy.img file file file



That's all