How to make a VM of an existing raspberry pi

Discussions about using Linux guests in VirtualBox.
Post Reply
AlexandraYoung
Posts: 1
Joined: 31. Jul 2022, 17:21

How to make a VM of an existing raspberry pi

Post by AlexandraYoung »

I have a micro sd card from a raspberry pi that isn't working for some reason and I want to extract the files from it. However the files can't be properly accessed (at least with my level of expertise) without having it running. I was hoping I could make a VM of the pi from the micro sd card and access the files from there but that has proven to be very difficult.

What I've tried and the error I got/why it didn't work:
  • using dd to turn the micro sd into a .iso | failed to boot
    FATAL: Could not read from the boot medium! System halted.
  • using dd to turn the micro sd partitions into individual .iso files | failed to boot
    FATAL: Could not read from the boot medium! System halted.
  • using dd to turn the micro sd partitions into individual .iso files then mounting the .iso files at the correct locations (msdos boot partition mounted at /boot/, and ext3/ext4 root partition mounted at /) | i can't find a way to edit the mount point of a .iso
  • mounting the original sd card as a usb device | virtualbox does not recognize any availible usb devices even though they're there, probably because I'm using a linux host
  • mounting the whole file system as a shared folder | failed to boot
    FATAL: Could not read from the boot medium! System halted.
  • installing a normal raspian system and shoving in parts of the original file system from there | i could not convert the .img raspian image to .iso
    ccd2iso:
    Unrecognized sector mode (c0) at sector 0!
System info:
Host: x86 | arch linux | virtualbox 6.1.36-1 with extension pack 6.1.36
Guest: Raspberry pi 3b+ | raspian

Does anyone know how to do this? Is it even possible? Thank you!
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to make a VM of an existing raspberry pi

Post by scottgus1 »

I think the simplest thing would be to skip Virtualbox altogether. The Raspbian OS ought to be accessible from a Linux host. You might do better getting some assistance from a Linux or a Raspberry Pi forum to find out how to mount the SD card in the host OS.

I'm not sure if copying files from an SD card into an ISO file necessarily makes the ISO bootable. I think there's more to be done, though I'm not certain what to do.

Additionally, Raspbian from an actual Raspberry Pi is probably an ARM OS, which will not boot on an x86 PC-compatible computer, whether in the host OS or in a VM.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to make a VM of an existing raspberry pi

Post by mpack »

A lot of misunderstandings there. ISO is not a synonym for "raw disk image", it directly refers to the ISO-9660 (and later relative) filesystems found on an optical disk. So while all ISO files are indeed raw disk images, not all raw disk images are ISO files - and giving the file a lying extension will cause confusion, it will not help. Also, just like all disk drives, there are a number of requirements of an image before you can boot from it, not least that boot code has to be present, and both boot code and OS has to be for the right processor. The RPi is ARM based so you obviously won't be able to boot that on an x86 PC (whether or not the PC is also a VM). Another problem is I don't think an RPI sdcard is even bootable in the standalone sense: AIUI the bootloader is in flash on the RPi itself. There will be a secondary (ARM coded) boot on the sdcard tho, designed to be compatible with the RPi bootloader.

Imaging just a partition strips off all boot info so you definitely don't want that.

Basically you need to forget all thought of turning the SDcard into an "ISO" or of getting the ARM based RPi OS to boot on an x86 PC.

You can however image the sdcard and mount the image in a Linux VM that understands the EXT4 filesystem, which I assume is what the sdcard is using. Some PC tools may be able to access an EXT4 image directly. You have a number of options for imaging the card. The normal fallback will be Disk2VHD, but I suspect that will not like a card with an alien filesystem - worth a try though. Another option is to use one of the sd imaging tools popular in the RPi community and create a raw image of the entire sdcard, then clone the raw image using CloneVDI with the compact option set. You can then mount the resulting VDI as a second drive in any Linux VM. I'm hopeful this should work, though it hinges on the RPi bootloader using PC compatible partition schemes.
arQon
Posts: 228
Joined: 1. Jan 2017, 09:16
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Ubuntu 16.04 x64, W7

Re: How to make a VM of an existing raspberry pi

Post by arQon »

In a nutshell, you need an SD card reader on the PC. I use a USB one that cost about $3, which is easily the best option for this.

Once you have that, you can capture the USB device in any Linux VM and treat the card like any other filesystem. In your case, you can just use your host install. (Repairing RPi boot media like this is the only thing I use the adapter for). :)

As mpack says:
mpack wrote:you need to forget all thought of turning the SDcard into an "ISO" or of getting the ARM based RPi OS to boot on an x86 PC.
All you need, and all you *care* about, is being able to read some handful of files from it. That's a hardware problem for you, not a software one.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to make a VM of an existing raspberry pi

Post by mpack »

For completeness I'll add a solution that doesn't help now, but would have helped in the past and may help again in the future. Which is this:

The Raspberry Pi has pretty complete networking support. Meaning that it supports shared folders which can be visible on your home network. Any important files are easily accessed over the network and can be copied to backup storage.

And finally: right now is a bad time to be buying a Raspberry Pi (not available), but of course without something that cheap, if it's doing something important then it pays to have a backup Pi!
Post Reply