Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After reading this answer, I thought it would be funny to roll my own init on Python, so I wrote this in /init-python.

import os
import subprocess
# Make / writable!
subprocess.call(['/bin/mount', '-o', 'rw,remount', '/'])
# Became IPython (Now we're at it, get a good shell!)
os.execv('/usr/bin/ipython3', ['init'])

Then added init=/init-python to the linux line in GRUB config. It works.

So I was wondering now... how to power off or reboot my system with my homemade init?

share|improve this question
up vote 4 down vote accepted

It can be done with reboot function (man 2 reboot).

import ctypes
libc = ctypes.cdll['libc.so.6']
RB_POWER_OFF = 0x4321fedc
RB_AUTOBOOT  = 0x01234567

def shutdown():

def reboot():
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.