Skip to content

Instantly share code, notes, and snippets.

@brysonian
Created February 24, 2017 08:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brysonian/958d760ff5e8c7aecc45d17c4a92b1c7 to your computer and use it in GitHub Desktop.
Save brysonian/958d760ff5e8c7aecc45d17c4a92b1c7 to your computer and use it in GitHub Desktop.
Mounting Raspberry Pi Drive via Vagrant

#Mounting Raspberry Pi Drive via Vagrant

Install Vagrant

Find instructions here Vagrant. Probably not a bad idea to run the getting started and make sure it works.

Identify your USB device

With your pi drive mounted (e.g. via a microsd reader) run VBoxManage list usbhost. This will print a list of UDB devices available to VirtualBox. Look for one that matches your device, this will probably have a manufacturer name of "Generic". Once you find it, note the VendorId and ProductId.

Configure Your Vagrant Project

Make a new directory and run vagrant init. This will create a Vagrantfile. Open this in a text editor and replace everything with this:

Vagrant.configure("2") do |config|
  config.vm.box = 'precise64'
  config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
  config.vm.provider :virtualbox do |vb|
    vb.customize ['modifyvm', :id, '--usb', 'on']
    vb.customize ['usbfilter', 'add', '0',
      '--target', :id,
      '--name', 'PiImage',
      '--vendorid', '0x05e3',
      '--productid', '0x0736']
  end
end

Replace the vendorid and productid values with the ones you found in the last step.

Start the Vagrant Box

Run vagrant up to start the project.

Connect to the Vagrant Project and Mount the Drive

Once the machine is up, run vagrant ssh and you will ssh into the virtual machine. To mount the device I recommend using pmount. You can install it by running sudo apt-get install pmount. Once pmount is installed you need to find where your USB drive is so you can mount it. Run sudo fdisk -l to get a listing of all disks. Look for one that matches, it will probably look something like:

Disk /dev/sdb: 32.0 GB, 32010928128 bytes
64 heads, 32 sectors/track, 30528 cylinders, total 62521344 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: 0x0cf63fa8

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192      131071       61440    c  W95 FAT32 (LBA)
/dev/sdb2          131072    62521343    31195136   83  Linux

In this case the device I want is at /dev/sdb2. Now mount the drive by running pmount /dev/sdb2. This will mount the drive in /media in this case it would be /media/sdb2. From there you can cd into that directory and access the full filesystem.

Once you are done unmount the device using pumount /dev/sdb2 where "/dev/sdb2" is the name of your device.

Copying Files to the Drive

If you want to copy files to and from the drive you can use the /vagrant directory which is mapped to the directory your vagrant project was run from. Any files you add to that dir you can then find in /vagrant and copy to and from as you usually would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment