Using your Feabhas USB stick on a Mac

Nearly all our Feabhas courses now have their tools/lab exercises on a bootable Linux USB stick, either Fedora or Ubuntu. These USB sticks were designed to boot laptop PCs, but Macbook Pros are becoming increasingly popular in the laptop market, with 10% of the market in 2015.

Our USB sticks won’t boot a Macbook Pro, but we can run them in a virtual machine on a Mac.

Here I’ll talk you through what needs to be done in nine easy steps to get one of our EL-503 or EL-504 Fedora 19 USB sticks working with a Macbook Pro with Virtual Box, so that you can do all the Lab exercises in our courses including firing rockets from the USB rocket launchers!

My thanks to Niall Cooling – evangelist of all things Mac – for taking the plunge and getting a USB stick booting on his Macbook pro!

1. Insert the USB Stick.

When you first insert the USB Drive you’ll likely get the following dialog:

NewImage

Just click ‘Ignore’

2. Find the name of the USB Drive

$ diskutil list

/dev/disk4 (external, physical):
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:     FDisk_partition_scheme                        *15.7 GB    disk4

1:                      Linux                         524.3 MB   disk4s1
2:                 Linux_Swap                         3.6 GB     disk4s2   3:                      Linux                         11.5 GB    disk4s3

In this example it appears as /dev/disk4

Make sure it’s not mounted

$ diskutil unmountDisk /dev/disk4

Unmount of all volumes on disk4 was successful

3. Change file ownership and access permissions to allow the USB stick to run with Virtual Box

Check the USB Drive permissions:

$ ls -al /dev/disk4

brw-r—–  1 root  operator    1,  10  9 Mar 09:04 /dev/disk4

