Friday, March 22, 2013

smartos: add additional disk from a different zpool

I have 2 zpools

  pool: zones
  pool: zpool_repos


I want to add to a KVM machine a disk living not in the zones pool, but in the other one.

My VM is already provisioned.
First of all I must stop it.

vmadm stop <uuid>

Now I create a ZFS volume

zfs create -V 10G zpool_repos/mykvmdata

Now I create a json file for the update

vi adddisk.json

{
   "add_disks": [
      {
          "media": "disk",
          "model": "virtio",
          "nocreate": "true",
          "boot": false,
          "path": "/dev/zvol/rdsk/zpool_repos/uuu"

      }
   ]
}

Now I update the KVM machine.

vmadm update 5942c90f-ecbb-4acd-822f-43e1901e2eb6 -f dataset.json

That's all.
Now, after starting the virtual machine, from inside it, I must partition the new disk (i.e. /dev/vdb in linux) and format.

Thursday, March 14, 2013

iPxe server (on CentOS) to serve SmartOS

This document talks about how I set up an iPXE server on CentOS 6 mainly to serve SmartOS.
Although I've not understood some things (like undionly or the fact that there are many dhcp requests from the pxe client) the following procedure works for me

Links

Install dhcp and tftp services

yum install dhcp.x86_64
yum install tftp-server.x86_64 

Get iPXE undionly


cd /var/lib/tftpboot/
curl http://cuddletech.com/IPXE-100612_undionly.kpxe > undionly.kpxe 
curl http://boot.ipxe.org/undionly.kpxe > undionly.kpxe

Download iPxe

Optional.
Useful to get some network modules if the client uses gPxe (like KVM one) that is unable to work with iPxe
cd /root
mkdir git
cd git/
git clone git://git.ipxe.org/ipxe.git
cd ipxe/src
make
make bin/ipxe.pxe
cp bin/ipxe.pxe /var/lib/tftpboot/
  
 

DHCP Configuration

It is useful to configure the DHCP server to provide IP addresses only to known MAC addresses. I think it is also useful to link MAC addresses with IP addresses. So a server always get the usual IP.

Note: 192.168.56.10 is the TFTP server (may be the same server as DHCP)

vi /etc/dhcp/dhcpd.conf
ddns-update-style none;

option domain-name "my.domain";
option routers 192.168.56.1;
option domain-name-servers 192.168.56.2, 192.168.56.3;

default-lease-time 600;
max-lease-time 7200;

log-facility local7;

subnet 192.168.56.0 netmask 255.255.255.0 {

   deny unknown-clients;
   next-server 192.168.56.10;

   host hcn2 {
      hardware ethernet 00:19:99:e0:87:30;
      fixed-address 192.168.56.20;
      if exists user-class and option user-class = "iPXE" {
         filename = "menu.ipxe";
      } else {
         filename = "undionly.kpxe";
      }
   }

}

Configuring iPXE

vi /var/lib/tftpboot/menu.ipxe
#!ipxe

######## MAIN MENU ###################
:start
menu Welcome to iPXE's Boot Menu
item
item --gap -- ------------------------- Operating systems ---------------
item smartos    Boot SmartOS (platform-20121228T011955Z)
item --gap -- ------------------------------ Utilities ------------------
item shell      Enter iPXE shell
item reboot     Reboot
item
item exit       Exit (boot local disk)
choose --default smartos --timeout 30000 target && goto ${target}

########## UTILITY ITEMS ####################
:shell
echo Type exit to get the back to the menu
shell
set menu-timeout 0
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

########## MENU ITEMS #######################
:smartos
set base-url ${boot-url}/images/smartos/20130111T010112Z/platform/i86pc
kernel ${base-url}/kernel/amd64/unix -v -B console=text,smartos=true
module ${base-url}/amd64/boot_archive
boot || goto failed
goto start

Preparing the SmartOS image

From the SmartOS wiki:
There are 2 files of importance, the kernel ("unix") and the boot archive ("boot_archive"). The paths to these files are significant and should not be omitted. They should be:
  • (prefix)/platform/i86pc/kernel/amd64/unix
  • (prefix)/platform/i86pc/amd64/boot_archive
The prefix may be anything you wish (a common prefix would be "/tftpboot/smartos/20121004T212912Z/") but the path after the prefix must be in the form above. If you do not the OS will fail to boot with an error saying "krtld: error during initial load/link phase"; in this case the image make sure your path is in the proper form. The important point being, don't just untar the latest platform image into your TFTP directory and boot it, you'll have problems unless you change the typical "platform_20121004T212912Z/" to simply "platform/".

So:

cd /var/lib/tftpboot/
mkdir images
cd images/
mkdir smartos
cd smartos
curl https://download.joyent.com/pub/iso/platform-latest.tgz > /tmp/platform-latest.tgz
cat /tmp/platform-latest.tgz | tar xz
ls | grep platform- | sort | tail -n1
platform-20130111T010112Z
mv platform-20130111T010112Z 20130111T010112Z
cd 20130111T010112Z/
mkdir platform
mv i86pc/ platform/

Please note: change 20130111T010112Z with the current version

Configuring iptables

To allow DHCP

vi /etc/sysconfig/iptables-config
IPTABLES_MODULES="ip_conntrack_tftp"

vi /etc/sysconfig/iptables
-A INPUT -m udp -p udp --dport 67:68 --sport 67:68 -j ACCEPT
-A INPUT -m tcp -p tcp --dport 69 -j ACCEPT
-A INPUT -m udp -p udp --dport 69 -j ACCEPT
/sbin/service iptables restart 

Configuring xinetd

To enable TFTP

vi /etc/xinetd.d/tftp
...

        disable                 = no

...
 
/etc/init.d/xinetd restart
 
 
 

Link for today

Solaris command: prstat http://jianmingli.com/wp/?p=1967