If I were a giant…

What would you do if you were a giant?

Romantic Promposal Sign (even msg)

If I were a big giant, I would pick stars from the sky for you.

But I am only a young man, can I pick you up for prom instead?

Asking Her Out for a Date

After talking about the fantastic night sky/big tree scene in BFG movie, ask,

You know, if I were a giant, I think I want to reach up and pick stars from the sky.

But I’m not, so instead of stars, can I pick you up for dinner/coffee?

A Note for Mom on Mother’s Day

I want to be a giant, so I can pick stars for you on Mother’s day.  But I’m not, so I picked some flowers instead.  Happy mother’s day!

Advertisements

Get ISO From CD For Checksum Verification

WRONG WAY:  This will generate an ISO file but its checksum will be different from the source ISO image:

dd if=/dev/sr0 of=/tmp/disk_image.iso

RIGHT WAY:  To generate an image identical to the source, first find CD info

$ isoinfo -d -I /dev/sr0 | egrep -i 'block size|volume size'
Logical block size is: 2048
Volume size is: 275040
$

Next, use the logical block size for the ‘bs’ operand and volume size for the ‘count’ operand:

$ dd if=/dev/sr0 of=/tmp/disk_image.iso bs=2048 count=275040

This will create a ISO file identical to the source, thus having the same checksum.

Or just skip the ISO file and pipe the image to md5sum, for example.

$ dd if=/dev/sr0 bs=2048 count=275040 | md5sum

Recipes from preschool

YOGURT POPS

Mix together:

  • 2 cups vanilla yogurt
  • 1 1/2 cups orange juice
  • 1 tsp vanilla extract

Pour into containers (paper cups, popsicle forms) and freeze until hard


OATMEAL MUFFINS

Mix together:

  • 1 cup flour
  • 3 tsp baking powder
  • 1/2 tsp salt
  • 1/4 cup sugar

add:

  • 1 cup oats
  • 1 egg slightly beaten
  • 1 cup milk
  • 3 tbs oil

Bake at 425 degrees for 15 min.  Makes 12


COOL WATERMELON SLUSHES

The watermelons in Thailand don’t look like the watermelons in North America. Unlike North American watermelons, which are oval and weigh 15 to 45 pounds (7 to 20 kilos), Thai watermelons are round like balls and weigh only 5 to 15 pounds (2 to 7 kilos). The insides look the same, though, and they taste the same, too. Here’s a watermelon recipe from Thailand that tastes great no matter where the watermelons are from.

HERE’S WHAT YOU NEED:

  • 6 ice cubes
  • 2 cups (500 ml) seedless pieces of watermelon
  • 1 tablespoon (15 ml) sugar or honey

HERE’S WHAT YOU DO:

  1. Put the ice cubes in a blender or food processor. Ask a grown-up to mix the ice cubes until they are crushed.
  2. Add the watermelon pieces and blend until the shake is slushy, about 1 minute.
  3. Add the sugar or honey and blend for 10 seconds. Pour the slush into tall glasses.

Makes 4 cool-off slushes.


RAMEN NOODLE SOUP

Looking for a good, but cheap meal? In Japan, you can stop by a ramenaya, a Japanese noodle shop, and get a bowl of soup for 260 yen (about $3). For a fast Japanese meal, make yourself a bowl of noodle soup. Be sure it looks good – food presentation is a creative art in Japan.

HERE’S WHAT YOU NEED:

  • 1 package ramen noodle soup

ADD-INS (USE UP TO 4):

  • 1 carrot, cut into very think sticks, about 2 inches (5 cm) long
  • 1 scallion, chopped
  • Daikon radish, cut into very thin sticks, about 2 inches (5 cm) long
  • 1 mushroom, sliced
  • 3 pea pods
  • 1 Chinese cabbage leaf, shredded
  • 1 lettuce leaf, shredded