VirtualBox can only read/write files owned by the current user you are logged in as. However Mac OS X, had put root as owner. With this default, you won’t be able to import the disk file that we are going to create. So we need to change the permission of the device:
(note the use of the backward ` not the forward ‘)

$ sudo chown whoami /dev/disk4

Password:

$ ls -al /dev/disk4

brw-r—–  1 Niall  operator    1,  10  9 Mar 09:04 /dev/disk4

4. Create a Virtual Disk File:

There’s two ways we can do this, either from within Virtual Box using the Settings menu or from the command line on a Mac Terminal:

$ VBoxManage internalcommands createrawvmdk -filename /Users/Niall/Documents/usbdrive.vmdk -rawdisk /dev/disk4

RAW host disk access VMDK file /Users/Niall/Documents/usbdrive.vmdk created successfully.

You’ll likely get the following dialog again

NewImage

Ignore as before

Check the created file:

$ ls -al ~/Documents/usbdrive.vmdk 

-rw——-  1 Niall  staff  538  9 Mar 09:19 /Users/Niall/Documents/usbdrive.vmdk

 

5. Create a Virtual Box Image

We can now create a VirtualBox image using this file:

NewImage

You’ll need to allow at least 768MB for Memory Size.

This should result in a machine being created. The VM should run as a single core machine.

NewImage

If we now start this machine it should boot into Linux as expected

NewImage

Now we can log into our VM, there’s four things we need to do:

(i) Get the tools and environment set up to build Linux code in our VM.

(ii) Get a screen debug session so we can interact with a box irrespective of whether it’s an NFS build or a FLASH build.

(iii) Get a TFTP session so we can download new builds onto the box, either Kernel+Rootfs combined RAMdisk builds or just the kernel for an NFS build.

(iv) Get an NFS session up and running for an NFS build.

These will be covered in steps 6-9 but before we go there, a few notes on what can go wrong with subsequent boots – this will save a lot of head scratching at a future date.

5a. What Can Go Wrong:

Removal and Reinsertion of USB Drive causes the VirtualBox machine to no longer boot.

NewImage

If you reinsert the Drive it still fails to start, but with a different error (VERR_ACCESS_DENIED)

However, if you reset the owner then it will boot okay

$ sudo chown whoami  /dev/disk4

5b: Removal and reinsertion where drive number changes 

if you remove and reinsert the device, and the drive is now seen as a different drive because you had other USB Drives previously inserted as well (e.g. from /dev/disk4 to /dev/disk3) then the machine will no longer boot.

In this case, you’ll need to create a new VMDK drive for /dev/disk3 and store it in parallel with the one for /dev/disk4,

In the Virtual Box Settings Menu under Storage you’ll need to change the entry under Controller: SATA to your new vmdk file.

6. Set up the GCC toolchain and build the kernel / install rootfs:

Login as you would on a PC and set up the tools / environment as normal.
Then build the kernel, extract the rootfs, configure the /etc/exports file, disable firewalld and enable/(re)start the xinetd, nfs-server.service and nfs.target as per the Lab instructions on the EL503/EL504 course.

 

7. Setting up Serial Debug
We’ll be using GNU screen to get a serial debug connection to our target board (Beaglebone Black) connecting the USB on the Mac to the TTL 3v3 inline debug connector on the Beaglebone Black board iself

(i) In Virtual Box, under Settings > Ports, click the USB tab and select USB 2.0 (EHCI controller), then connect the Beaglebone board USB debug cable.

(ii) To check your USB serial device on your Mac, type ls -l /dev/tty*  at a shell prompt and note the tty.usbserial device name, e.g. tty.usbserial-FTGVHRT4

(iii) Add a new USB filter using the icon with the green ‘+’ sign and add a filter for FTDI TTL232R-3V3.

Mac_VM_VIrtualBox_USB_Port

the settings should be captured for you, but for reference, they are:
Vendor ID: 0403
Product ID: 6001
Revision 0600,
Manufacturer: FTDI,
Product: TTL232R-3V3,
Serial No FTGVHRT4 (or whatever the extension is to your /dev/tty.usbserial is,
or better still, leave it blank and see if it picks it up automatically).

8. Setting up TFTP:

To get TFTP working on MAC:

(i) Set up a network connection.
You will need a Thunderbolt to 1GB Ethernet adapter (£25 from PC world). Connect the Ethernet to the Beaglebone board as you would on a Linux PC.

NewImage

(ii) Configure the Network Connection in Virtual Box as follows:
– enable network adapter
– attached to Bridged Adapter
– en5: Thunderbolt Ethernet
– Adapter Type: “Intel PRO/1000 MT Desktop (82540EM)
– 
Promiscuous Mode: “Allow All”
– MAC Address 0800279E23EF (or whatever your MAC address is in your VM Network Wired Ethernet Settings) 

(iii) Configure the uEnv.txt file on the SD card to boot your Beaglebone with so that it boots using TFTP.
ipaddr=10.0.0.3
serverip = 10.0.0.1
fdtfile=am335x-boneblack.dtb
kernel_file=zImage
loadzimage=tftp ${loadaddr} ${kernel_file}
loadfdt=tftp ${fdtaddr} ${kernel_file}
my_bootargs=setenv bootargs console=${console} root=/dev/nfs rw nfsroot=10.0.0.1:/home/fedora.rootdir ip=${ipaddr}:::::eth0
uenvcmd=echo “booting from network”; run loadzimage; run loadfdt; run my_bootargs; bootz ${loadaddr} – ${fdtaddr}

(iv) Boot the VM.
Check the xinet daemon is runing using “sudo systemctl status xinetd” and restart using “sudo systemctl restart xinetd” if required.
Check the firewall is disabled using “sudo systemctl status firewalld” and stop/disable it using “sudo systemctl stop firewalld” and “sudo systemctl disable firewalld” if required.

(v) Connect the Beaglebone and power up, and check to see if you can see “########” denoting successful TFTP download.

9. NFS:


Make sure you have unpacked the rootfs into /home/fedora/rootdir and your /etc/exports file contains the line “/home/fedora/rootdir *(rw,sync,no_root_squash,no_subtree_check)

(NB: on some Macs the exports file is /private/etc/exports)

If the network is configured as above for TFTP, then NFS should work. However, if the wrong network connection is set, e.g. en1 Thunderbolt1 or en2 Thunderbolt 2, then you may see TFTP working and NFS not working.

Andy McCormick

Andy McCormick

Technical Consultant at Feabhas Ltd
I provide expertise and training for Embedded Linux courses.

I have over 20 years of experience in the embedded sector, gained at companies such as Pace, Open TV and Sony Semiconductor Europe.

I've led work on numerous projects at all stages in the design cycle with comprehensive expertise in software engineering design, support and integration.
Andy McCormick
Dislike (0)

About Andy McCormick

I provide expertise and training for Embedded Linux courses. I have over 20 years of experience in the embedded sector, gained at companies such as Pace, Open TV and Sony Semiconductor Europe. I've led work on numerous projects at all stages in the design cycle with comprehensive expertise in software engineering design, support and integration.
This entry was posted in General, Linux, training and tagged , , , , . Bookmark the permalink.

Leave a Reply