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
$ 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/
grub-install --recheck --debug /dev/sdc

Note that if your file is somewhere else you may want to do the following instead (for example if your /boot was on /dev/sdc1 and that had been mounted at /media/myuser/boot_usb):

grub-install --root-directory /media/myuser/boot_usb /dev/sdc


shutdown -r now

What happens, though, if you’re confronted with a text Grub menu (because it hasn’t found your boot USB drive)? It will display something like:

                        GNU GRUB

    Minimal BASH-like line editing is supported. For the first word,
    TAB lists possible command completions. Anywhere else TAB lists
    possible device or file completions. ESC at any time exits.


In this case you’ll need to find the partition containing your grub and Linux/initramfs files. To do that you can try the following:

grub> ls
(hd0,0) (hd0,1) (hd1,0)
grub> ls (hd0,0)/
grub> ls (hd0,1)/
grub> ls (hd1,0)/

… until it displays files like vmlinuz etc. Once you figure out what device has your files you can then prepare to boot by loading the Linux image (kernel) and initramfs file.


grub> set root=(hd0,0)
grub> linux /vmlinuz-4.4.0-166-generic root=ZFS=rpool/ROOT ro boot=zfs nosplash
grub> initrd /initrd.img-4.4.0-166-generic
grub> boot

Now, if, after doing this, the Linux boot sequence comes up with the following:

Welcome to emergency mode! After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" or ^D to
try again to boot into default mode.
Give root password for maintenance
(or press Control-D to continue):

… then enter the root password. And enter “journalctl -xb” as instructed. If you see something about a dev-disk-by-uuid not timing out then your boot USB may not have the same UUID as it did previously (especially if you rebuilt the partition table). In this case enter:

# ls -l /dev/disk/by-uuid

to find out the ID of your boot disk. Then update/edit /etc/fstab with the correct UUID, and try rebooting again.

See Also

How To Use 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 or 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/



MYIP=`ifconfig ${WANIF} |grep -o -E 'inet addr:([0-9.]+)' |grep -o -E '([0-9.]+)'`
/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/

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/
--2013-11-10 17:12:09--
Connecting to||:443... connected.
WARNING: cannot verify'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||:443... connected.
WARNING: cannot verify'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:

# 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/
. /lib/firewall/

fw_is_loaded || exit 0

case "$ACTION" in
                /root/ >/tmp/dnsdynamic.log 2>&1

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
  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 (note that 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 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 with the same username and password as above, or ssh admin@
    • 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.


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
                        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
exit from configuration console.