Uwe Hermann: Testing stuff with QEMU - Part 1: SELinux support in Debian unstable [Update]
Here's a quick HOWTO to get you started with the QEMU emulator, the Debian installer (etch beta 3), and SELinux. If you execute the following steps you'll be left with an SELinux-enabled Debian unstable QEMU image, but not with a complete working and perfectly configured SELinux system. A more detailed article about SELinux will probably follow...
Basic Debian unstable install in QEMU:
-
Install QEMU:
apt-get install qemu -
Download the latest Debian etch installer ISO image (etch beta 3, currently):
wget http://cdimage.debian.org/cdimage/etch_di_beta3/i386/iso-cd/debian-testing-i386-binary-1.iso -
Create a QEMU image which will hold the Debian installation:
qemu-img create -f qcow /path/to/debian.img 5000M -
Boot directly from the ISO image and install Debian into the QEMU image (I won't go into the details of the installation itself; Wolfang Lonien has nice HOWTOs for that: part 1, part 2, video):
qemu -hda /path/to/debian.img -boot d -cdrom debian-testing-i386-binary-1.iso -
After the installation is done, configure the system, tweak
/etc/apt/sources.listif needed, and then dist-upgrade to the latest stuff:
apt-get update && apt-get dist-upgrade -
That's about it for the basic Debian install, you can now shutdown the OS and QEMU (type "
halt" in the emulated Debian, wait for the shutdown to complete, press CTRL+ALT+2 to switch to the QEMU console, and type "quit").
-
Create an overlay image based on the previously installed Debian image:
qemu-img create -b /path/to/debian.img -f qcow /path/to/debian_selinux_overlay.img -
Now boot into the new overlay image:
qemu -hda /path/to/debian_selinux_overlay.img
-
SELinux wants to label all the files on your system (all inodes actually), so your filesystem(s) need the so-called extended attributes (xattr) and "security labels" (both are kernel options) which most modern file systems now support. For ext3 (for example) you need these config options:
Luckily the Debian kernels are xattr-enabled by default so we don't have to do anything at all here.
CONFIG_EXT3_FS=y
CONFIG_EXT3_FS_XATTR=y
CONFIG_EXT3_FS_SECURITY=y
-
Install the basic SELinux packages and the source package of the SELinux reference policy:
apt-get install checkpolicy policycoreutils selinux-policy-refpolicy-src -
I noticed a bug in the current Debian packages (the
setfilesutility is in the wrong place, see #384850), but there's a simple workaround:
ln -s /sbin/setfiles /usr/sbin/setfiles -
Now we can (re-)label the file system:
cd /etc/selinux/refpolicy/src/policy
make relabel
This will build the reference policy from source and relabel your file system (this will take a while).
There might be some warnings (and maybe you'll notice further bugs), but they seem not to be critical. -
We can now (almost) enable SELinux, but before we can reboot we need to work around another bug (#384852), otherwise SELinux will not be enabled when we reboot:
ln -s /etc/selinux/refpolicy/src /etc/selinux/targeted -
Now reboot the emulated Debian system, and at the GRUB console add the kernel option
selinux=1to enable SELinux in the kernel (press "e" to edit the boot options). -
You'll get tons of SELinux log messages while the system boots, that's normal at this point, don't worry.
Then you can type "sestatus", which should print some information on the running SELinux system. If it says "SELinux status: disabled" something went wrong.
user_xattr support for SELinux, only xattr support (for security.selinux xattrs) for the filesystem you use, which is available per default in Debian kernels (thanks Russell Coker).
The two states shown in red (“waiting” and “running”) are rest states, normally we expect the job to remain in these states until an event comes in, at which point we need to take actual to get the job into the next state.
The other states are temporary states; these allow a job to run shell script to prepare for the job itself to be run (“starting”) and clean up afterwards (“stopping”). For services that should be respawned if they terminate before an event that stops them is received, they may run shell script before the process is started again (“respawning”).
Jobs leave a state because the process associated with them terminates (or gets killed) and move to the next appropriate state, following the green arrow if the job is to be started or the red arrow if it is to be stopped. When a script returns a non-zero exit status, or is killed, the job will always be stoped. When the main process terminates and the job should not be respawned, the job will also always be stopped.
As already covered, events generated by the init daemon or received from other processes cause jobs to be started or stopped; also manual requests to start or stop a job may be received.
The communication between the init daemon and other processes is bi-directional, so the status of jobs may be queries and even changes of state to all jobs be received.
How does it differ from launchd?


