Editing Ubuntu Gutsy template creation
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 2: | Line 2: | ||
[[Category: Templates]] | [[Category: Templates]] | ||
[[Category: Ubuntu]] | [[Category: Ubuntu]] | ||
+ | |||
This article summarizes the experience of creating Ubunty Gutsy Gibbon (a.k.a. 7.10) template for OpenVZ. | This article summarizes the experience of creating Ubunty Gutsy Gibbon (a.k.a. 7.10) template for OpenVZ. | ||
Line 9: | Line 10: | ||
=== debootstrap === | === debootstrap === | ||
− | You have to have a | + | You have to have a debootstrap working for Gutsy, i.e. you should have |
− | * | + | * debootstrap and its dependencies |
− | * | + | * /usr/lib/debootstrap/scripts/gutsy file |
− | The simplest way to have it all is to work on an | + | The simplest way to have it all is to work on an Ubunty Gutsy system (be it on a real machine or inside a VE). If you don't have debootstrap installed, this is the command to install it: |
# apt-get install debootstrap | # apt-get install debootstrap | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== vzctl === | === vzctl === | ||
− | You need vzctl-3.0. | + | You need vzctl-3.0.19 or later to work with Ubuntu Gutsy Gibbon. If vzctl-3.0.18 or earlier is used, you will not be able to run your VE. See {{bug|662}} for details. |
− | |||
− | |||
== Creating template == | == Creating template == | ||
Line 39: | Line 26: | ||
=== Running debootstrap === | === Running debootstrap === | ||
− | Create | + | Create some directory: |
− | + | # mkdir gutsy-chroot | |
Run debootstrap to install a minimal Ubunty Gutsy system into that directory: | Run debootstrap to install a minimal Ubunty Gutsy system into that directory: | ||
− | + | # debootstrap --arch ''ARCH'' gutsy gutsy-chroot | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Substitute your architecture instead of ''ARCH''. For example, for AMD64/x86_64, use <code>amd64</code> or for ia64, use <code>ia64</code>. For i386 you do not have to give this option. | |
− | + | === Preparing/starting a VE === | |
− | + | Now then you have an installation created by debootstrap, you can run it as a VE. In the example below VE ID of 777 is used; of course you can use any other non-allocated ID. | |
− | ==== Moving installation to | + | ==== Moving installation to VE private area ==== |
− | You should move the contents of gutsy-chroot directory into new | + | You should move the contents of gutsy-chroot directory into new VE private area, like this: |
− | # mv gutsy-chroot /vz/private/777 | + | # mkdir /vz/private/777 |
+ | # mv gutsy-chroot/ /vz/private/777 | ||
− | ==== Setting | + | ==== Setting VE config ==== |
− | An initial config for the [[ | + | An initial config for the [[VE]] is needed: |
# vzctl set 777 --applyconfig vps.basic --save | # vzctl set 777 --applyconfig vps.basic --save | ||
− | ==== Setting | + | ==== Setting VE OSTEMPLATE ==== |
− | Also, we need < | + | Also, we need <tt>OSTEMPLATE</tt> to be set in VE configuration file, for the [[vzctl]] to work properly. |
# echo "OSTEMPLATE=ubuntu-7.10" >> /etc/vz/conf/777.conf | # echo "OSTEMPLATE=ubuntu-7.10" >> /etc/vz/conf/777.conf | ||
− | ==== Setting | + | ==== Setting VE IP address ==== |
− | For the [[ | + | For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it: |
# vzctl set 777 --ipadd x.x.x.x --save | # vzctl set 777 --ipadd x.x.x.x --save | ||
− | {{Note|if you use private IP for the | + | {{Note|if you use private IP for the VE, you have to set up NAT as described in [[Using NAT for VE with private IPs]].}} |
− | ==== Setting DNS server for | + | ==== Setting DNS server for VE ==== |
− | For the [[ | + | For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it: |
# vzctl set 777 --nameserver x.x.x.x --save | # vzctl set 777 --nameserver x.x.x.x --save | ||
Instead of <code>x.x.x.x</code>, specify the same IP that you have in your <code>/etc/resolv.conf</code>. | Instead of <code>x.x.x.x</code>, specify the same IP that you have in your <code>/etc/resolv.conf</code>. | ||
− | ==== Starting | + | ==== Starting VE ==== |
− | Now start the | + | Now start the VE: |
# vzctl start 777 | # vzctl start 777 | ||
=== Modify the installation === | === Modify the installation === | ||
− | You have to do some things in order to modify the installation to better suit the environment it will be run in (i.e. a | + | You have to do some things in order to modify the installation to better suit the environment it will be run in (i.e. a VE). |
− | First, enter a | + | First, enter a VE: |
# vzctl enter 777 | # vzctl enter 777 | ||
− | {{Warning|Do not run the commands below on the hardware node, they are only to be run within the | + | {{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}} |
+ | |||
==== Remove unneeded packages ==== | ==== Remove unneeded packages ==== | ||
− | Some packages does not make sense in a | + | Some packages does not make sense in a VE. Remove those: |
− | [ | + | [VE]# dpkg -P ubuntu-minimal wpasupplicant wireless-tools \ |
udev pcmciautils initramfs-tools volumeid console-setup \ | udev pcmciautils initramfs-tools volumeid console-setup \ | ||
xkb-data usbutils mii-diag alsa-base alsa-utils ethtool \ | xkb-data usbutils mii-diag alsa-base alsa-utils ethtool \ | ||
module-init-tools linux-sound-base console-tools \ | module-init-tools linux-sound-base console-tools \ | ||
console-terminus busybox-initramfs libvolume-id0 \ | console-terminus busybox-initramfs libvolume-id0 \ | ||
− | ntpdate | + | ntpdate |
− | |||
− | |||
− | |||
− | |||
− | |||
Clean up after udev: | Clean up after udev: | ||
− | [ | + | [VE]# rm -fr /lib/udev |
==== Disable getty ==== | ==== Disable getty ==== | ||
− | On a usual Linux system, | + | On a usual Linux system, getty is running on a virtual terminals, which a VE does not have. |
− | |||
− | |||
− | + | There are two ways to disable it: | |
− | |||
− | |||
First way: | First way: | ||
− | [ | + | [VE]# rm /etc/event.d/tty* |
− | |||
Second way: | Second way: | ||
− | [ | + | [VE]# dpkg -P system-services |
− | Second way can be dangerous for future versions of | + | Second way can be dangerous for future versions of system-services, but it's OK for now since the only service they carry is running gettys. |
==== Set sane permissions for /root directory ==== | ==== Set sane permissions for /root directory ==== | ||
− | [ | + | [VE]# chmod 700 /root |
==== Disable root login ==== | ==== Disable root login ==== | ||
− | [ | + | [VE]# usermod -L root |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== Get new security updates ==== | ==== Get new security updates ==== | ||
− | [ | + | [VE]# apt-get update && apt-get upgrade |
<small>This didn't show anything for me, but might do something in the future.</small> | <small>This didn't show anything for me, but might do something in the future.</small> | ||
Line 156: | Line 124: | ||
==== Install some more packages ==== | ==== Install some more packages ==== | ||
− | [ | + | [VE]# apt-get install ssh quota |
Feel free to add packages which you want to have in a default template to this command. | Feel free to add packages which you want to have in a default template to this command. | ||
==== Fix SSH host keys ==== | ==== Fix SSH host keys ==== | ||
− | This is only useful if you installed SSH above. Each individual [[ | + | This is only useful if you installed SSH above. Each individual [[VE]] should have its own pair of SSH host keys. The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot. |
<!-- please DO NOT remove <pre>...</pre> pair of tags below, | <!-- please DO NOT remove <pre>...</pre> pair of tags below, | ||
Line 175: | Line 143: | ||
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys | chmod a+x /etc/rc2.d/S15ssh_gen_host_keys | ||
</pre> | </pre> | ||
+ | |||
==== Disable <code>sync()</code> for syslog ==== | ==== Disable <code>sync()</code> for syslog ==== | ||
Line 182: | Line 151: | ||
<!-- DO NOT remove <pre> here, it's useful --> | <!-- DO NOT remove <pre> here, it's useful --> | ||
− | <pre>[ | + | <pre>[VE]# sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/syslog.conf</pre> |
==== Fix <code>/etc/mtab</code> ==== | ==== Fix <code>/etc/mtab</code> ==== | ||
Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, so <code>df</code> and friends will work: | Link <code>/etc/mtab</code> to <code>/proc/mounts</code>, so <code>df</code> and friends will work: | ||
− | [ | + | [VE]# rm -f /etc/mtab |
− | [ | + | [VE]# ln -s /proc/mounts /etc/mtab |
After that, it would make sense to disable <code>mtab.sh</code> script which messes with <code>/etc/mtab</code>: | After that, it would make sense to disable <code>mtab.sh</code> script which messes with <code>/etc/mtab</code>: | ||
− | [ | + | [VE]# update-rc.d -f mtab.sh remove |
+ | |||
+ | ==== Get rid of tmpfs mounts ==== | ||
+ | |||
+ | [VE]# sed -ie '/tmpfs/d' /etc/init.d/mountkernfs.sh | ||
==== Disable some services ==== | ==== Disable some services ==== | ||
Line 196: | Line 169: | ||
In most of the cases you don't want klogd to run -- the only exception is if you configure iptables to log some events -- so you can disable it: | In most of the cases you don't want klogd to run -- the only exception is if you configure iptables to log some events -- so you can disable it: | ||
− | [ | + | [VE]# update-rc.d -f klogd remove |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== Clean packages ==== | ==== Clean packages ==== | ||
After installing packages, you'll have some junk packages laying around in your cache. Since you don't want your template to have those, this command will wipe them out. | After installing packages, you'll have some junk packages laying around in your cache. Since you don't want your template to have those, this command will wipe them out. | ||
− | [ | + | [VE]# apt-get clean |
− | |||
− | + | Set propper hostname and file /etc/hosts | |
− | [ | + | [VE]# echo "localhost" > /etc/hostname |
− | [ | + | [VE]# echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts |
− | |||
− | + | Remove DNS entries: | |
+ | [VE]# > /etc/resolv.conf | ||
− | + | Maybe clean up logfile, root history etc. | |
− | |||
− | |||
Now everything is done. Exit from the template and go back to the hardware node. | Now everything is done. Exit from the template and go back to the hardware node. | ||
+ | [VE]# exit | ||
− | + | <big><big>To be continued</big></big> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |