newspaint

Documenting Problems That Were Difficult To Find The Answer To

Monthly Archives: November 2013

Moving Linux Boot Partition to USB Drive

I have a Xubuntu (Ubuntu) Precise 12.04.3 LTS (long term support) installation on two hard drives, each encrypted using cryptsetup (LUKS) and then mirrored using mdadm.

To date I’ve had a separate /boot partition on each magnetic spinning disk. However I wished to move that /boot partition to USB drive so I wouldn’t need to rely on booting from magnetic disk anymore.

These are the steps I took to copy the /boot partition from my existing partition (/dev/sda2) onto a new partition on a USB flash drive (/dev/sdc).

In this example I took a USB stick (8GB in size) and created a 512 megabyte boot partition formatted in ext4 (/dev/sdc1) and also created a FAT32/VFAT partition with the rest of the space on the USB drive.

Check USB Vendor/Model

$ cat /sys/block/sdc/device/vendor
SanDisk
$ cat /sys/block/sdc/device/model
Cruzer Facet

Partition USB Stick

$ fdisk /dev/sdc # (assume sdc is USB stick)

d (delete partition)

n (new partition)
  p (primary)
    1 (partition number 1)
      [enter] (first sector, default 2048)
      +512M (last sector)
a (toggle bootable flag)
  1 (parition number 1)
n (new partition)
  p (primary)
    2 (partition number 2)
      [enter] (first sector, default 1050624)
      [enter] (last sector, whole of disk)
t (change parition type)
  2 (partition number 2)
    c (W95 FAT32 LBA)
w (write partition table to disk)

Format Partitions

mkfs.ext4 -L "usb_boot" /dev/sdc1
mkfs.vfat -n "USB_FAT32" /dev/sdc2

Copy Existing Boot

mkdir /mnt/sdc1
mount /dev/sdc1 /mnt/sdc1 -t ext4
rsync -avP /boot/* /mnt/sdc1/

Install Grub

cat /boot/grub/device.map
grub-install --recheck --debug /dev/sdc

Reboot

shutdown -r now

See Also

How To Use dnsdynamic.com With OpenWRT

Update (2014-09-03): Barrier Breaker has LuCI module support for dynamic DNS. See this blog article for details.


So you have your custom router with OpenWRT on it and you have a dynamic hostname with dnsdynamic.com or dnsdynamic.org. How do you get your OpenWRT router to send IP updates whenever you connect on the WAN interface?

In my case the WAN interface uses the pppoe-wan device. You might be using eth1 or similar – so make the appropriate changes in the following scripts for your situation.

I do it this way; create a script in /root/dnsdynamic.sh:

#!/bin/sh

WANIF="pppoe-wan"
MYHOST="newspaint.dnsdynamic.com"
USERNAME="admin@newspaint.wordpress.com"
PASSWORD="secret!Password"

MYIP=`ifconfig ${WANIF} |grep -o -E 'inet addr:([0-9.]+)' |grep -o -E '([0-9.]+)'`
URL="https://www.dnsdynamic.org/api/?hostname=${MYHOST}&myip=${MYIP}"
/usr/bin/wget -O - --no-check-certificate --http-user "${USERNAME}" --http-password "${PASSWORD}" "$URL"

Don’t forget to make the script executable:

chmod 755 /root/dnsdynamic.sh

Next, get the package “wget” for your OpenWRT router (the default doesn’t have functions for password-protected web pages, so I go to the web interface on my router, select System -> Software, [update packages if I haven’t for a while], Filter: type wget, click “Find package”, then below on the “Available packages” tab select the wget package to install).

Finally you can test the script by running it on the command line (on your router as you’ve SSH’d in as root). You should see output similar to the following:

root@myOpenWRTRouter:~# /root/dnsdynamic.sh
--2013-11-10 17:12:09--  https://www.dnsdynamic.org/api/?hostname=newspaint.dnsdynamic.com&myip=41.42.43.44
Resolving www.dnsdynamic.org... 84.45.76.100
Connecting to www.dnsdynamic.org|84.45.76.100|:443... connected.
WARNING: cannot verify www.dnsdynamic.org's certificate, issued by `/C=US/O=GeoTrust, Inc./CN=RapidSSL CA':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 401 Authorization Required
Connecting to www.dnsdynamic.org|84.45.76.100|:443... connected.
WARNING: cannot verify www.dnsdynamic.org's certificate, issued by `/C=US/O=GeoTrust, Inc./CN=RapidSSL CA':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: 6 [text/html]
Saving to: `STDOUT'

 0% [                                       ] 0           --.-K/s              nochg
100%[======================================>] 6           --.-K/s   in 0s

2013-11-10 17:12:10 (12.6 KB/s) - written to stdout [6/6]

Typical responses from dnsdynamic are nochg and good <ip_address>.

Finally – how to make it update every time you connect to the WAN?

Create a script in /etc/hotplug.d/iface named 30-dnsdynamic:

#!/bin/sh
# This script is executed as part of the hotplug event with
# HOTPLUG_TYPE=iface, triggered by various scripts when an interface
# is configured (ACTION=ifup) or deconfigured (ACTION=ifdown).  The
# interface is available as INTERFACE, the real device as DEVICE.

[ "$DEVICE" != "pppoe-wan" ] && exit 0

. /lib/functions.sh
. /lib/firewall/core.sh

fw_init
fw_is_loaded || exit 0

case "$ACTION" in
        ifup)
                /root/dnsdynamic.sh >/tmp/dnsdynamic.log 2>&1
        ;;
esac

This script triggers whenever an interface is brought up or down – but will exit if the device is not pppoe-wan and will only take action if the interface is being brought up (as this is when your interface will be assigned a dynamic IP address and so should make the IP address notification).

Unlocking a HG612 Revision 3B

I bought, second-hand, a HG612 revision 3B openreach VDSL modem on eBay.

Referring to this blog post entitled “Huawei HG612 Hacking” and the linked PDF document the following was done (but no credit for this should be taken on this blog, it is partly reproduced purely in case the originals should disappear for some reason, there are many more details, acknowledgements, and useful diagnosis information in that document):

  1. obtain a copy of the unlocked firmware from the above link (listed on the right hand side of the blog page)
  2. power off the modem
  3. connect a PC via Ethernet to the LAN2 socket on the modem
  4. pre-configure the PC’s Ethernet interface to a static IP address of 192.168.1.100/24
  5. press and hold the RESET button on the modem while powering up the modem
    • release the RESET button after 5 seconds after powering up
  6. use a web browser on the PC to visit modem’s web server http://192.168.1.1/ (note that 192.168.1.1 is not pingable and the Ethernet port lights do not light up on the modem in this state)
  7. on the “Update Software” page displayed supply the name of the unlocked firmware on your PC by clicking the Browse… button on the webpage
    • click on the “Update Software” button on the webpage
    • note that the modem lights do not flicker, nor do the LAN port lights activate
  8. wait for the firmware to be completely loaded (do not power off)
    • modem will reboot automatically after programming
    • the modem LAN2 port lights should be activated
  9. visit page http://192.168.1.1/ on the modem again
  10. you should see a login page branded “Huawei EchoLife Home Gateway”
  11. login with username admin, password admin
  12. you can also telnet to 192.168.1.1:25 with the same username and password as above, or ssh admin@192.168.1.1
    • full line statistics can be obtained from the xdslcmd tool (type sh first, then xdslcmd info --stats)

A “long reset” can restore a default configuration:

  1. reboot the modem, give it some time to settle
  2. check the modem has a working xDSL line connection
  3. hold the reset button on the hg612 for 10+ seconds then release (“long reset”)
  4. give the modem time to reboot again

Output of Stats

I got the following stats output:

Welcome Visiting Huawei  Home Gateway
Copyright by Huawei Technologies Co., Ltd.
Login:admin
Password:admin

ATP>sh

BusyBox v1.9.1 (2010-10-15 17:59:06 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

# xdslcmd info --stats
xdslcmd: ADSL driver and PHY status
Status: Showtime
Retrain Reason: 0
Max:    Upstream rate = 30992 Kbps, Downstream rate = 90516 Kbps
Path:   0, Upstream rate = 20000 Kbps, Downstream rate = 79999 Kbps

Link Power State:       L0
Mode:                   VDSL2 Annex B
VDSL2 Profile:          Profile 17a
TPS-TC:                 PTM Mode
Trellis:                U:ON /D:ON
Line Status:            No Defect
Training Status:        Showtime
                Down            Up
SNR (dB):        8.9             15.3
Attn(dB):        0.0             0.0
Pwr(dBm):        13.0           -3.0
                        VDSL2 framing
                        Path 0
B:              239             237
M:              1               1
T:              23              45
R:              0               16
S:              0.0955          0.3782
L:              20107           5373
D:              1               1
I:              240             127
N:              240             254
                        Counters
                        Path 0
OHF:            3268582         1270641
OHFErr:         2               3
RS:             0               1330714
RSCorr:         0               7
RSUnCorr:       0               0

                        Path 0
HEC:            1               0
OCD:            0               0
LCD:            0               0
Total Cells:    831152799               0
Data Cells:     222704          0
Drop Cells:     0
Bit Errors:     0               0

ES:             2               3
SES:            0               0
UAS:            18              18
AS:             5407

                        Path 0
INP:            0.00            0.00
PER:            1.64            4.25
delay:          0.00            0.00
OR:             116.56          60.17

Bitswap:        15              8

Total time = 1 hours 30 min 25 sec
FEC:            0               0
CRC:            2               0
ES:             2               3
SES:            0               0
UAS:            18              18
LOS:            0               0
LOF:            0               0
Latest 15 minutes time = 25 sec
FEC:            0               0
CRC:            0               0
ES:             0               0
SES:            0               0
UAS:            0               0
LOS:            0               0
LOF:            0               0
Previous 15 minutes time = 15 min 0 sec
FEC:            0               0
CRC:            0               0
ES:             0               0
SES:            0               0
UAS:            0               0
LOS:            0               0
LOF:            0               0
Latest 1 day time = 1 hours 30 min 25 sec
FEC:            0               0
CRC:            2               0
ES:             2               3
SES:            0               0
UAS:            18              18
LOS:            0               0
LOF:            0               0
Previous 1 day time = 0 sec
FEC:            0               0
CRC:            0               0
ES:             0               0
SES:            0               0
UAS:            0               0
LOS:            0               0
LOF:            0               0
Since Link time = 1 hours 30 min 5 sec
FEC:            0               7
CRC:            2               3
ES:             2               3
SES:            0               0
UAS:            0               0
LOS:            0               0
LOF:            0               0

# exit
ATP>exit
exit from configuration console.