HERE’S WHAT YOU DO:

  • Ask a grown-up to help you make the soup according to the package directions.
  • Place up to 4 of the added-ins into a large soup bowl. Carefully pour the hot broth and noodles over the vegetables. Use chopsticks to arrange the vegetables artistically.

Serves 1 kid a tasty Japanese soup.

Kids’ Multicultural Cookbook


LEMON SQUARES

  • 1 cup of Gold Medal all-purpose flour
  • 1/2 cup of margarine or butter, softened
  • 1/4 cup of powdered sugar
  • 1 cup of granulated sugar
  • 2 teaspoons of grated lemon peel, if you like
  • 2 tablespoons of lemon juice
  • 1/2 teaspoon of baking powder
  • 1/4 teaspoon of salt
  • 2 eggs
  1. Heat the oven to 350 degrees
  2. Mix thoroughly flour, margarine and powdered sugar in a small bowl. Press evenly with hands in bottom and about 5/8 inch up sides of an ungreased square pan, 8x8x2 inches. (If dough is sticky, flour fingers.) Bake 20 minutes.
  3. Beat remaining ingredients in a medium bowl on medium speed until light and fluffy. Pour over hot crust.
  4. Bake just until no indentation remains when touched lightly in center, about 25 minutes. Let stand until cool, then cut into about 1 1/2-inch squares.

Makes 25 squares.

LEMON COCONUT SQUARES

Prepare as directed in Lemon Squares except – stir 1/2 cup flakes coconut into fluffy mixture.


2015 summer camp, Creative Learning Center, Alamo, CA

Start vboxnet0 at Boot

I did some work with VirtualBox 4.1.6. on Fedora 15, and I noticed that my host-only network interface vboxnet0 was not created automatically by VirtualBox’s init scripts.  That became a problem because I wanted to configure all interfaces before starting any virtual machines.

It turns out the solution is quite simple. When a command like VBoxManage or VBoxHeadless is run, all network interfaces are set up. So just adding VBoxManage with a harmless option to the init script will ensure the virtual network interfaces are created at boot time. For example, in /etc/rc.d/rc.local I added


VBoxManage list vms > /dev/null 2>&1

Now everything works swimmingly.

Setting Up ClearOS as Wireless Router Using OpenWrt Virtual AP

Update 12/03/2011:  I set up my OpenWrt VM using VMWare Player because I couldn’t get USB to work in VirtualBox.  See What’s Wrong With VrtualBox for descriptions of my problems.  And please let me know if you have solutions.

ClearOS will not have built-in Wi-Fi support until the next version, 6.1, is released.  This blog entry is for those who want to add wireless coverage to their current ClearOS boxes.  I will go over the steps to create an OpenWrt virtual machine using VMWare Player, and to configure it as an wireless access point.

Network Configuration

ClearOS is a Linux server/gateway distribution.  Since it currently lacks Wi-Fi support, often an external wireless AP is added to a network to provide Wi-Fi coverage.  That was my setup until a couple of weeks ago, when my wireless router failed.  Its replacement is a virtual network with a virtual wireless AP.  This tables compares the old, real network with the new, virtual network.

Function Real network Virtual network
DHCP server ClearOS ClearOS
Wi-Fi Access Point Netgear wireless router.  Its DHCP function was disabled. VMWare virtual machine running OpenWrt.  OpenWrt’s DHCP function is also disabled
Connection from ClearOS to Wi-Fi eth2, a Fast Ethernet adapter.  It was connected directly to a LAN port on the wireless router. vmnet2, VMWare virtual network adapter #2.  vmnet2 and the OpenWrt VM are connected through VMWare’s virtual switch
Connection from Wi-Fi to ClearOS Netgear router LAN port #1.  Connected to eth2 through a cable. VM eth0, a virtual Fast Ethernet adapter.  It is configured as an OpenWrt LAN port.
Wi-Fi radio Router radio VM wlan0, a USB wifi adapter.  It is configured as a LAN interface.  OpenWrt connects eth0 and wlan0 using a Linux network bridge.

The two networks have similar topology because I wanted to replicate the real network in a virtual environment.

Selecting a USB Wireless Adapter

There are two requirements when selecting an adapter for an OpenWrt access point:  The adapter must support access point mode (most newer ones do), and its driver is distributed with OpenWrt (many are).  To check if these conditions are met, start by finding the name of the adapter’s driver on Linux wireless wiki.  Its USB device page lists more than 350 adapters and their drivers.  After finding the driver, look for its features on the driver page.  The adapter can function as an access point if “Yes” appears in the “AP” column.

To determine whether the driver is distributed with OpenWrt, look for its kernel module package in the package list.  The name of the package is usually “kmod-<driver name>” but sometimes slightly different.  For example, on Linux wireless wiki there are drivers “ath9k_htc” and “rt2800usb”, but the OpenWrt package names are “kmod-ath9k-htc” and “kmod-rt2800-usb”, respectively.  For this reason it is best to search for a partial name (“kmod-ath” or “kmod-rt28”) and review the result.  The package lists are available from OpenWrt.

Let’s take Rosewill RNX-EasyN1 as an example.  It does not appear on Linux wireless wiki, but searching on Google I learned it is built around Ralink RT3070 and needs driver rt2800usb.  On Linux wireless wiki driver page, I learned the adapter does work in AP mode.  Looking through the package list of OpenWrt 10.03.1-rc6, I found its driver package “kmod-rt2800-usb”.

Finally, beware that newer adapters may not work with older drivers. For example, Rosewill RNX-EasyN1 does not work with the rt2800usb driver distributed with OpenWrt 10.03.

Installing and Configuring VMWare Player

I chose VMWare Player for virtualization because it works and it is free.  Xen and KVM aren’t supported by ClearOS 5.2, which is what I use.  VirtualBox has problem with USB pass-through.

VMWare Player can be downloaded from from VMWare’s web site.  Registration is required to download.  Look for “VMWare Player for 32-bit Linux” and “VMWare VIX API for 32-bit Linux” on the download page.  As of 11/30/2011, 4.0.1 is the latest version, and the files are “VMware-Player-4.0.1-528992.i386.bundle” and “VMware-VIX-1.11.1-528992.i386.bundle”.

Before installing VMWare, gcc and kernel headers need to be installed.  VMWare needs them to re-compile its kernel modules.


bash$ if [ `uname -r | grep PAE` ]; then yum install gcc kernel-PAE-devel ; else yum install gcc kernel-devel ; fi

This one liner checks the kernel release and installs the matching kernel headers.

To install VMWare Player


bash$ chmod +x ./VMware-Player-4.0.1-528992.i386.bundle
bash$ ./VMware-Player-4.0.1-528992.i386.bundle --console

Installation will start after accepting the license agreement and answer a few questions.

Similarly, to install VIX API


bash$ chmod +x ./VMware-VIX-1.11.1-528992.i386.bundle
bash$ ./VMware-VIX-1.11.1-528992.i386.bundle --console

By default, VMWare activates only vmnet1 and vmnet8 virtual network adapters on the host.  To activate vmnet2, first add the following lines to /etc/vmware/networking.


answer VNET_2_DHCP no
answer VNET_2_HOSTONLY_NETMASK 255.255.255.0
answer VNET_2_HOSTONLY_SUBNET 192.168.75.0
answer VNET_2_VIRTUAL_ADAPTER yes

Altough 192.168.75.0/24 is shown, feel free to select any valid subnet for vmnet2.  In fact, vmnet2 will not be assigned an IP address in the final setup.

Now create a device node for vmnet2 and restart VMWare virtual network.


bash$ mknod /dev/vmnet2 c 119 2; vmware-networks --stop; vmware-networks --start

Running ifconfig should show vmnet2 active with IP address 192.168.75.1

Configuring ClearOS

Although vmnet2 is active at this point, ClearOS’s webconfig still can’t detect it.  (I do not know the reason.  If anyone does, please leave a comment.)  This is a problem because webconfig is the best tool for configuring ClearOS.  However there is a workaround.  Since webconfig can detect Linux Ethernet bridges, adding vmnet2 to a bridge creates a suitable network interface.

The first step is to install the bridge utilities.


bash$ yum install bridge-utils

To set up the Ethernet bridge


bash$ brctl addbr br0
bash$ ifconfig vmnet2 inet 0.0.0.0
bash$ brctl addif br0 vmnet2
bash$ ifconfig br0 up

The first command creates the bridge br0, the second deletes vmnet2’s IP address, the third adds vmnet2 as a port of br0, and finally the last command activates the bridge.

The next step is to use webconfig to configure br0.  After logging in, select “IP Settings” under the Network menu, and then click on the “Edit” button for br0.

image

On the next page, assign a role and IP setting to br0.  For example here br0 is set up as the “Hot LAN” interface with a static IP address 192.168.2.1.  Click on “Confirm” to save changes.

image

The final step in webconfig is to add DHCP settings for br0.  Select “DHCP Server” under the Network menu, and then click on the “Add” button for br0.

image

On the next page, make suitable changes for your network and click on “Update” to save the settings.  The following image shows the default ClearOS settings for the 192.168.2.0/24 subnet.

image

Now log out from webconfig and return to a shell session to edit two files.  One is /etc/sysconfig/network-scripts/ifcfg-br0.  This file is updated whenever the IP settings of br0 change.  However ClearOS has a bug and classifies br0 as a regular Ethernet interface instead of a Linux bridge.  To fix this problem change the value of TYPE from "Ethernet" to "Bridge", as shown below.  Make sure to use a uppercase “B” followed by lowercase “ridge”.  This field is case sensitive.  Also, the value of <code>HWADDR</code> should be set to <code>00:00:00:00:00:00</code>.  A bridge does not have a MAC address until an interface is added.


DEVICE=br0
TYPE="Bridge"
ONBOOT="yes"
USERCTL="no"
HWADDR="00:00:00:00:00:00"
BOOTPROTO="static"
IPADDR="192.168.2.1"
NETMASK="255.255.255.0"

Second, add the following lines to /etc/rc.d/rc.local


ifconfig vmnet2 inet 0.0.0.0
/usr/sbin/brctl addif br0 vmnet2

vmrun -T player \
    start /etc/vmware/guests/OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6.vmx \
    nogui

/etc/rc.d/rc.local is the last init script to run, after all real and virtual network interfaces are configured.  The purpose of these three lines is to connect vmnet2 to br0 and to start the OpenWrt virtual machine.  The parameter /etc/vmware/guests/OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6.vmx of the last command specifies the VM’s configuration file, which is discussed in the next section.

Setting Up OpenWrt VM

With ClearOS and VMWare configured and ready, it’s time to install the virtual machine.  One that boot into OpenWrt 10.03.1-rc6 is available from my SkyDrive.  Its files are stored in gzipped tar files.  (I will add new VMs when new versions become available.)

The content of a tar file can be extracted to any location.  I prefer /etc/vmware/guests.


bash$ mkdir /etc/vmware/guests
bash$ cat OpenWrt-10.03.1-rc6.tar.gz | ( cd /etc/vmware/guests; tar xzvf - )
./OpenWrt-10.03.1-rc6/
./OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6-disk1.vmdk
./OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6.vmx

The .vmdk file is the VM’s disk file.  The .vmx file is its configuration file.

For VMWare to automatically connect a USB Wi-Fi adapter to a VM, the adapter’s vendor ID and product ID need to be in the .vmx file.  To find them first install Linux USB utilities.


bash$ yum install usbutils

Next use lsusb to list USB devices connected to the host PC.  The following result shows the Rosewill adapter and a USB thumb drive.


bash$ lsusb
Bus 007 Device 001: ID 0000:0000
Bus 002 Device 003: ID 125f:0000 A-DATA Technology Co., Ltd.
Bus 002 Device 001: ID 0000:0000
Bus 002 Device 002: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Bus 005 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 006 Device 001: ID 0000:0000
Bus 008 Device 001: ID 0000:0000

For each device two 4-digit hexadecimal numbers, separated by a colon, appear after “ID”.  The number before colon is the vendor ID; the other is the product ID.  In this example “148f” is the vendor ID, and “3070” is the product ID.

Now append the following line to the VM’s .vmx file (/etc/vmware/guests/OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6.vmx if the commands shown earlier are followed verbatim):


usb.autoConnect.device0 = "vid:<vendor ID> pid:<product ID>"

Using the Rosewill adapter as an example again:


usb.autoConnect.device0 = "vid:148f pid:3070"

OpenWrt First Boot

At this point the virtual machine is ready for its first boot.  To start the VM,

bash$ vmrun -T player start /etc/vmware/guests/OpenWrt-10.03.1-rc6/OpenWrt-10.03.1-rc6.vmx nogui

This is one of the commands added to /etc/rc.d/rc.local.

To confirm the VM is up and running, do a DNS lookup.

bash$ nslookup OpenWrt localhost

Server:         localhost
Address:        127.0.0.1#53

Name:   OpenWrt
Address: 192.168.2.134

To configure OpenWrt, start a telnet session to the returned IP address.


bash$ telnet 192.168.2.134
Trying 192.168.2.134...
Connected to 192.168.2.134.
Escape character is '^]'.
 === IMPORTANT ============================
  Use 'passwd' to set your login password
  this will disable telnet and enable SSH
 ------------------------------------------

