Boot iPXE from harddisc (Network booting from GRUB using iPXE)

wget https://raw.github.com/panticz/preseed/master/ipxe/scripts/install_grub_ipxe.sh -O - | sudo bash -

#!/bin/bash

# download GRUB iPXE boot image
wget http://dl.panticz.de/ipxe/ipxe.lkrn -O /boot/grub/ipxe.lkrn

# create GRUB menu entry
cat <<EOF> /etc/grub.d/49_ipxe 
#!/bin/sh
exec tail -n +3 $0

menuentry "Network boot (iPXE)" {
  linux16 /boot/grub/ipxe.lkrn
}
EOF

# update GRUB config
update-grub

Links
http://packages.ubuntu.com/de/precise/grub-ipxe
http://ipxe.org/embed

Install LXC (Linux Containers) under Ubuntu

wget https://raw.github.com/panticz/installit/master/install.lxc.sh -O - | bash -

#!/bin/bash

# install lxc
apt-get install -y lxc

# disable auto configuration for eth0
sed -i 's|auto eth0|#auto eth0|g' /etc/network/interfaces
sed -i 's|iface eth0 inet dhcp|#iface eth0 inet dhcp|g' /etc/network/interfaces

# create network bridge
cat <<EOF>> /etc/network/interfaces
auto lxcbr0
iface lxcbr0 inet dhcp
  bridge_ports eth0
EOF

# disable auto configuration for network bridge by lxc
sed -i 's|USE_LXC_BRIDGE="true"|USE_LXC_BRIDGE="false"|g' /etc/default/lxc-net

OPTIONAL: enable apt-cache
echo 'Acquire::http::Proxy "http://apt-cacher:3142/";' >> /etc/apt/apt.conf
apt-get update

OPTIONAL: create volume for lxc containers
lvcreate --name lxc-data --size 128G vg0
mkfs.ext4 /dev/vg0/lxc-data
echo "/dev/vg0/lxc-data /var/lib/lxc/ ext4 defaults 0 0" >> /etc/fstab

create vm
# install debian wheezy
lxc-create -n vm1 -t debian

# install debian squeeze
lxc-create -n squeeze1 -t debian -- template-options -r squeeze

lxc-create -n vm3 -t ubuntu
# lxc-create -n foo -f lxc.conf

# OPTIONAL: enable apt-cache in VM
echo 'Acquire::http::Proxy "http://apt-cacher:3142/";' >> /var/lib/lxc/vm3/rootfs/etc/apt/apt.conf

configure autostart
echo "lxc.start.auto = 1" >> /var/lib/lxc/vm3/config

# vm config
/var/lib/lxc/vm1/config

# start vm
lxc-start -n vm1

# bypass apparmor (LTSP server test)
echo "lxc.aa_profile = unconfined" >> /var/lib/lxc/vm3/config

templates
/usr/share/lxc/templates/

# dep
# apt-get install -y bridge-utils debootstrap
# libvirt-bin

# configure fs
echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
mount -a

Links
https://www.stgraber.org/2013/12/21/lxc-1-0-your-second-container/
http://askubuntu.com/questions/256304/public-ip-address-for-lxc-container/311003#311003
http://wiki.gentoo.org/wiki/LXC
http://www.linuxcertif.com/man/5/lxc.conf/
https://www.docker.io/
http://wiki.debian.org/LXC
http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-lucid-containers/
http://blog.foaa.de/2010/05/lxc-on-debian-squeeze/
http://www.thomas-krenn.com/de/wiki/Perl_warning_Setting_locale_failed_unter_Debian
https://packages.debian.org/de/jessie/lxc - Debian jessie LXC package

Create CentOS 6 DomU

wget https://raw.github.com/panticz/xen/master/domains/centos.6.sh -O - | bash -

#!/bin/bash

#
# IP    : dhcp
# user  : root
# pass  : t00r
#

#
# TODO
# use separate partitions for root (/dev/vg0/centos6-disk) and swap (/dev/vg0/centos6-swap) instead of harddisk image
#

# create disk
lvcreate --name centos6-disk --size 8G vg0

# download installation kernel and initrd
[ -d /tmp/centos6 ] || mkdir /tmp/centos6
wget -q http://mirror.netcologne.de/centos/6/os/x86_64/images/pxeboot/initrd.img -O /tmp/centos6/initrd.img
wget -q http://mirror.netcologne.de/centos/6/os/x86_64/images/pxeboot/vmlinuz -O /tmp/centos6/vmlinuz

