Archive for March, 2009
Arch Linux under VMware and Windows
Arch Linux meets VMware 6.5 on Windows XP
Software Used
References
- Installing Archlinux in VMware
- All VMware 6.5 Workstation Documentation
- VMware 6.5 Workstation User Manual (pdf)
- Timekeeping in VMware Virtual Machine (pdf)
- Arch Linux Official Install Guide
Why Linux in a VM
I’m not a big fan of Linux on the Desktop, especially with a laptop. While Linux has come a very long way in the years since I’ve been using it, there are still some problems: Ugly fonts, problems with ACPI (i.e. Standby, Hibernate, etc), an increasingly inferior Linux version of Firefox (versus its Windows counterpart), etc. Really, Windows XP is more than adequate for the majority of my desktop needs; the only part of a real *nix OS that I miss is the command line.
With this in mind, I’m looking for a fast and lightweight Linux version that I can run within VMware under Windows. The latest versions of Ubuntu, Fedora, Suse, etc. have their advantages, but are becoming so big and bulky that even a Linux guru would have a hard time figuring out what all the files under /etc do. What I really want is a distro where I can, actually, understand each file in /etc, uses standard Unix initialization scripts, and does not require a GUI at all since I’m not planning on installing X Windows. After browsing Distrowatch.com, it looks as if Arch Linux fits the bill perfectly – optimized for 686 processors, a lightweight ISO download (about 300 megs), a nice package manager, Pacman, and a traditional BSD style init system that I can completely understand!
Download and Install VMware
Download VMware Workstation from the above link. VMware Workstation is not a free product, though you can register with an email address and get a 30 day trial version which will suffice for now. The activation code will be sent to the email you used to register, and you will need it to install the product. The installation itself is as easy as clicking on the downloaded installer and following the prompts. Although VMware Workstation isn’t free, we only need the full version to create the Arch Linux virtual machine – once we’ve created it, we can uninstall the Workstation and install VMware Player which will allow us to continue to use our Arch VM.
Also download the latest version of Arch Linux, which currently is 2009.02. I went ahead and downloaded the full ISO which is only about 3.5 GB – not too bad considering Red Hat now requires a full DVD. Impressively, you won’t even need to virtually mount or burn the iso to disc – VMware can use just the downloaded ISO file itself!
Configuring the Virtual Machine
After you’ve installed and activated VMware and downloaded the Arch iso, we’re ready to create the virtual machine:
- Open up VMware and click on the New Virtual Machine button.
- Choose the Typical option unless you have some very strange configuration needs, such as non-standard SCSI disc types, multiple processors, etc.
- Choose Installer disc Image file(iso) and browse to the location where you downloaded the Arch iso.
- Choose Linux as the Guest Operating System Type and select Other Linux 2.6.x Kernel as your version. Be careful in choosing between 32 and 64 bit depending on your processor type.
- Select a name (I just used Arch 2009.02) and location for the virtual machine file. The file will need about 8 Gigs of free space depending on how large you want your VM to be.
- Set your size – I went with the default of 8 Gigs which should be more than enough for now. VMware can increase the size later if you need more.
- Finally, you can modify any other settings. The default ram setting allows for 256 megs, but my laptop has 2 Gigs, so I bumped this up to 512 MB. The only other setting you’re likely to modify is the network type. I went with NAT, which will set the Linux VM similar to how a PC is configured when using a typical home router to share a cable/DSL internet connection among multiple users.
Installing Arch
Immediately after confirming your settings, VMware will boot the ISO up as if it were physically in the CD-Rom drive and you had reboot the PC.
Installing Linux now is exactly the same as if you really had booted the CD physically. The only thing to remember is that the hard disc that the Linux kernel will ’see’ is the VM file that is on your hard drive. The kernel can absolutely *not* access any part of the disc outside of this file. Therefore, when partitioning your system, you can go ahead and choose a typical partition scheme without worrying that Linux will overwrite the actual hard drive (i.a. the partition that Windows physically boots and lives).
Depending on which view (full screen, unity, etc) you are using to see the VM, you may have problems with the mouse/keyboard at first, especially since there is no mouse support in the standard Arch console. In other words, once you click into the Arch VM, you will not be able to access your mouse to get out of the VMware window and back to the Windows desktop. The solution is to use the following kb shortcuts:
To go from the Windows desktop into the Arch VM, either click inside the VM window or Ctrl-g
To get out of the VM and back to Windows: Ctrl-alt.
Setup Arch Linux
Login as root and run /arch/setup
0 – Select Source
Since we downloaded the full install iso, we can choose Cd-Rom as our source. If you only downloaded the ftp iso (which is several gigabytes smaller), you’ll need to choose ftp/http option. With the ftp option, you’ll have to also figure out to setup the network adapter in order to access the package repositories. This is covered in a later section
1 – Set Clock
Both Linux and Windows obtain the current time from the Bios. If this were a default install on a non-dual-boot/non-vm machine sharing Windows, UTC would be the best option. Windows, however, will ‘modify’ the Bios clock to what it considers Local Time, and like many other options, Windows cannot/will not allow modifications, while Linux, of course, is not so demanding, and can work around Windows’ limitations. On a dual-boot machine, we would have to use Local Time so that Linux would not corrupt the internal clock with regards to the Windows install. However, since Linux will be running in a virtual machine, the actual ‘bios’ that it sees is not the hardware itself, but instead the virtual hardware provided by VMware. This includes the ‘virtual’ bios and its clock. Thus, we can go ahead and use UTC and also setup the correct time zone.
After setting the time zone, the Linux time was still several hours behind the actual local time. For now, we’ll just ignore this; later, we’ll use VMware Tools to keep the Linux VM in sync with our Windows install, which itself uses NTP to synchronize time with time servers on the internet.
2 – Prepare Hard Drive
You may partition your hard drive any way you like, including using the default Arch settings by choosing Auto-Prepare. The one thing to remember, though, is that the Linux kernel running in the virtual machine does not see the actual physical hard drive(s). Instead, it only sees a virtual hard drive provided by VMware; this virtual hard drive is essentially mapped to the virtual machine image file on Windows. There, unless you’re using a very strange virtual hardware setup, you’ll see your hard drive from within Linux as a single 8 gig (or whatever size you choose during the VM configuration) drive mapped as sda. I went ahead and choose Auto-Prepare which created the following partitions:
| File | Size |
|---|---|
/boot |
32 MB |
Swap |
512 MB |
/ |
6.5 GB |
/home |
1.1 GB |
For my file system type, I went ahead with Ext3; though ext4 is currently available, it is still quite new and there are probably a few bugs lurking within the code.
3 – Select Packages
I choose both the base and base-dev packages and used the default individual apps presented. I went ahead and added openssh, openssl, and sudo, also, so I can run an SSH server (allowing me to transfer files via SFTP from the host).
4 – Install Packages
This will have been completed after selecting your packages as outlined in the previous section. If you downloaded the full ISO, and selected CD-Rom as your source in step one, this will only take a minute or two.
5 – Configure System
With the packages installed, we now need to setup our virtual machine, including network settings, servers, etc. The two editors you may choose from our Vi and Nano. If you’ve never heard of either, you’ll definitely want to use Nano. Furthermore, most of these files are already nicely explained in the Arch Install Guide, so we’ll just concentrate on the differences as dictated by running Arch within VMware.
/etc/rc.conf
VMware NAT setup (from VMware manual)
rc.conf is definitely the most important config file for BSD like systems, including Arch. Most of the lines will have already been set to the correct settings from previous configuration options and/or can be left alone. However, we do need to figure out how VMware has set up our virtual network. Since I choose NAT during the VM setup, we will be using DHCP to obtain our network settings, including ip address and dns servers. To find out how VMware has set up the NAT/DHCP servers, hit ctrl-alt to switch between Linux and Windows. Go back to the VMware window and click on edit -> Virtual Network Editor. By default, VMware will create a Virtual Switch named VMnet8 to handle NAT.
If we switch to the NAT tab and select VMnet8, we see that the gateway IP address from the point of view of the Linux VM is 192.168.2.17 with a subnet mask of 255.255.255.0. Therefore, the following lines in the Networking section of rc.conf are modified:
HARDWARECLOCK="UTC"
eth0="dhcp"
INTERFACES=(eth0)
gateway="default gw 192.168.17.2"
ROUTES=gateway
Also, we add sshd to our daemons line in order to allow SSH server to start up on boot:
DAEMONS=(syslog-ng, network, netfs, crond, sshd)
Refer to VMware Workstation Manual chapters 14 and 15 for more help in understanding how VMware sets up the Network.
/etc/resolv.conf
As long as we’re using DHCP and have set up our network configuration correctly as per above, this file can be left untouched as the DHCP client will overwrite this file with the correct settings upon system bootup.
/etc/hosts, /etc/hosts.allow, /etc/hosts.deny
hosts.deny may be left alone. However, we want to initially allow our Windows install to be able to transfer files via SFTP to the Linux virtual machine. Therefore, allow ssh connections to be allowed into the Arch machine. We could limit it to just the host machine’s ip address, but since VMware’s NAT will already allow block, by default, connections not originating from the host, there is no reason to get paranoid. On a real production server(s) running in a VM, there is a quite a bit of tweaking one could do to these files to allow the proper access controls.
Running on a virtual machine under VMware, the only host will need to allow connections from is our host Windows operating system, and the only line we need is:
/etc/hosts.allow
sshd: 192.168.17.
We’ll add our single localhost name to the hosts file. Since I left the default hostname as myhost in /etc/rc.conf, I’ll use it here. If you used another hostname, you’ll have to make the appropriate substitution here.
/etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 myhost.localdomain myhost
Forgetting to set this correctly will cause all sorts of strange problems. The first time I did this, opening up a file with a text editor would take nearly 30 seconds. It took a bit of Googling to figure out that the hosts file was the culprit.
For more info on these files, see the man pages:
/etc/pacman.d/mirrorlist
In the past, this file would not need to be modified; however, the first mirror is by default set to the ArchLinux official ftp repository. Unfortunately, this is now being throttled, and your package upgrades and installs will be very slow if this is your first line in the mirrorlist. Therefore, just comment out the first line assuming it points to ftp.archlinux.org…
#Server = ftp://ftp.archlinux.org/$repo/os/i686
Root Password
Finally, make sure you set a root password. Normally, you’d want to make this a very hard-to-guess word; however, when running in the virtual machine under a standard Windows install, no network connections not based within the VM will be able to access the Linux VM, so you can be a little less cautious
After finishing the configuration file section, go back to the main menu. The Arch setup program will create the initial ram disk the Kernel will use to bootstrap itself.
6 – Install Bootloader
Choose Grub as the default bootloader. You’ll then be thrown into an editor in order to configure the options. When dual-booting, you’d normally have to make sure that your Windows partition(s) were listed here. However, within a virtual machine, no other partitions can be seen since, as noted previously, the hard drive that is actually being written in the VMware virtual file. The only setting I made was to increase the size of my console, as the default was a little small on my 14 inch widescreen. I used a standard 1024/768 console size with color by appending the following to my default kernel line: vga=775
Finally, go ahead and choose /dev/sda as the partition on which Grub should be installed. Though Linux will think it is writing to the MBR of the main hard drive, it is really just writing an MBR on the virtual image’s file.
Finishing Up
Your system should be completely setup and installed now. In the bottom of the VMware window within Windows, you’ll notice a few buttons to finish installing, change discs, cancel. Luckily, Arch Linux is contained on a single disc (one of the reasons I prefer Arch), so we can go ahead and complete the install. Exit the setup menu, and go ahead and type reboot at the prompt. Arch Linux will now reset and automatically start up Grub. Choose the default Kernel to boot, and when it finishes booting up, switch back to Windows with a ctrl-alt. Click on the Finished Installing button in the VMware window.
Your virtual Linux machine should be ready to go!
On the first reboot, a few problems crept up that are due (I’m guessing) to an error with the time settings. First, when I check the time in Linux, an incorrect time is given that is several hours before the actual time. Also, a bunch of errors were listed on first boot regarding the file system (when it is checked for errors). Warnings included comments to the effect that some file system accesses had been done in the future. Obviously, since the last time these file systems were mounted was during the install, and I’m guessing the errors are due to the clock being out of sync upon the reboot. Will have to look more into this…
If you reboot the system, Arch Linux should now start vm-tools automatically. At this point, we have a nice and fresh Linux system easily available to us from within Windows. If there are any other apps that you know you’ll always want as part of your default system, go ahead and install them now with Pacman. For example, I went ahead and installed the following:
- Emacs – not a big vi fan, myself
- man-pages – the default Arch Linux install does not include quite a few of these. After installing the package, go ahead and run the command makewhatis – in order to index the man page database, which you can search through with the apropos command.
- htop – nice replacement for the standard top process viewer.
- most – colorful replacement for less
Now that you’ve got your required apps, one last thing to do would be to update the system in order to install the latest patches. Pacman makes this easy:
pacman -Su
Installing VMware Tools
VMware Tools is a group of several services that run on the guest operating system. It helps provide time synchronization, message passing, file sharing, shutdown abilities from the host, mouse and resolution support, etc. Since we are not going to be installing X-Windows, support for screen size and mouse use isn’t important.
Fortunately, Arch Linux provides an open source version of of the tools known as Open VM Tools in its repository. There are a few caveats to follow when using a version of VMware prior to 6.5. However, it is now extremely easy to setup the tools with version 6.5. Following the Arch Linux in VMware Tutorial, we’ll sync the package manager database and also install the tools with Pacman:
pacman -Sy
pacman -S open-vm-tools
The tools and its few dependencies will be downloaded and installed. The service script will be installed under /etc/rc.d. If you look in the directory, you’ll see that Pacman has installed a script for starting open-vm-tools. By default, Arch starts all scripts that are configured within /etc/rc.conf. In this file, make sure the Daemons line includes the tools:
DAEMONS=(syslog-ng network netfs crond sshd open-vm-tools)
Installing the Shutdown / Restart / Suspend Scripts
Begin by clicking on the VM menu link within Windows, and select Install VMware Tools. This will essentially mount a virtual CD image with the tools within the Linux guest VM. Go back into Arch Linux, and as root mount the cd:
mount /dev/sr0 /mnt/cdrom
For some reason, my cdrom is now showing up as /dev/sr0 and not /dev/cdrom as usual. You may have to use mount /dev/cdrom /mnt/cdrom if your cdrom is configured as expected by the Kernel…
After mounting, you should cp the file VMware Tools-X.X.X.tar.gz to a permanent directory, untar and unzip it:
cp VMware Tools-X.X.X.tar.gz ~
cd ~
tar xvzf VMware Tools-X.X.X.tar.gz
For some reason, open-vm-tools does not install the correct scripts that allow one to shutdown/restart/suspend the Linux guest from within Windows via VMware. Therefore, we need to mount the official VMware-tools package from Windows, unzip the distro, and copy the scripts on over to are Linux install.
Within the new directory that you’ve just expanded, go into the /etc directory and copy the following scripts to newly created VMware-tools directory within /etc
mkdir /etc/VMware-tools
cp poweroff-vm-default /etc/VMware-tools
cp poweron-vm-default /etc/VMware-tools
cp resume-vm-default /etc/VMware-tools
cp suspend-vm-default /etc/VMware-tools
You can go ahead and delete the VMware Tools tar file and expanded directory if you like. After unmounting the cdrom, reboot Arch using the standard shutdown -r now. You go back into Windows and VMware and be able to shutdown/restart/suspend Arch Linux via the VMware menu VM -> power -> Shutdown / Suspend / Restart Guest menu item!
File Sharing
As long as you’ve successfully installed the VMware-tools (or Open VMware Tools via Pacman as previously described), you can easily share files between the Windows XP host and the Arch Linux Guest. Though it would be possible to set up Samba to share files via the virtual ethernet connection, VMware Tools makes the process far easier.
Start from your Windows VMware window with your Arch Linux OS chosen as the current virtual machine. Go to the menu and click VM -> Settings. Your guest VM’s hardware configuration window will open up; click on the options tab and then choose Shared Folders. Add as many folder from your Windows box as you’d like available within the Arch guest.
Click back into the Arch virtual machine and, as root, open up /etc/fstab. Here you’ll enter a line specifying the share to be automounted on boot. The standard mount point is /mnt/hgfs which is named after VMware’s sharing file type, though you can create any directory you like. Append a line to /etc/fstab similar to the following, customizing the options if desired
.host:/ /mnt/hgfs vmhgfs defaults,user,ttl=5,uid=root,gid=wheel,fmask=0113,dmask=0002 0 0
The permissions mask mounts the root of the shared directories with owner root. If you have added more users, you can add them to the wheel group in order to give that user both read and write access to the shared directories.
After successfully installing the tools, I noticed that when shutting down the system, i would get an error:
module vmhgfs is in use
This was being caused by the /etc/rc.d/open-vm-tools script attempting to remove the vmhgfs module from the kernel before the shared folder from my Windows host had been cleanly unmounted. Unfortunately, the unmounting of filesystems stage is after open-vm-tools is executed. I ended up fixing this by explicitly unmounting the shared folder before attempting to remove the vmhgfs module within the /etc/rc.d/open-vm-tools:
[ -z "$VMGHFS" ] && umount /mnt/hgfs && rmmod vmhgfs
Substitue your shared folder’s mount location for /mnt/hgfs if different than mine
Creating a Snapshot
Now that your base system is installed and configured to your liking, we’ll create a snapshot of our pristine Linux install. That way, we can always reset our system to the default should the need arise in the future.
- Go back to Windows and the VMware window itself via ctrl-alt
- Make sure you’re context/tab is in your new Arch Linux install, and click on the VM menu item.
- Click on the snapshot -> take snapshot menu items.
- Give the snapshop a name and description. I gave it a name of Pristine Arch Linux 2009.02, and listed the current state of the OS in the description. For example, fresh install with open-vm-tools, a list of extra packages installed, etc.
After the snapshot image is saved to the Windows hard drive, you can then go into the Snapshot manager in VMware and revert to this state anytime. I moved the image file itself to a second hard drive for safe keeping!