# RPI3 migration failure from raspbian-9 to balenaos

**URL:** <https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946>\
**Category:** balenaOS\
**Tags:** raspberrypi3\
**Created:** [October 25, 2019, 11:15am UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946 "2019-10-25T11:15:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [October 25, 2019, 11:15am UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/1 "2019-10-25T11:15:45Z")

</div>

Actually, I have followed the migration instructions in the link below and I have succeeded to migrate amd64/ubuntu16 cards without any troubles. But the problem occurs with rapsbian-9, the process (execution logs) seems to be fine, I have received “migration successful, please reboot system”. After the reboot, nothing changes, it booted to raspbian-9 and not from the modified initramfs.

Migration instructions: [https://github.com/balena-io-playground/balena-migrate](https://github.com/balena-io-playground/balena-migrate).

* * *

These are my steps run inside the RPI3 that i want to migrate :  
1- git clone [https://github.com/balena-io-playground/balena-migrate](https://github.com/balena-io-playground/balena-migrate) && cd balena-migrate/migratecfg  
2- wget [https://files.resin.io/resinos/raspberrypi3/2.43.0%2Brev1.dev/image/balena.img.zip](https://files.resin.io/resinos/raspberrypi3/2.43.0%2Brev1.dev/image/balena.img.zip) # In order to download the balenaos rpi3 image  
3- cp balena-migrate-sample.conf balena-migrate.conf # then updating the IMAGE\_FILE environment variable and setting REQUIRE\_NMGR\_FILE=FALSE  
4- ./balena-migrate  
5- reboot

I appreciate any hint or help.

---

<div class="post-metadata">

**Author:** ![xginn8](https://avatars.discourse-cdn.com/v4/letter/x/8baadc/32.png) [@xginn8](https://forums.balena.io/u/xginn8)\
**Post date:** [October 28, 2019, 2:39pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/3 "2019-10-28T14:39:32Z")

</div>

Hi there and thanks for reaching out!

As you may have already noticed, that repository is slated for deprecation. We should be able to help you migrate the device directly, I have reached out to some folks internally who may be able to help.

Stay tuned, we will reach out again with more information soon!

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [October 31, 2019, 12:07am UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/12 "2019-10-31T00:07:16Z")

</div>

Hey @omarsastec, as my colleague mentioned, that repository is deprecated, and there’s a more recent tool in the works, just not quite there yet.

Still to unblock you, we’ve digged into the issue, and could replicate your problem. With a couple of small changes, we could made it work, see the `quickfix` branch on the tool you used: [https://github.com/balena-io-playground/balena-migrate/tree/quickfix](https://github.com/balena-io-playground/balena-migrate/tree/quickfix)

Then you could basically modify your flow, currently checking out the `quickfix` branch, and use that. Here’s my expanded flow if that helps, hope I haven’t missed anything.

1. `git clone https://github.com/balena-io-playground/balena-migrate && cd balena-migrate/migratecfg && git checkout quickfix` This is while we are checking the changes in the quickfix branch, once that is merged, this last part (the `git checkout ....` will not be needed)
2. `wget https://files.resin.io/resinos/raspberrypi3/2.43.0%2Brev1.dev/image/balena.img.zip` In order to download the balenaos rpi3 image. This is unconfigured image, so will need a `config.json`
3. `unzip balena.img.zip && gzip balena.img`
4. `cp balena-migrate-sample.conf balena-migrate.conf`  
a. then updating the `IMAGE_FILE=balena.img.gz` environment variable  
b. setting `BALENA_CONFIG=config.json` and create that `config.json` file there from one config download from the dashboard (navigate to the target application, “Add Device” \> “Advanced” \> “Download configuration file only”)  
c. setting `REQUIRE_NMGR_FILE=FALSE`  
d. set `NO_FLASH=FALSE` and `NO_SETUP=FALSE` (can also add `DEBUG` and `LOG_...` settings if want to debug further, but not required)
5. run the migrator `sudo ./balena-migrate -c balena-migrate.conf`

This succeeded for me on a Raspbian 9 Stretch & Raspberry Pi 3.

If it works for you, we’ll merge the changes, and no extra checkout will be needed, so would be eager to hear your feedback! And the new tool would be generally ore robust in the future.

---

<div class="post-metadata">

**Author:** ![lucianbuzzo](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/lucianbuzzo/32/615_2.png) [@lucianbuzzo](https://forums.balena.io/u/lucianbuzzo)\
**Post date:** [November 4, 2019, 9:47am UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/16 "2019-11-04T09:47:23Z")

</div>

A PR has been opened that incorporates these changes here [https://github.com/balena-io-playground/balena-migrate/pull/2](https://github.com/balena-io-playground/balena-migrate/pull/2) - please try it out and let us know how it goes.

---

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [November 4, 2019, 10:06am UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/18 "2019-11-04T10:06:36Z")

</div>

Hi there,

Thanks for the replies. I’ll be testing the fixes ASAP and return a feedback according to the result.

Cheers.

---

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [November 4, 2019, 4:19pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/20 "2019-11-04T16:19:38Z")

</div>

Hello,

I confirm that the fixes solved the problem. Feel free to merge the PR.

I’ve got two questions btw:

- What’s the purpose of adding “basename” to INITRAM\_REQUIRED\_PGMS ?
- The sync was added to flush the buffer during the cp ? Means the persisted image was corrupted before the fix ?

Thank you.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [November 4, 2019, 4:46pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/23 "2019-11-04T16:46:54Z")

</div>

Hey @omarsastec, glad that it works for you!

The PR is fixing things up:

- `basename` needs to be added, as the stage2 updater _uses_ it, but if not copied in, that step will be broken
- `sync` is also needed to be added, as after file operations it’s good practice to call `sync`, so that all the changes are written to disk. If not called, the code can operate on half-written data, or move on while changes are not persisted (just kept in memory/buffers). It doesn’t mean data was corrupted, it was just incomplete (moving on too fast).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [November 6, 2019, 1:08pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/26 "2019-11-06T13:08:09Z")

</div>

Hello and thanks for you support,

Actually, during balena-migrate execution, the gzipping process is working fine and a valid backup.tgz was created. The problem occurs after the reboot, the backup.tgz in /mnt/data/ is corrupted for compressed files with a large size.

```
tar -ztvf backup.tgz 
...
...
tar: unexpected end of file
tar: short 

```

I have tried that twice with different content to backup in each time. I noticed that the restored tgz file is truncated in both tries, and with a size of 127M.

I understand that the truncating is related to memory limit . Is there a chance to backup compressed content with size ~ 20 GB ? Any suggestion ? Disk repartition before stage 2 ?

I appreciate your help.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [November 6, 2019, 3:12pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/29 "2019-11-06T15:12:22Z")

</div>

hey @omarsastec, are you trying to transfer ~20GB of data, hence that number you mention?

The amount of data that can be transferred depends on the available device memory, as the hard drive is modified completely in the migration process, thus everything that needs to be transferred have to fit into a limited amount of space.

What sort of thing are you trying to migrate over, if we may ask? Just to understand your use case better. Are these database files, videos, some other large files? Could any of those actually be part of your application data on the balena side? We appreciate any context that you could share.

---

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [November 6, 2019, 3:14pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/32 "2019-11-06T15:14:56Z")

</div>

Hey @imrehg,

The data type is mainly videos, so we can say that gzipping is useless here, and I am restricted from transferring it to an external storage.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [November 6, 2019, 3:22pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/33 "2019-11-06T15:22:40Z")

</div>

Yeah, I would agree that external storage or some other way to transfer the videos are much better in this case. The backup is mostly conceived to provide a way of getting in settings files, or other smaller stuff that are unique to a device.

The tar/gzip’ing is used, as the device is restoring from a single file, that can hold all folder structure and other file metadata, the compression is sort of secondary aspect, anyways.

---

<div class="post-metadata">

**Author:** ![omarsastec](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@omarsastec](https://forums.balena.io/u/omarsastec)\
**Post date:** [November 6, 2019, 3:42pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/35 "2019-11-06T15:42:52Z")

</div>

Like i have already mentioned, transferring data to an external storage isn’t yet an option.  
Isn’t it possible to ensure partial disk repartition ? Means before proceeding to stage 2, we create a partition that holds backup data, then we proceed by installing balena in the left space.

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [November 6, 2019, 4:00pm UTC](https://forums.balena.io/t/rpi3-migration-failure-from-raspbian-9-to-balenaos/39946/36 "2019-11-06T16:00:53Z")

</div>

Hi again,

Unfortunately, as mentioned, this is a deprecated project and we don’t support partial repartitioning. As Greg says, balenaOS expects to be installed on an entire media device, as it also dynamically reconfigures the remaining partition space at first boot. Because of this, any changes to the same media node being used to install balenaOS on will be destroyed.

Currently I believe your only option is to store this backup data on an external media node.

Best regards,

Heds