# create installation configuration
cat <<EOF> /tmp/centos6-inst
kernel      = '/tmp/centos6/vmlinuz'
ramdisk     = '/tmp/centos6/initrd.img'
memory      = '512'
disk        = [ 'phy:/dev/vg0/centos6-disk,xvda,w' ]
name        = 'centos6-inst'
dhcp        = 'dhcp'
vif         = [ 'mac=00:00:00:00:ce:ce' ]
on_poweroff = 'destroy'
on_reboot   = 'destroy'
on_crash    = 'destroy'
extra       = "text ip=dhcp ks=http://preseed.panticz.de/preseed/centos6-minimal.cfg"
EOF

# install
xm create -c /tmp/centos6-inst

# create CenOS 6 configuration
cat <<EOF> /etc/xen/centos6
bootloader  = "/usr/lib/xen-4.1/bin/pygrub"
memory      = '512'
disk        = [ 'phy:/dev/vg0/centos6-disk,xvda,w' ]
name        = 'centos6'
dhcp        = 'dhcp'
vif         = [ 'mac=00:00:00:00:ce:ce' ]
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
EOF

# OPTIONAL: add to autostart
ln -s /etc/xen/centos6 /etc/xen/auto/centos6

# start CenOS 6
xm create -c centos6

Links
http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-kickstart2-startinginstall.html

Create IPfire DomU (firewall)

Check for latest IPFire version
http://downloads.ipfire.org/

wget https://raw.github.com/panticz/xen/master/domains/ipfire.sh -O - | bash -

#!/bin/bash

#URL=http://downloads.ipfire.org/releases/ipfire-2.x/2.13-core73/ipfire-2.13.xen.i586-full-core73.tar.bz2

# get ipfire xen image
#wget ${URL} -P /tmp/

# extract
#tar xjf /tmp/ipfire-2.*.xen.i586-full-core*.tar.bz2 -C /tmp/

# new version
wget -q http://downloads.ipfire.org/releases/ipfire-2.x/2.13-core75/ipfire-2.13.xen.i586-downloader-core75.tar.bz2 -O - | tar -C /tmp -xjf -
bash /tmp/ipfire/xen-image-maker.sh

# fix kernel name and Xen 4.x console output 
mount /root/ipfire-boot.img /mnt/
sed -i 's|vmlinuz-3.2.48-ipfire-xen|vmlinuz-3.2.48-ipfire-pae|g' /mnt/grub/grub.conf
sed -i 's|xvc0|hvc0|g' /mnt/grub/grub.conf
umount /mnt

# fix Xen 4.x console output
mount /root/ipfire-root.img /mnt/
sed -i 's|xvc0|hvc0|g' /mnt/etc/inittab
sed -i 's|xvc0|hvc0|g' /mnt/etc/securetty
umount /mnt

# fix wrong nobody user id
mount /root/ipfire-var.img /mnt/
find /mnt/ipfire/ -user 65534 -exec chown 99:99 {} \;
umount /mnt/

# copy data to lv
mkdir -p /tmp/ipfire/mnt/

# copy boot filesystem
lvcreate --name fw-boot --size 256M vg0
mkfs.ext2 /dev/vg0/fw-boot
#mount /tmp/ipfire/ipfire-boot.img /tmp/ipfire/mnt/ -o loop
mount ipfire-boot.img /tmp/ipfire/mnt/
mount /dev/vg0/fw-boot /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# copy root filesystem
lvcreate --name fw-root --size 2G vg0
mkfs.ext4 /dev/vg0/fw-root
#mount /tmp/ipfire/ipfire-root.img /tmp/ipfire/mnt/ -o loop
mount ipfire-root.img /tmp/ipfire/mnt/
mount /dev/vg0/fw-root /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# copy var filesystem
lvcreate --name fw-var --size 2G vg0
mkfs.ext4 /dev/vg0/fw-var
#mount /tmp/ipfire/ipfire-var.img /tmp/ipfire/mnt/ -o loop
mount ipfire-var.img /tmp/ipfire/mnt/
mount /dev/vg0/fw-var /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# create swap
lvcreate --name fw-swap --size 1G vg0
mkswap /dev/vg0/fw-swap


# clean up
rm -r /tmp/ipfire*

