I would like to collect information here how to migrate the system from the standard module to A311D.
Especially if the current system uses encrypted NVMe storage, I hope there is a procedure to retain all files on the rootfs while being able to boot the A311D.
I assume that the A311D on RCM4 comes with a system image preinstalled. I would then also assume, that it will boot to that image as it is not aware of the NVMe installation. Therefore, the boot partition contents must be configured to boot from NVMe, which will likely involve recreating a initramfs and boot.scr. But what must I do to accomplish this in the right way.
Actual commands would be much appreciated
Hi, I think the âcollection of informationâ is done: Migrating encrypted NVMe to different SoM (imx8mq to a311d)
I think the next step to improve upon the experience would be to write up a script that does the migration. Would you want to be my figurative guinea pig to try out such a migration script if i were to write one?
That would be possible once I got my hands on the BPi4 + adapter. Though this could take a while according to the posted delivery time.
I can be a guinea pig. I was already planning on moving the a311d from my big reform to my pocket when my rcore arrives.
Okay, so this is a preliminary guide on how to migrate from one SoM to another, assuming that you have used reform-setup-encrypted-nvme
to set up your nvme drive with luks and lvm2. If you have a different setup, you have to adjust the assumptions that this guide makes accordingly. What we essentially are trying to do is to create a new /boot
partition which is able to load the encrypted rootfs. That /boot
partition can be placed on the sd-card or emmc, which depends on the SoM you are migrating to.
- before taking out your original SoM, make sure that your system is fully upgraded. Use
apt update && apt full-upgrade
to do this. - if a new kernel version got installed, reboot into that new kernel
- clean your apt cache with
sudo apt clean
- make sure that your apt cache contains the latest kernel image package by running this:
sudo apt-get --download-only install linux-image-$(uname -r)
- download and flash the latest rescue system for your new SoM to your sd-card or usb-stick
- take out your old SoM and install the new SoM
- insert the sd-card or usb-stick with your rescue system and boot your system and once in there, execute the following script as root:
#!/bin/sh
set -eu
umount /boot
cryptsetup luksOpen /dev/nvme0n1 reform_crypt
vgchange -ay reformvg
mount /dev/mapper/reformvg-root /mnt
DEV_MMC="$(sh -c '. /mnt/usr/share/reform-tools/machines"/$(cat /proc/device-tree/model).conf"; echo $DEV_MMC')"
mount "/dev/${DEV_MMC}p1" /mnt/boot/
mount -o bind /dev /mnt/dev/
mount -t sysfs sys /mnt/sys/
mount -t proc proc /mnt/proc/
chroot /mnt sh -c 'apt-get install --reinstall /var/cache/apt/archives/linux-image-*_arm64.deb'
umount /mnt --recursive
reform-boot-config --emmc /dev/reformvg/root
vgchange -an reformvg
cryptsetup luksClose reform_crypt
Above script will first populate the first partition on emmc with the kernel image, initrd and device tree from your system on nvme and then run reform-boot-config
to configure the initramfs in that /boot
partition to load the correct root filesystem and set up mount points in /etc/fstab
accordingly. If you do not want to or cannot have your /boot
on emmc, adjust above steps by replacing $DEV_MMC
with $DEV_SD
and remove the --emmc
argument from reform-boot-config
.
So this both worked and didnât work for me, but I also had some issues with reform-setup-encrypted-nvme
when I first setup my drive and had done some stuff manually.
This DEV_MMC="$(sh -c '. /mnt/usr/share/reform-tools/machines"/$(cat /proc/device-tree/model).conf"; echo $DEV_MMC')"
did not seem to pull the right information so mount /dev/${DEV_MMC}p1" /mnt/boot/
did not work properly. I ended up hardcoding it to mount /dev/mmcblk1p1 /mnt/boot/
which got me past that part.
I also had errors with this line `chroot /mnt sh -c âapt-get install --reinstall /var/cache/apt/archives/linux-image-*_arm64.debâ. I think it just didnât find an image to fetch. I commented out as I was already up to date.
My final issue was with reform-boot-config --emmc /dev/reformvg/root
. Error pops up saying -emmc doesnât work on A311d. I just deleted the --emmc part. It was mad that the fstab on the NVME drive wasnât pointing to a valid boot partition because it was set to â/dev/mmcblk2p1â which I guess was the location of the boot partition on emmc for the imx8 board. Changed that to â/dev/mmcblk1p1â and script completed, and encrypted drive was intact.
I did manually edit crypttab and fstab during initial setup so my issues might be related to that.
Would you like to invest the time so that we can get to the bottom of these issues and fix them in the tooling?
The file /usr/share/reform-tools/machines/MNT Pocket Reform with BPI-CM4 Module.conf
should contain the line DEV_MMC="mmcblk1"
. If it does, then I do not understand how DEV_MMC
could be set to the wrong value. Can you reproduce the problem?
Running this command is not about the package being up to date. It is and it has to be. Because it is, the command contains the --reinstall
switch. The point of running that command is to fill the /boot
partition with the kernel image and initramfs.
That is correct. Using the eMMC on A311D incorrectly can soft-brick your board and you need some additional hardware to unbrick it. This is why the tooling currently forbids writing to it.
If you do that, it will configure your /boot
on the SD-card instead.
Finally I got my A311D module an also could not get past the DEV_MMC=
line. The eMMC on A311D seems to be read only. Would it be possible to put boot on NVMe? Using the SD card for boot is not quite ideal.
Technically, the eMMC on A311D is not read-only at all. It is a normal block device as far as linux is concerned. MNT only decided that tools like reform-flash-rescue or reform-flash-uboot should refuse operating on eMMC in case of A311D. But if you feel like being adventurous, then nothing stops you from either removing these safety measures from the scripts or do the things they do manually.
It is possible to put /boot
on NVMe if u-boot is able to read from it. In July, this got merged: NVMe Boot Support (!3) ¡ Merge requests ¡ Reform / reform-a311d-uboot ¡ GitLab So it might work to flash u-boot 2024-08-01 onto your eMMC and have it read /boot
from NVMe. But if you go down that route, please be aware, that you can soft-brick your board. Maybe wait for some guidance from MNT before you do this. Personally, I have /boot
on eMMC but my u-boot is still on my SD-card. That way I donât risk soft-bricking my A311D and after linux has loaded, I can remove the SD-card and get the slot back and can use it to load pictures from my camera or some such.
Can you explain what kinds of things would lead to the soft-bricking youâre describing?
The A311D first tries to load u-boot from eMMC and only then tries to load it from SD-card. So if your u-boot on eMMC is somehow broken, then you cannot boot your system and if you cannot boot your system, how do you repair u-boot on eMMC?
Got it. What kind of hardware would someone need to get out of such a situation, do you know?
Youâd either need a Compute Module 4 IO Board or this as the cheaper option:
Cute hack Iâll make one before I upgrade to uboot from emmc
I believe this needs --reinstall to actually download it; compare
$ sudo apt-get --download-only install linux-image-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-image-6.10.9-mnt-reform-arm64 is already the newest version (6.10.9-1+reform20240916T143123Z).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ sudo apt-get --reinstall --download-only install linux-image-$(uname -r)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 68.3 MB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 https://mntre.com/reform-debian-repo reform/main arm64 linux-image-6.10.9-mnt-reform-arm64 arm64 6.10.9-1+reform20240916T143123Z [68.3 MB]
Fetched 68.3 MB in 25s (2,717 kB/s)
Download complete and in download only mode
I suspect this is why @hardcoreufo got the following issue
I followed @joschâs instructions (modulo adding --reinstall), booted into the a311d SOM, and attempted to run @josch 's script. I added set -x to the script so I could see what was happening. Hereâs what I got
root@reform:~# ./a311d.sh
+ umount /boot
+ cryptsetup luksOpen /dev/nvme0n1 reform_crypt
Enter passphrase for /dev/nvme0n1:
+ vgchange -ay reformvg
File descriptor 17 (/root/.cache/mesa_shader_cache_db/part0/mesa_cache.db) leaked on vgchange invocation. Parent PID 1259: /bin/sh
[There are 200 of these, all in /root/.cache/mesa_shader_cache_db/. Redacted because it seems inconsequential]
2 logical volume(s) in volume group "reformvg" now active
+ mount /dev/mapper/reformvg-root /mnt
+ sh -c . /mnt/usr/share/reform-tools/machines"/$(cat /proc/device-tree/model).conf"; echo $DEV_MMC
+ DEV_MMC=mmcblk1
+ mount /dev/mmcblk1p1 /mnt/boot/
mount: /mnt/boot: fsconfig system call failed: /dev/mmcblk1p1: Can't lookup blockdev.
dmesg(1) may have more information after failed mount system call.
I suspect the issue is that /dev/mmcblk1 isnât partitioned:
root@reform:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
mmcblk0 179:0 0 29.7G 0 disk
ââmmcblk0p1 179:1 0 488M 0 part
ââmmcblk0p2 179:2 0 29.2G 0 part /
nvme0n1 259:0 0 931.5G 0 disk
ââreform_crypt 254:0 0 931.5G 0 crypt
ââreformvg-swap 254:1 0 8G 0 lvm
ââreformvg-root 254:2 0 923.5G 0 lvm /mnt
mmcblk1 179:256 0 14.6G 0 disk
mmcblk1boot0 179:512 0 4M 1 disk
mmcblk1boot1 179:768 0 4M 1 disk
Shall I try to partition it? Is there a particular way I should partition it to leave room for u-boot, if I would like to put u-boot on emmc at some point in the future?
Is there an illustration like this for a311d somewhere? Curious what all the ribbon connectors on the a311d module are for
Edit: found this! https://mntre.com/documentation/reform-rcm4-bpi-bundle-manual.pdf
Yes. I wish I could edit my original post to fix this issue but alas the edit button is somehow missing.
@minute do you know why this is? I already observed this issue on other posts of mine and it makes it hard to keep my posts up to date and correct if sometimes the edit button decides to vanish.
A very simple partitioning scheme with an msdos partition table and two primary partitions will suffice. Make the boot partition around 500 MB large. You do not need to take care of having room for u-boot because on eMMC there is a special section to flash u-boot to. Thatâs what you see as mmcblk1boot0
and mmcblk1boot1
(the backup) in your output above.
Another way to partition your eMMC is to run reform-flash-rescue
but on A311D you have to edit the script so that it allow you to run it even though you are on A311D. If you know how to, manually partitioning eMMC to your liking is probably easier.
Thank you for all the help!
Do you know what the logic is for using the backup? Or where I can find more info about this?
It depends. Vendors can configure this and I donât think it is (yet) configured in a way for MNT supported boards as I am used to from other devices with eMMC I own. But generally, you have those two boot0 and boot1 partitions which contain u-boot and to make sure that flashing u-boot does not soft-brick your device in case you have a sudden power loss or any other issue, you first flash u-boot to one of the two and then run a command like mmc bootpart enable ...
to only enable this partition after you verified that flashing u-boot to it was successful. If it wasnât, for example in case you had a sudden power loss, your system would still boot from the other and you can attempt flashing again.
Iâve successfully migrated from imx8 to a311d on my pocket reform, after already having migrated to encrypted nvme. Hereâs a full sequence of how I did it, based on @joschâs instructions above. Take care with these instructions, itâs possible to get into a situation that may require another computer and some clever thinking to undo.
- Before taking out your original SoM, make sure that your system is fully upgraded.
- If a new kernel version got installed, reboot into that new kernel
- Clean your apt cache with
sudo apt clean
- Make sure that your apt cache contains the latest kernel image package by running this:
sudo apt-get --reinstall --download-only install linux-image-$(uname -r)
- Download and flash the latest rescue system for a311d to your sd-card. Find the latest pocket-reform-system-a311d.img.gz at https://mnt.re/system-image, flash it following the instructions in section 6.3 in the manual.
- You may want to mount one of the partitions of the sd card and paste the contents of this message into a text file there, so you can read it while youâre booted into that system easily.
- Power off, take out the old SOM and install the a311d SOM. For now, you can attach the antenna cable to the antenna connector closest to the a311d chip; thatâs the wifi antenna connector.
- Boot. Hopefully you get a screen with a snowy wallpaper, and then the MNT setup wizard. Click the x in the top right corner to exit, and then type HYPER+Return to open a shell.
- First, you want to partition and format the new boot partition on emmc (assuming yours isnât already partitioned; note that this will effectively wipe the emmc on the SOM). Hereâs what I ran:
sfdisk /dev/mmcblk1 <<EOF
size=1048576, type=83
type=83
EOF
mkfs.ext4 /dev/mmcblk1p1
- Run the following steps to mount the nvme root partition at /mnt, with the new emmc boot partition at /mnt/boot. Pay attention to the output of each to make sure itâs all working!
umount /boot
cryptsetup luksOpen /dev/nvme0n1 reform_crypt
vgchange -ay reformvg
mount /dev/mapper/reformvg-root /mnt
mount "/dev/mmcblk1p1" /mnt/boot/
mount -o bind /dev /mnt/dev/
mount -t sysfs sys /mnt/sys/
mount -t proc proc /mnt/proc/
- chroot into that mountpoint to reinstall the kernel package you made sure to download earlier. This will generate a new image and populate the new boot partition:
chroot /mnt sh -c 'apt-get install --reinstall /var/cache/apt/archives/linux-image-*_arm64.deb'
- Edit /mnt/etc/fstab while youâre here, since the imx8 device names donât match the a311d ones. Note that youâll need to undo this if you ever want to switch back to imx8. Change
/dev/mmcblk2p1 /boot auto errors=remount-ro 0 1
to
/dev/mmcblk1p1 /boot auto errors=remount-ro 0 1
- Unmount it all:
umount /mnt --recursive
- Edit
reform-boot-config
to allow you to find /boot on emmc. I added this line right after the point where it sources the machine conf, near line 30:
EMMC_USE=true
Then run it:
reform-boot-config --emmc /dev/reformvg/root
- Unmount everything:
vgchange -an reformvg
cryptsetup luksClose reform_crypt
- At this point, the boot partition on the a311d emmc is valid, but uboot (still on the sd card) will prefer to mount the boot partition from the sd card. You can work around this by moving boot.scr:
mount /dev/mmcblk0p1 /boot
mv /boot/boot.scr /boot/boot.scr.back
If you ever need to boot to recovery again, you can slot this sd card into another device and move boot.scr.back to boot.scr.
- Reboot. You should get the disk encryption passphrase prompt. Note that at this point uboot is still on the sd card, and youâll need to keep it in to boot.