Posts Tagged ‘Unix’

This post will document how to setup the DSTAR Commander image for use on a Raspberry Pi / DVMEGA hotspot.  I use a Mac.  Theses instructions demonstrate how I set up my hotspot using a Mac.  These hotspots are great to use and enable you to talk across the globe using an HT on low power.

Outline:
  1. Burn image to SD Card
  2. Boot your Pi and VNC into it
  3. Set up DSTAR Repeater
  4. Set up ircddb Gateway
  5. Set up text and email of system information
  6. Create Remote Control App
  7. Reboot and Test
  8. Secure your Pi (Change user password and VNC password)
  9. Change the Hostname of your Pi
  10. References
What you will need:
  • 16 GB or greater SD card. I love this Lexar card. I don’t recommend PNY. The one I bought failed in a couple of months.
  • SD Card Reader (The USB reader that came with my Lexar works great).
  • G4KLX image. I have used many of them and prefer DSTAR Commander.
  • A VNC Program. I use Jump Desktop on the Mac and iOS they all sync together and work great!
  • The Unarchiver application, free in the Mac App Store.
  • Software that will let you see devices connected to your network via ethernet. If, like me, you are using an Apple Time Capsule the Airport utility will only show you devices connected wirelessly. Use the iPhone app Fing to get the ip and MAC address of your Pi.

(more…)

Advertisements
Introduction

I love the Raspberry Pi! I am currently using one as a local DSTAR hotspot. It works great. I have tried several different images (Maryland-DSTAR, Western, and DSTAR Commander). I think I have settled on DSTAR Commander. I think I finally have everything working exactly how I want it to.

When making tweaks to the system, it is very important to make a backup of your current system so that you can easily go back to where you started if you messed something up. Additionally, if your SD Card fails (and it WILL), having a backup will enable you to quickly get your system back online.

I used to have to shut down the pi, pull the SD Card out, find my SD Card adapter, plug it into my Mac, make a backup, and then reverse the process to get my system online again.  Those days are over. You can make a backup of your pi and have the backup written to your regular PC all from the command line. Here is how to do it.

Bottom Line Up Front:

From your local machine, run the remote backup command:

ssh pi@xx.x.x.xx "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=~/Desktop/pibackup.gz

If you ever need to use your back up you cannot do it remotely (at least that I know of).  You will need to insert the SD card into your local machine and run the following commands:

diskutil unmountDisk /dev/disk#
gzip -dc ~/Desktop/pibackup.gz | sudo dd of=/dev/rdisk# bs=1m conv=noerror,sync

Continue reading if you need much more detailed instructions on what this command does, what each piece of the command means, and how to get all of the necessary inputs.

(more…)

GEEK ALERT! GEEK ALERT! GEEK ALERT!

I recently purchased an early 2015 13″ Ratina MacBook Pro. I wanted to do something with the SD Card slot and saw an ad for the Nifty MiniDrive. I decided I was going to install Ubuntu on the SD Card so that it was always available but without making any permanent modifications to my internal drive. This post will describe exactly what I did to accomplish this goal.

When complete, you will have Ubuntu installed to your SD card, rEFInd installed on your SD Card, and GRUB will be removed from your internal hard drive.  When booting into Ubuntu you will first use the Apple Boot Manager (by holding the “option” key) to get you to rEFInd, and then rEFInd will boot Ubuntu in verbose mode.

Eventually, I would like to remove rEFInd as well and just use the Apple StartUp Manager to boot directly into Ubuntu but I have not found a good tutorial yet.  In all honesty, I don’t understand enough about EFI booting to understand how the boot process is being completed without GRUB.  I just deleted GRUB from /dev/sda to see what would happen and found that not only did Ubuntu boot but it booted a lot faster without it!

Nifty MiniDrive

Nifty MiniDrive

Nifty MiniDrive installed in the SD Card slot of my rMBP

Nifty MiniDrive installed in the SD Card slot of my rMBP. The entire Ubuntu system, rEFInd, and my user files all reside inside that little red MicroSD Card.

Nifty MiniDrive Box

Nifty MiniDrive Box

Downloads