BusyBox v1.15.3 (2011-10-29 04:41:06 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 Backfire (10.03.1-RC6, r28680) --------------------
  * 1/3 shot Kahlua    In a shot glass, layer Kahlua
  * 1/3 shot Bailey's  on the bottom, then Bailey's,
  * 1/3 shot Vodka     then Vodka.
 ---------------------------------------------------
root@OpenWrt:/#

As  the screen suggests, the first order of business should be setting a secure password.

Next is to install the adapter driver and access point software.  As mentioned in “Selecting a USB Wi-Fi adapter”, the Rosewill adapter’s driver package is “kmod-rt2800-usb”:


root@OpenWrt:/# opkg update ; opkg install hostapd kmod-usb2 kmod-rt2800-usb

Substitute “kmod-rt2800-usb” with the appropriate driver for your setup.

Once the driver is installed,  use OpenWrt’s wifi command to generate the default wireless configuration file. “uci” commands are then used to set options.


root@OpenWrt:/# wifi detect > /etc/config/wireless
root@OpenWrt:/# uci set wireless.radio0.disabled=0
root@Openwrt:/# uci set wireless.@wifi-iface[0].ssid=<your SSID>
root@OpenWrt:/# uci set wireless.@wifi-iface[0].encryption=psk2
root@OpenWrt:/# uci set wireless.@wifi-iface[0].key=<your passkey>
root@OpenWrt:/# uci commit

Here the first command creates the template; the second enables the radio; the third sets Wi-Fi’s SSID; the fourth and fifth commands enable encryption; and the last command saves configuration changes. By default the wireless network and OpenWrt LAN port eth0 are bridged, so no network options need to change.

Since ClearOS is already set up as the DHCP server for the wireless subnet, OpenWrt’s DHCP server needs to be disabled and stopped.


root@OpenWrt:/# /etc/init.d/dnsmasq disable
root@OpenWrt:/# /etc/init.d/dnsmasq stop

Finally, restart OpenWrt’s network interfaces.


root@OpenWrt:/# /etc/init.d/network restart

Now your ClearOS box with built-in Wi-Fi access point is ready.

What’s Wrong With VirtualBox?

I started this project using VirtualBox 4.1.6 and 4.0, but I just couldn’t get the USB adapters to work.  I tried to two adapters.  One is TP-Link TL-WN722N (Atheros AR9271), and the other is the Rosewill.  When running in VirtualBox, OpenWrt couldn’t download the adapter’s firmware.  OpenWrt did initialize the Rosewill adapter and set up the access point, but no device could connect to it. If you know the solutions to these problems, please let me know.

VMWare Has Problems Too

VMWare can’t seem to reset the TP-Link adapter.  If I rebooted the OpenWrt VM after the adapter was initialized, OpenWrt wouldn’t be able to access it again.  But if I unplugged it and then plugged it back in, everything would be fine.  Or if I rebooted ClearOS, it would work too.

Changes on OpenWrt Disk Image

Before converting the raw ext2 disk image to a .vmdk file, I made three changes.

  1. From GRUB configuration file I deleted all things related to the serial port.  There is no need to work through a serial-port console when the VM’s regular console is available.  This change shortens boot time.
  2. The default configuration of eth0 is changed from static IP address to DHCP, reporting the hostname “OpenWrt”.  This is necessary because OpenWrt is just a normal device in the network, not a DHCP server or router.
  3. In the network initialization script /etc/init.d/network, a 10-second delay is added before the wireless interface is brought up, because it takes a while for USB devices to settle down.

History

12/03/2011:  Add descriptions of VirtualBox USB problem, VMWare/TP-Link problem, and chanages to OpenWrt disk image.

Expanding x86 OpenWrt Root Partition

The root partition of the official x86 OpenWrt image is not very big, about 50 MiB.  Many find it too small after installing a few add-on packages.  Here I will cover the steps to expand it.  The resultant image can be used in a live USB (see Easy Live USB for x86 OpenWRT) or copied to a hard disk.

Procedure Outline

  1. Get an uncompressed disk image.
  2. Pad image to desired size
  3. Attach the image file to a loop device
  4. Edit image partition table to enlarge the root partition
  5. Resize the file system in root partition
  6. Detach the image from the loop device.

All commands below are run in Bash.

Uncompress Image File

Use whichever method you like to download an image file from OpenWrt (http://downloads.openwrt.org) and uncompress it using gzip.  For example, these two commands download and uncompress the 10.03.1-rc6 disk image.


bash$ wget --quiet http://downloads.openwrt.org/backfire/10.03.1-rc6/x86_generic/openwrt-x86-generic-combined-ext2.img.gz
bash$ gunzip openwrt-x86-generic-combined-ext2.img.gz

Alternative, you can just copy an image file from a live USB flash drive.  This will save you the trouble of restoring custom configurations.

Pad Disk Image

The next step is to use “dd” to increase the size of the disk image.


bash$ dd if=/dev/zero bs=1M count=50 >> openwrt-x86-generic-combined-ext2.img

This command appends 50 MiB of zeros to the end of the disk image:  “if=/dev/zero” tells dd to copy data from /dev/zero; “bs=1M” sets the block size to 1 MiB (1024*1024 bytes); “count=50” tells dd to copy 50 blocks.

Attach to Loop Device

Note:  All commands from this point to the end need to be run by a user with root privilege.

These commands find an unused loop device and attach it to the image file.

bash$ loop_dev=`losetup -f`
bash$ echo $loop_dev
/dev/loop3
bash$ losetup $loop_dev openwrt-x86-generic-combined-ext2.img

The first command uses “losetup -f” to find an unused device and stores the result in the shell variable loop_dev.  The “echo” command shows the device found.  Finally “losetup” attaches the device to the disk image.

Edit Partition Table

To expand a disk partition, it needs to be deleted first.  A new, larger partition is then created to take its place.  This new partition must start from the same sector as the old to prevent loss of data.

fdisk is used to manipulate the disk partition table.

bash$ fdisk -u=sectors -c=dos $loop_dev

The -u option asks fdisk to list partitions in sectors.  The -c option tells fdisk to operate in DOS compatibility mode.  $loop_dev is the loop device attached to the image file.

To see the existing partitions, type “p” at the fdisk prompt.

Command (m for help): p

Disk /dev/loop3: 107 MB, 107437568 bytes
16 heads, 63 sectors/track, 208 cylinders, total 209839 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
/dev/loop3p1   *          63        9071        4504+  83  Linux
/dev/loop3p2            9135      107855       49360+  83  Linux

fdisk shows /dev/loop3 has 209839 sectors.  It also lists two partitions.  The first one, /dev/loop3p1, is a small boot partition.  The second, /dev/loop3p2, is the root partition.  The root partition starts from sector 9135.  Make a note of this number.

Now delete the root partition and create a new one that covers all available space.


Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 2): 2
First sector (9072-209838, default 9072): 9135
Last sector, +sectors or +size{K,M,G} (9135-209838, default 209838): 209838

Command (m for help): w
The partition table has been altered!

The “d” command asks fdisk to delete a partition, and “2” selects the second partition for deletion.  The “n” command asks fdisk to create a new partition.  “p” specifies a primary partition, and “2” selects the second primary partition.  The first sector of this partition is sector 9135, same as the deleted partition.  Its last sector is sector 209838, the default choice.  This is also the last sector on /dev/loop3.  Finally, the “w” command writes the new partition table through /dev/loop3 to the disk image.

Resize Root File System

The following commands will expand the root file system to the size of the root partition.

bash$ kpartx -a $loop_dev
/dev/mapper/loop3p1: mknod for loop3p1 failed: File exists

The “kpartx -a” command creates device nodes for the partitions in the disk image.  The output of “kpartx –a” (“mknod for loop3p1 failed”) seems to be a bug in my system.  As far as I can tell, the creation and deletion of loop3p1 occur normally.

Another thing worth noting:  kpartx and fdisk use different naming conventions.  kpartx uses “/dev/mapper/device_name”, for example “/dev/mapper/loop3p1”.  fdisk uses “/dev/device_name”, such as “/dev/loop3p1”.  This is because kpartx works with the device mapper.

Now run “fsck” to check the file system before resizing it.  In fact, some file systems can’t be resized until they are checked.

bash$ fsck -f /dev/mapper/loop3p2
fsck from util-linux 2.19.1
e2fsck 1.41.14 (22-Dec-2010)
Filesystem did not have a UUID; generating one.

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/mapper/loop3p2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/loop3p2: 957/6000 files (0.2% non-contiguous), 8173/49152 blocks

The “-f” option forces a run even when the file system seems clean.
Finally, resize the root file system.

bash$ resize2fs /dev/mapper/loop3p2
resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/mapper/loop3p2 to 100352 (1k) blocks.
The filesystem on /dev/mapper/loop3p2 is now 100352 blocks long.

bash$ kpartx -d $loop_dev

After resizing, “kpartx -d” reverses the changes made by “kpartx -a”.

Detach From Loop Device

The final step is to detach the image file from the loop device.


bash$ losetup –d $loop_dev

That’s it.  The disk image is now ready to be used in a live USB or copied to a hard disk.

Booting From USB Without BIOS Support

After creating my OpenWRT live USB (Easy Live USB for x86 OpenWRT), I wanted to use it on an older PC but ran into a problem:  its BIOS does not support booting from USB.  I had two choices.  One was to boot up Linux from CD then switching to USB drive.  The other was to get a CD bootloader that can read USB drives.  Not wanting to do more work, I went searching and found Plop Boot Manager.  It is very impressive.  Compact and full of features.  It handles multiboot.  It works with many bootloaders.  It can boot OS on USB or CD without BIOS support.  It even has a great GUI reminiscent of video arcade games.  And it’s free.  Do take a look.

But if you just want to get down to business, I have a ready-to-use CD image (plpbt_hiddenusb.iso on my SkyDrive).  Just insert  the CD and plug in your USB drive.  Plop Boot Manager will do the rest.

Posted in Linux. 2 Comments »