If you're like me and you've put your microSD (from the Raspberry Pi) into an SD adapter sleeve and then into your MacBook, you see that the
boot partition has mounted nicely and you can even edit the files on there.
But what if you wanted to adjust things on the next partition, the one that's associated with root?
Or, what if you've made an IMG file of your entire microSD (using something like Etcher or ApplePi-Baker) and you'd like to edit that second partition there in place in the file (without first burning it to media)?
Or what if, like me, you have a pile of microSD cards each with different projects on them and you need to figure out what this one is? I'll take you through this scenario below to show you how easy it can be.
The bad news
The bad news is that the second partition of a Raspbian install uses a file format that isn't readily supported on OSX without paying for a driver. Regardless of any hack you've heard about, attempting to mount it directly on a Mac will likely result in media or image corruption and I say this from experience.
The good news
Fortunately, Ubuntu does a great job of this and it's free as an operating system. You don't technically have to install it over your hard drive or even to move your partitions around; Ubuntu has a LIVE version in which you simply boot to CD or USB drive. (Make sure that you get the Desktop version.)
Assuming that you're now in an Ubuntu session
Editing directly on the microSD media
- Insert the microSD card into a USB type of adapter
- Insert the USB adapter then into your MacBook
- In many cases, Ubuntu's Desktop version will just auto-mount BOTH partitions for you
- Edit anything you need to either from the Terminal or from the File Manager
- Find the
/etc/hostnamefile and you can find out the name of the Raspi if it had booted
Don't forget to safely eject those partitions and wait for the dialog box informing you that it's now safe to remove it.
Just remember that you're in Ubuntu at the moment and not Raspbian so if you're developing in this operating system, you still need to test things in Raspbian.
Editing directly an IMG file
- If you've copied the
octopi.imgfile, say, from earlier to a USB drive, insert this into the MacBook and it should auto-mount
- Open up a Terminal (Ctrl-Alt-T)
- Look for your own username and
cd meinto that (this is where auto-mount decides to mount things for you)
In my case, I see
- (In my case, I'll just type the first character of that to save typing all that).
And there is your IMG file.
So now, this part gets technical.
CHS (0x0,130,3), end-CHS (0x8,138,2), startsector 8192, 129024 sectors; partition 2 : ID=0x3, start-CHS (0x8,138,3), end-CHS (0x213,120,37), startsector 137216, 8400896 sectors
You're interested in the value after
startsector at the end of all that (not the first time seen): 137216. Multiply this by 512 to get 70254592.
sudo mount octopi.img -o offset=70254592 /mnt
sudo ls /mnt
You should now see the entire set of folders from the root area of that image file (the second partition).
When finished, don't forget to safely eject the mounted system:
sudo umount /mnt
If you do this a lot and you actually have Ubuntu installed, then create a
mnt folder under your home directory and mount it there instead. Then you won't have to use
sudo just to list the files and to work with it.
sudo mount octopi.img -o offset=70254592 ~/mnt
cat ~/mnt/etc/hostname # Didn't have to use sudo this way
sudo umount ~/mnt