What you need

  • 32GB or greater micro SD Card
  • Nifty MiniDrive Adapter (not required. You can use any SD Card or MicroSD Card with adapter.
  • Ubuntu 15.04 iso
  • 8GB USB stick (to create the Ubuntu install USB)
  • A verified, and bootable backup of your system.

Create The Ubuntu Live USB

Create a bootable Ubuntu USB stick using these instructions on the Ubuntu download page.

Prepare SD Card

Use Disk Utility to create three partitions on the SD Card.

  • 10GB for the Ubuntu root partition (FAT32). Will be changed to ext4 during install of Ubuntu.
  • 18GB for your Home partition (FAT32).  Will be changed to ext4 during install of Ubuntu.
  • ~4GB for a Share partition (FAT32)
  • Select options and select GUID partition scheme.
  • Press Apply.

Install rEFInd onto the SD Card

  1. Open Terminal and type the following command
    diskutil list
  2. The output will look similar to this:
    $ diskutil list
    /dev/disk0
    #:                      TYPE NAME     SIZE      IDENTIFIER
    0:     GUID_partition_scheme          *500.3 GB disk0
    1:                       EFI EFI      209.7 MB  disk0s1
    2:         Apple_CoreStorage          499.4 GB  disk0s2
    3:    Apple_Boot Recovery HD          650.0 MB  disk0s3 
    
    /dev/disk1
    #:                      TYPE NAME     SIZE      IDENTIFIER
    0:         Apple_HFS MBP SSD          *499.1 GB disk1
                                 Logical Volume on disk0s2
                                 11B21249-47B3-4FF1-A807-AD81CEC8B910
                                 Unencrypted
    
    /dev/disk2
    #:                      TYPE NAME     SIZE      IDENTIFIER
    0:     GUID_partition_scheme          *31.9 GB  disk2
    1:                       EFI EFI      209.7 MB  disk2s1
    2:      Microsoft Basic Data UBUNTU   10.5 GB   disk2s2
    3:      Microsoft Basic Data HOME     18.1 GB   disk2s3
    4:      Microsoft Basic Data SHARE    3.1 GB    disk2s4
    $
  3. Above, you can see that the EFI partition on my 32GB flash drive is /dev/disk2s1.
  4. Type the following commands in Terminal to mount the EFI partition of the SD Card:
    mkdir /Volumes/efisd
    sudo mount -t msdos /dev/disk2s1 /Volumes/efisd
  5. Mount the rEFInd disk image.
  6. Drag the rEFInd EFI folder and copy it to the EFI partition of the SD Card by dragging and dropping. Unmount the rEFInd image.
  7. On the SD Card EFI folder, delete the 32-bit drivers and executables.
  8. Optionally, you can edit the rEFInd.conf file in order to remove the Recovery HD, and Legacy mode boot options.  Just open the rEFInd.conf file in a text editor and remove the “#” that precedes these two lines in the file.  They are not adjacent so you will have to scroll through and find them.
    scanfor internal,external,optical,manual
    dont_scan_volumes "Recovery HD"
  9. Once you make the edits to rEFInd.conf, save it and close it.
  10. OPTIONAL: With the EFI partition mounted you can change the icon to an Ubuntu icon (or any other icon you prefer.  Find an icon you like and apply it to the EFI folder.  I used an Ubuntu icns file I downloaded off of the internet.
  11. Eject the EFI folder.
  12. Copy the wireless driver to the share partition on your SD Card. Just drag the “brcmfmac43602-pcie.bin” file that you downloaded earlier to the SHARE partition on the Micro SD Card.

Install Ubuntu to the SD Card

  1. Ensure your Ubuntu Live USB is inserted.
  2. Reboot computer and press and hold the option key after you hear the startup chime. If you changed the icon of the EFI folder on the SD card, then your start up screen will look similar to mine. If you see two “EFI” sections, choose the one on the left.

    Start Up Manager before installing Ubuntu. Choose the LEFT EFIBoot.

    Start Up Manager before installing Ubuntu. Choose the LEFT EFIBoot.

  3. Select “Try Ubuntu” and let it boot up.
  4. Click on “Install Ubuntu” and follow the prompts until you get to Preparing to Install Ubuntu.
  5. Ensure that “Download updates while installing” and “Install this third-party software” are Unchecked. My installs failed when either were checked.
    Do not install updates or software
  6. When you get to Partitioning, choose “Something Else.”
  7. At the bottom of the window, select /dev/sdb2 as the location to install the boot loader (the same partition that you will install Ubuntu and mount at /. I think there is a bug in the installer because it always installs GRUB to the EFI partition of /dev/sda/. No worries because we will fix it after the install.
  8. Select the /dev/sdb2 partition (yours may be different, make sure you choose your 10GB Ubuntu partition). Press “Change…” In the drop down choose use as ext4 and set mount to “/”. Check format. Hit ok.
  9. Select /dev/sdb3 (may be different on your system, choose the “HOME” partition you created when we prepared the SD Card in OS X). Press “Change…” In the drop down choose use as ext4 and set mount to /home. Check format. Hit ok.
  10. Hit continue. You’ll get a warning that you will erase those two partitions. Hit ok.
  11. You’ll get another message that you have no Swap. That is fine, I have 16GB of RAM and doubt I will need it. Hit ok.
  12. Press “Install.”
  13. Once the install is complete choose to reboot.  You’ll get a message to remove the Installer USB and press enter.  Remove it and press enter.  The system will reboot. Reboot into OS X.

Remove GRUB From Your Internal Drive

  1. Once you are booted back into OS X, open a Terminal.
  2. Mount the EFI partition of your internal hard drive using the following commands.
    diskutil list
    Your EFI partition is probably disk0s1 but verify this from the output of diskutil list!
  3. Type the following commands in Terminal to mount the EFI partition of your internal HD:
    mkdir /Volumes/efi
    sudo mount -t msdos /dev/disk0s1 /Volumes/efi
  4. The EFI partition will mount.  Open it with the Finder.
  5. Open the EFI Folder.  There will be two folders: APPLE and UBUNTU
  6. Delete the UBUNTU folder ONLY
  7. Eject the EFI volume.
  8. Restart the computer.
  9. Press the “option” key after you hear the start up chime and choose “EFIBoot.” Mine looks like this:

    Apple Start Up Manager

    Apple Start Up Manager

  10. On the rEFInd Menu Choose Ubuntu and press enter.  Your system will load.  Enter your password and you will be logged in to Ubuntu. My rEFInd Menu looks like this:

    rEFInd Menu

    rEFInd Menu

  11. If you open the “Disks” application in Ubuntu you can see how your partitions are laid out.  Below is a picture of my final set up.

    Final partition setup in Ubuntu

    Final partition setup in Ubuntu

Get Your Ubuntu WiFi Working

  1. Open Terminal and enter the following commands:
    cd /lib/firmware/brcm
    sudo cp /media/YOURUSERNAME/SHARE/brcmfmac43602-pcie.bin .
  2. Reboot.
  3. WiFi should be working and you should be able to update your software.
  4. Reboot after updates have been applied and enjoy Ubuntu running off your SD Card!

Fixes Still Required

  1. 5Ghz WiFi does not work.  Only 2.4Ghz.
  2. Trackpad does not work perfectly.  No two-finger scrolling or two-finger right clicking.
    1. Go to Github and download the zip file (on the right hand side).  Extract the archive.  Open a terminal go to the directory of the archive.  Follow the instructions in the readme file and reboot.  Works like a charm!
    2. I noticed that after an update, I had to re-apply this fix.  So bookmark the github link.
  3. I’d like to figure out a way to get rid of rEFInd but have not figured that out yet.

I hope you found this tutorial helpful.  Please leave a comment if it helped or if you have any questions.

References

I recently bought a new hybrid SSD drive for my MacBook Pro 5,1.  I’m dual booting Mac OS X and Ubuntu 11.04 64-bit.  I’ve made a lot of changes to my Ubuntu system and I really did not want to go through the hassle of reinstalling Ubuntu and redoing the changes.  I needed a way to clone the entire hard drive to include the partition schemes, operating systems and files.

I used the Unix command “dd” to accomplish this task.  Using dd I cloned my old (internal) drive to the new (external) drive.  Both systems remain bootable and all files and permissions remain intact.  dd does not care what operating system(s) are on the drive or how many partitions you have.  It is a bare-metal duplication from one drive to the other.

I did a lot of research on the ‘net to learn how to do this.  I am writing this post to help others that may find themselves in the same situation.  Additionally, this will capture everything I’ve learned so that I can refer back to it the next time I have to do this.

Like my other Unix posts, let me alert you to to the EXTREME geekiness of this post.  If Unix commands are not your thing, don’t waste your time reading the rest of this.

One of the reasons I enjoy working with Unix on Mac OS X & Ubuntu is that it provides a playground for me to learn how my computer works. I get immense joy when I string a Unix command together and it works. (My wife would be rolling her eyes right now.)

Reqired Items

  1. Bootable backup of your working system(s) and files. (The unofficial nick-name for dd is “Data Destroyer” because if you type the command wrong, you will nuke your entire system).

  2. Your new hard drive.  I formatted mine before this process although I don’t think this is required.

  3. An external enclosure for your new drive to reside during the operation.

Preparation

  1. Disconnect from the internet to prevent Dropbox, MobileMe or Mail from changing your system while going through this process.

  2. Backup your system; especially your important files. It’s too easy to destroy your system.

  3. Boot from your backup. All of this was done with OS X but could also be done from Linux.

  4. Attach the hard drive you want to clone your drive to.

  5. The drive will mount. Unmount it (do not eject) using disk utility; leave it connected via USB or FW.

Clone Your Hard Drive

  1. Open a terminal window and run the following command:

diskutil list

It will output the following:

$ diskutil list
/dev/disk0
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        500.1 GB   disk0
1:                        EFI                         209.7 MB   disk0s1
2:                  Apple_HFS JangoFett               469.6 GB   disk0s2
3:       Microsoft Basic Data                         9.3 GB     disk0s3
4:       Microsoft Basic Data                         20.0 GB    disk0s4
5:                 Linux Swap                         1.0 GB     disk0s5
/dev/disk1
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        
500.1 GB   disk1
1:                        EFI                         209.7 MB   disk1s1
2:                  Apple_HFS Backup                  499.8 GB   disk1s2
/dev/disk2
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *500.1 GB   disk2
1:                        EFI                         209.7 MB   disk2s1
2:                  Apple_HFS BobaFett                499.8 GB   disk2s2

Backup (disk1) is the drive I have booted from.  JangoFett (disk0) is the SOURCE and BobaFett (disk2) is the TARGET.  EVERYTHING on the target drive will be erased during the operation.  Note that we want to clone the entire disk so we use disk0.  If we only wanted to clone the JangoFett partition to the BobaFett partition, disk0s2 would be the source and disk2s2 would be the target.

  1. Run the following command:

   sudo dd if=/dev/rdisk0 of=/dev/rdisk2 bs=128m conv=noerror,sync

  • sudo  = Super User Do; runs the command as root or the super user
  • dd   = Data Description; utility used to copy and convert data
  • if   = input file (the SOURCE or the drive you want to copy FROM) which is /dev/rdisk0
  • of   = output file (the TARGET or the drive you want to copy TO) which is /dev/rdisk2
  • bs   = the block size 128m; you can experiment with smaller or larger numbers depending upon what you are doing.
  • conv = tells dd not to worry about errors noerror and sync says write 0’s to the target if you can’t read the data.

Note: I use rdisk0 and rdisk2 instead of disk0 and disk2.  rdisk is the block device; disk is the character device.  The command works using both but seems to run faster when using rdisk.  I’m sure my understanding is probably off.  Again, I’m not an expert.  I know just enough to be dangerous.

When you press enter you will be asked for your password; enter it and hit return.

Like most Unix commands, there is no feedback, no progress bar, nothing.  The cursor just sits there and blinks at you (mocking you) while it follows your instruction.  Don’t fret. Let it run it’s course. When it completes you will see a completion message telling you how many blocks and files that were copied. This could take HOURS (it will be significantly less time than re-partitioning, re-installing and editing everything).

Getting the status of dd

As my wife would tell you, I’m not very patient.  I surely loathe not knowing what is going on.  Fortunately, this provided another Unix learning opportunity.  Computers are machines, they do EXACTLY what we tell them to do (mostly).  You just have to know how to ask.  The commands below assume that dd is currently running.

The Easy Way (works on a Mac):

Press “CTRL + T”

The Hard Way:

  1.  Open a new (2nd) Terminal window.

  2.  Enter the following command:

   ps -ac | grep dd

  • ps   = Process Status; displays all of the processes that have controlling terminals
  • -ac  = Two options to the ps command.  a tells ps to show your processes and other users’ processes; c tells ps to just list the executable name of the process (dd) instead of the entire command.
  • |    = “pipe” diverts output from the previous command to the next command
  • grep = Global Regular Expression Print; searches for a pattern from what is inputed to it
  • dd   = the pattern we are searching for; since we ran the command “dd” we want to search for that pattern.

The command will return something like the following:

$ ps -ac | grep dd
355 ttys000    1:39.76 dd

The first number is the PID or Process ID of dd.  We need the PID in order to ask dd its current status.  We get the status by running the following command:

   kill -INFO 355

  • kill  = is the command used to terminate or signal a process.  
  • -INFO = is an option to the kill command; it tells your computer “don’t terminate the process, just tell me what’s going on.”
  • 355   = the PID of dd; the process whose status we want to know 

The status of dd is written to the FIRST terminal window (where dd is running):

1266+0 records in
1265+0 records out
169785425920 bytes transferred in 4582.019038 secs (37054719 bytes/sec)

Run the command as many times as you want.  You’ll see the the numbers increasing with each successive instance of the command.

Explaining the Status Message

1266 is the number of records dd has read from the source (disk0); 1265 is the number of records dd has written to the target (disk2).  A record is a block.  The size of that block is 128m (128 Mega Bytes) because that is what we instructed dd to use when we ran it.

For those that don’t know, there are 1024 bytes in a kilobyte; 1024 kilobytes in a megabyte; and 1024 megabytes in a gigabyte.

Ergo: 1265 (records) x 128 (megabytes/record) x 1024 (kilobytes/megabyte) x 1024 (bytes/kilobyte) = 169,785,425,920 bytes (which is exactly the number of bytes that have been transferred).

It took dd 4,582 seconds to make that transfer which is about 1 hour and 16 minutes (4582 / 60).  Knowing that we have a 500GB hard drive we can estimate that it is going to take about 4 hours to clone the drive.

Completion

When dd completes the cloning process and exits, it will display its’ final status message.

dd: /dev/rdisk2: short write on character device
dd: /dev/rdisk2: Input/output error
3726+1 records in
3726+1 records out
500107862016 bytes transferred in 14584.393113 secs (34290619 bytes/sec)

The error message states that the last block was “short” meaning it wasn’t a full 128MB block.  The “+1” (3726+1) is the number of errors.  Only one error which was the short write at the end.  Nothing to worry about.

At this point the drives are EXACTLY the same; bit for bit.  To verify this run the following command:

    diskutil list

Returns the following output:

 

/dev/disk0
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        500.1 GB   disk0
1:                        EFI                         209.7 MB   disk0s1
2:                  Apple_HFS JangoFett               469.6 GB   disk0s2
3:       Microsoft Basic Data                         9.3 GB     disk0s3
4:       Microsoft Basic Data                         20.0 GB    disk0s4
5:                 Linux Swap                         1.0 GB     disk0s5
/dev/disk1
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        
500.1 GB   disk1
1:                        EFI                         209.7 MB   disk1s1
2:                  Apple_HFS Backup                  499.8 GB   disk1s2
/dev/disk2
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *500.1 GB   disk2
1:                        EFI                         209.7 MB   disk2s1
2:                  Apple_HFS JangoFett               469.6 GB   disk2s2
3:       Microsoft Basic Data                         9.3 GB     disk2s3
4:       Microsoft Basic Data                         20.0 GB    disk2s4
5:                 Linux Swap                         1.0 GB     disk2s5

You now have a perfect clone of your hard drive!

Remove the clone from the external enclosure, pop it into your computer and voila!  All systems running perfectly with no data loss.

If you want to boot from the clone while it is attached via FireWire or USB there are other some other things that need to be done.  That will have to wait for another post.  I’m still figuring that out.

If this was helpful, or you spot an error, please leave a comment!