Warning: session_start(): open(/tmp/sess_19d5820c4e8a9af86124916446b78376, O_RDWR) failed: No space left on device (28) in /var/www/html/inc/init.php on line 265

Warning: session_start(): Failed to read session data: files (path: ) in /var/www/html/inc/init.php on line 265

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/inc/init.php:265) in /var/www/html/inc/auth.php on line 432

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/inc/init.php:265) in /var/www/html/inc/actions.php on line 38
initramfs_send_sms [Ben's notes]

Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


Arch Linux - send SMS from initramfs

This is just a proof of concept. Might be useful to notify someone when a system has been booted and reached initramfs, and it is waiting for the decryption pass phrase.

Install packages

  • Install the required tools:
    pacman -S screen expect

Configure HSDPA module

Huawei MU609

  • The module might be configured for packet switched (PS) only. To be able to send SMS via AT commands, the module needs to be configured for CP_PS, CS or CS_ONLY, CS = circuit switched. If you also want to set up a dataconnection, configure CS_PS. If you don't include CS, you will receive the error: +CMS ERROR: 500 when sending an SMS.
    # screen /dev/ttyUSB0 115200

Configure initramfs

  • Edit the mkinitcpio configuration file: /etc/mkinitcpio.conf:
    # Load these modules before any boot hooks are run
    MODULES="ehci_hcd ohci_pci usbserial option ohci_hcd ehci_pci"
    # Include these binaries
    BINARIES="/usr/bin/expect /usr/bin/stty"
    # Include the script and TCL dependency
    FILES="/usr/lib/tcl8.6/init.tcl /usr/local/bin/init-sms.sh"
    # Add custom 'sms' hook
    HOOKS="base udev autodetect modconf block keyboard sms encrypt filesystems fsck"

Create custom hook

  • /usr/lib/initcpio/hooks/sms:
    run_hook() {
  • /usr/lib/initcpio/install/sms
    build() {

Create SMS script

  • This is just a simple quick expect script.
    # device
    set modem /dev/ttyUSB0
    # keep it open
    exec sh -c "sleep 3 < $modem" &
    # serial port parameters (probably not needed for USB)
    exec stty -F $modem 9600 raw -clocal -echo -istrip -hup
    # connect
    spawn -open [open $modem w+]
    send "at\r"
    expect "OK"
    # Unlock SIM if needed.
    send "at^cpin?\r"
    expect { 
             # ^CPIN: SIM PIN,3,10,3,10,3
             "*CPIN: SIM PIN*" {
               send_user "SIM is locked, trying PIN...\n"
               send "at^cpin=123456\r"
               expect { 
                 "OK" {
                 "+CME ERROR: incorrect password" {
                   send_user "Wrong PIN, please configure the right PIN.\n"
             # ^CPIN: READY,,10,3,10,3
             "*CPIN: READY*" {
               send_user "SIM is ready.\n"
    # Wait 5 seconds, device is connecting to network...
    sleep 5
    # set text mode
    send "at+cmgf=1\r"
    expect "OK"
    # set GSM encoding
    send "at+csmp=,,,0\r"
    expect "OK"
    # Configure SMS service center
    send {AT+CSCA="+31653131313"}
    send "\r"
    expect "OK"
    # Select TE character set
    send {at+cscs="GSM"}
    send "\r"
    expect "OK"
    # Send SMS to number...
    send {at+cmgs="0612345678"}
    send "\r"
    expect "> "
    # Text to send, end with \x1A = ctrl-z
    send "System has reached initramfs."
    send "\x1a"

Generate new initramfs

  • Generate new initramfs:
    mkinitcpio -p linux
  • Reboot and test!
initramfs_send_sms.txt · Last modified: 2021/10/09 15:14 by