# create xen config file
cat <<EOF> /etc/xen/fw
#bootloader = '/usr/lib/xen-default/bin/pygrub'
bootloader = '/usr/lib/xen-4.1/bin/pygrub'
memory = 512
name = "fw"
acpi = 1
apic = 1
vif = [ 'mac=00:17:4e:be:b1:ba' ]
disk = [
    'phy:/dev/vg0/fw-boot,xvda1,w',
    'phy:/dev/vg0/fw-swap,xvda2,w',
    'phy:/dev/vg0/fw-root,xvda3,w',
    'phy:/dev/vg0/fw-var,xvda4,w'
]
acpi=1
apic=1
pci = ['00:0c.0']
extra = 'iommu=soft'
EOF

# OPTIONAL: autostart
ln -s /etc/xen/fw /etc/xen/auto/01_fw

# TODO (automate)
rmmod e100
rmmod xen-pciback
modprobe xen-pciback 'hide=(00:0c.0)'
xm pci-list-assignable-devices

# start domU
xm create -c fw

# configure ipfire in terminal

# webinterface
https://YOUR_DOMU_IP:444

# Links
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_wheezy_xen_4.1?&#debian_wheezy_mit_xen_41_als_dom0
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_als_dom0_xen#xen_und_kernel_installieren
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_xen_4.x

Magento Cache

get all cache types
Mage::app()->getCacheInstance()->getTypes();

types
Mage::app()->getCacheInstance()->cleanType('config');
Mage::app()->getCacheInstance()->cleanType('layout');
Mage::app()->getCacheInstance()->cleanType('block_html');
Mage::app()->getCacheInstance()->cleanType('translate');
Mage::app()->getCacheInstance()->cleanType('collections');
Mage::app()->getCacheInstance()->cleanType('eav');
Mage::app()->getCacheInstance()->cleanType('config_api');

clear cache
Mage::app()->cleanCache();

Magento: Update free shipping

PHP script (/root/scripts/set_free_shipping.sh)

#!/usr/bin/php
<?php
if(count($_SERVER['argv']) > 1) {
    $value=$_SERVER['argv'][1];
    
    require '/var/www/app/Mage.php';
    Mage::app(0);

    $config = new Mage_Core_Model_Config();
    $config->saveConfig('carriers/flatrate/active', $value, 'default', 0);
    $config->saveConfig('carriers/matrixrate/active', !$value, 'default', 0);

    Mage::app()->getCacheInstance()->cleanType('config');
} else {
    echo "Usage: " . $_SERVER['argv'][0] . " 0|1\n";
}
?>

Cronjob (/etc/cron.d/newyear)
0 0 1 1 * root /root/scripts/set_free_shipping.sh 0

Magento: Update footer copyright year

PHP script (/root/scripts/update_copyright_year.php)

#!/usr/bin/php
<?php
require '/var/www/app/Mage.php';
Mage::app(0);
  
# update configuration
$config = new Mage_Core_Model_Config();
$config->saveConfig('design/footer/copyright', '&copy; ' . date("Y") . ' YOUR COMPANY INC.', 'default', 0);

# refresh cache
Mage::app()->getCacheInstance()->cleanType('config');
sleep(1);
Mage::app()->getCacheInstance()->cleanType('block_html');
?>

Cronjob (/etc/cron.d/newyear)
0 0 1 1 * root /root/scripts/update_copyright_year.php

Use in CMS block
{{config path='design/footer/copyright'}}

Dep: Update by SQL
update core_config_data
set value = CONCAT('© ', YEAR(CURDATE()), ' YOUR COMPANY INC.')
where path = 'design/footer/copyright';

Links
http://www.panticz.de/Magento-Cache

ZyXEL NSA320

enable telnet
login as admin
http://192.168.2.127/r38571,/adv,/cgi-bin/remote_help-cgi?type=backdoor
telnet 192.168.2.127
root
YOUR_PASS

USB TTL to NSA-320
http://dl.panticz.de/hardware/zyxel_nsa320/nsa320_usb_ttl.jpg

install ssh
wget ftp://ftp.zyxel-tech.de/2.new_mirror/NSA310/4.40/zypkg/web_prefix -O /i-data/d154583a/admin/zy-pkgs/web_prefix
# firmware / package / reload
# install ffp
/i-data/d154583a/admin/zy-pkgs/ffp/ffp.log

#
# flash new uboot
#
# http://forum.doozan.com/read.php?2,7806
# on tftp server

Syndicate content