Friday, May 30, 2014

Update Grub 2 options

As a follow up to my previous post Ubuntu Server 14.04 fun I was asked how to update the Grub2 file. It's really very easy. Use a text editor to open /etc/default/grub like so:
sudo nano /etc/default/grub
Then find the line that says GRUB_CMDLINE_LINUX_DEFAULT="" and add nomodeset inside the quotation marks.
If you do use nano then you can press Ctrl-o and Ctrl-x at this point to write and exit.
Then run this command:
sudo update-grub
and that should do it.

Thursday, May 29, 2014

Make Raspberry Pi (and other SBCs) report it's IP address when it starts up.

You can also track power on events and other information in this way. First, create a script, let's call it reportip.sh:

#!/bin/bash
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  result = ""
  printf -v result "192.168.1.2/rpi.php?id=pi-R&ip=%s" "$_IP"
  echo "$result"
  curl -u username:password $result
fi


What's going on here?
First it gets the IP address and assigns it to a variable $_IP.
It displays a message so if you do happen to have a display plugged in then you'll see what the IP address is without logging in.
It builds a $result variable that is a url. In this case I have a fictional web server at 192.168.1.2, a PHP script called rpi.php runs on it that can take some values and log them to a database. This is a very simple script that is setup to log to a SQLite database but could easily be rewritten to point to MySQL or your favorite database.
It then uses curl to call upon that url in order to set things in motion. I'm using the -u switch to specify a simple digest username and password.

Then you can put this into your /etc/rc.local
This is wildly insecure if you leave it in a user's home directory since whatever is in the script will be executed with root privileges on startup so don't do that in your day job. You can run it with sudo -u username /home/user/reportip.sh to run it with lesser privileges or put it elsewhere.
Once this is setup then every time your pi starts, it will get an IP and then hit your server to report what IP it got. Then you can go to that page and see what it is.

I actually need to rewrite that PHP script, it was lost in a hard drive crash earlier this year. Look for it soon, I will put it up on my GitHub account.

Thursday, April 24, 2014

Ubuntu server 14.04 fun

Recently lost a system drive in the AMD E350 based computer I use for various file server, database, test web server and other roles in my home network. The new drive came in the mail today so I decided to try to install the new Ubuntu server to it. I used the built-in LVM support that exists in the CLI installer now. Last time I had to do that by hand so it was a nice improvement.

Long story short, on boot up I was encountering an apparent hang or freeze once it was trying to initialize the swap space.
[    3.490158] firewire_core 0000:06:02.0: created device fw0: GUID 001e8c000042dc3f, S400
[    3.616414] random: lvm urandom read with 30 bits of entropy available
[    3.671945] bio: create slab <bio-1> at 1
[    3.843667] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null)
[    4.026158] Switched to clocksource tsc
[    4.460003] init: plymouth-upstart-bridge main process (183) terminated with status 1
[    4.462054] init: plymouth-upstart-bridge main process ended, respawning
[    4.470931] init: plymouth-upstart-bridge main process (194) terminated with status 1
[    4.472846] init: plymouth-upstart-bridge main process ended, respawning
[    4.482749] init: plymouth-upstart-bridge main process (196) terminated with status 1
[    4.484555] init: plymouth-upstart-bridge main process ended, respawning
[    4.493858] init: plymouth-upstart-bridge main process (198) terminated with status 1
[    4.495605] init: plymouth-upstart-bridge main process ended, respawning
[    4.503723] init: plymouth-upstart-bridge main process (200) terminated with status 1
[    4.505317] init: plymouth-upstart-bridge main process ended, respawning
[    4.516120] init: plymouth-upstart-bridge main process (201) terminated with status 1
[    4.517821] init: plymouth-upstart-bridge main process ended, respawning
[    4.552321] init: plymouth-upstart-bridge main process (203) terminated with status 1
[    4.553990] init: plymouth-upstart-bridge main process ended, respawning
[    5.143395] random: nonblocking pool is initialized
[    5.480640] Adding 7970812k swap on /dev/mapper/ubuntu--vg-swap_1.  Priority:-1 extents:1 across:7970812k FS

The most frustrating part of this is that the only reference I found to someone having the same problem online wasn't any help at all.

Then I discovered that in the recovery console I was able to see an IP and it was on my network just fine. So on the next reboot I tried connecting to it over SSH after it "froze" on me. I was able to connect and login and even use it as if nothing was wrong! The dmesg log shows the boot process continuing on from the above point as well.

Some research later and I found that if you add nomodeset to the kernel settings before it boots then it will continue on to the login prompt normally. I'm sure, now, that when it appears to freeze that's when it is actually switching to a video mode that is not working correctly on my hardware. This is probably not a very common problem which is why I don't see many other people talking about it online.

tl;dr? If you're having problems with Ubuntu appearing to freeze during the boot process.. try booting with nomodeset in your kernel options!

There's a nice description of what nomodeset does here: link