Thursday, February 9, 2017

Configure CentOS 6 VNC Server

One of the first things I like to do when provisioning a CentOS 6 server with a desktop GUI is to configure remote desktop; but the standard/included server (vino) only works when a user is already logged in. I want to usually be able to log-in remotely (in other words, have my VNC session log me in to a machine that has no users logged-in).

First, install and enable the VNC server:
# yum install tigervnc-server
# yum install xorg-x11-fonts-Type1
# chkconfig vncserver on
Set VNC password for your user:
# su - USER
# vncpasswd
# exit
Add the following lines to the following file:
# vim /etc/sysconfig/vncservers 
VNCSERVERS="1:USER"
VNCSERVERARGS[1]="-geometry 800x600"
Add port 5900 (TCP and UDP) to your firewall allow rules (I just did this graphically at the machine's physical terminal, but you can use iptables in the CLI).

See if VNC server comes up:
# service vncserver restart
Edit the user's vnc configuration to replace the "twm &" line with the following:
# service vncserver stop
# vim /home/USER/.vnc/xstartup 
exec gnome-session &
Test VNC server startup again:
# service vncserver restart
At this point, you should be able to point a VNC client at your machine, and you will automatically be logged-in. Note, it usually takes a little time... up to a minute or so, typically.

Thursday, January 19, 2017

Adding a JAR to an Android Studio Project

I recently needed to add some TFTP functionality to an Android app I've been working on. I opted to leverage the Apache Software Foundation's Commons-Net libraries. If you download the binaries, there is a .jar file you can use in your Android project.

To import the library into your Android Studio project, it's pretty simple.

  1. Create a new directory (if it isn't there) in your project called "libs."
  2. Copy the .jar file to your clipboard.
  3. In Android Studio's "Project" view, expand your project's app/libs branches.
  4. Paste the .jar file to the libs directory.
  5. Right click the .jar file, and then choose "Add As Library."
At this point, Gradle will rebuild, incorporating the new library into your project's builds; so at this point, you should be good to go. Import your library as needed and use it.

Tuesday, December 6, 2016

Migrating VMware Workstation Guests to KVM/qemu

I recently had the need to get one of my VMware Workstation guests (running CentOS 6.4) migrated to a KVM/qemu hypervisor environment. The VM was in the typical multiple file vmdk configuration that VMware Workstation uses.

Note: I've read that if you're migrating a Windows guest or a SCSI-originated guest (or something to that extent), you may get a BSOD or some other boot error. So this may not work for every case.

In summary, the process basically involves converting that multiple file setup into a single file, and then moving that single file into your storage pool for your KVM setup, from which you then import it. Of course, the devil is in the details, so...

Step 1 - Convert VMware multiple file VM into a single file
(note: if you have snapshots, it's best to delete those to ensure you're getting the latest image)
(note: your paths will vary)
# vmware-vdiskmanager -r /home/vm/vmware/c64/c64_disk.vmdk" -t 0 /home/c64.vmdk

During this, I got an error ("VixDiskLib: Invalid configuration file parameter.  Failed to read configuration file.") but I was able to continue on just fine. I assume this is about the VM's configuration, but since I was changing RAM amount and network stuff anyway, I didn't care.

Step 2 - Copy that single file to your storage pool / import location
(note: I'm doing it this way, as the next step is resource-intensive and my destination machine is faster - also, your paths will vary - also, I've setup my storage pool to not be the standard /var/lib/libvirt!)
# rsync -av /home/c64.vmdk [dest-machine]:/home/vm/c64/

Step 3 - Login to destination machine and convert the vmdk into a qemu-compatible format
(note: this will become your VM's main disk image file, so just put it in your pool where you plan on leaving it for the machine)
# qemu-img convert /home/vm/c64/c64.vmdk -O qcow2 /home/vm/c64/c64.img

Step 4 - Start virt-manager and import the VM
# virt-manager
- Create a new machine.
- Choose "Import existing disk image" option.
- Continue configuring it as necessary, and then boot it.

After all is said and done, you will need to tweak a few things (e.g. NIC/MAC, persistent net rules file, etc.), but you should basically be up and running.

Thursday, December 1, 2016

Headless CentOS 7 Virtualization Host: Part 1 - Host Installation & Setup

Here is how I setup a headless (no monitor) VM host on CentOS 7.2

Ensure your host's CPU can support virtualization (the result should be > 0):
# egrep -c '(vmx|svm)' /proc/cpuinfo
Install the KVM hypervisor and its necessary packages (this is competitive with vmware):
# yum install kvm libvirt virt-install qemu-kvm
Make sure the host's kernel is ready to perform NAT with the hypervisor for the VM guests. First we'll enable IP forwarding on the host:
# echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
# sysctl -p /etc/sysctl.d/99-ipforward.conf
Then, we'll modify the network adapter's configuration to use a bridge adapter (in my case, I'm using eth1). Open the config file for editing, comment out everything IP-related (IP, gateway, DNS, etc.), and add a link to the bridge configuration file that we'll add next:
# vim /etc/sysconfig/network-scripts/ifcfg-eth1
BRIDGE=virbr0
Next, we need to create a bridge adapter configuration file and add the following lines (your info will probably be same as what you commented out above):
# vim /etc/sysconfig/network-scripts/ifcfg-virbr0 
DEVICE="virbr0"
TYPE=BRIDGE
ONBOOT=yes
BOOTPROTO=static
IPADDR="[YOURS]"
NETMASK="[YOURS]"
GATEWAY="[YOURS]"
DNS1="[YOURS]"
If possible, reboot the machine to ensure kernel modules and network settings load and initialize.

Finally, just verify your installation and configuration:
# lsmod | grep kvm
# ip a show virbr0
# virsh -c qemu:///system list

Tuesday, November 29, 2016

Linux Partitions >2TB

For Linux hard drive partitions larger than 2TB, fdisk just doesn't cut it. You'll have to use parted, instead. But keep in mind that since this parted method uses GPT (part of EFI) instead of the old MBR type supported by most/all BIOS, you'll need to make sure your BIOS supports it (most newer ones should).

The example I'm using in my case was for a brand-new 3TB secondary storage device (no existing partitions), with the primary drive being for boot and of the MBR type on a smaller dedicated hard drive... hence "sdb" in the example below, instead of "sda."

First, verify the size of your drive:
# fdisk -l /dev/sdb
Then, get into the GNU parted shell:
# parted /dev/sdb
Once in the parted shell, issue the following commands...
First, create a GPT partition table:
(parted) mklabel gpt
Second, tell parted you'd like to use TB as the unit:
(parted) unit TB
Then, tell parted to create the 3TB partition:
(parted) mkpart primary 0.00TB 3.00TB
You may verify the partition table and quit:
(parted) print
(parted) quit
After that, all you have to do is create your file system and mount the drive.
 
 

Friday, October 28, 2016

Safely Enlarging a Linux /home Partition

I recently cloned a 1TB server hard drive onto a 1.2TB disk, using Clonezilla. This resulted in 0.2TB being unutilized, so I had to enlarge it. But how to do so without losing your data? Something like this (in my case, I needed to enlarge /dev/sda3, a primary partition):
# fdisk /dev/sda
Print the current partition table (so you can note the starting cylinder of the partition you're going to enlarge).

After noting the starting cylinder, delete the third partition.

Re-create the third partition. You MUST make sure it starts with the cylinder noted above! In my case, this was all just defaults. When done, just write the table to disk and reboot.

Next, you'll use the resize command in Linux to expand the file system to match the partition it's on.
# resize2fs /dev/sda3
Here is what I was presented with, information-wise. The process took merely about a minute.
resize2fs 1.41.12 (17-May-2010)Filesystem at /dev/sda3 is mounted on /home; on-line resizing requiredold desc_blocks = 55, new_desc_blocks = 67Performing an on-line resize of /dev/sda3 to 279054750 (4k) blocks.The filesystem on /dev/sda3 is now 279054750 blocks long.
Very painless!

Before (df -h):
/dev/sda3       865G  7.2G  814G   1% /home

After (df -h):
/dev/sda3       1.1T  7.2G  988G   1% /home

Thursday, August 18, 2016

Mount Linux NFS Share on a Mac

So apparently, you cannot just mount "-t nfs" a Linux NFS share on Mac OS X. Credit for this find goes to: http://www.cyberciti.biz/faq/apple-mac-osx-nfs-mount-command-tutorial/

Make sure your /etc/exports are right and then check...
$ showmount -e [nfs-server]
 If all is good, mount with the following command (omit the ",rw" if desired)...
$ sudo mount -t nfs -o resvport,rw [nfs-server]:/[exported-dir] [mount-point]