Folder consists of various python files and sub-folders to bootable image file

I am looking to convert a folder containing subfolders and Python files that perform specific tasks into a bootable image file to be saved directly on an SD card. I plan to copy the file to my Windows computer and use Etcher. This will enable me to flash the SD card and run the Python script on another BeagleBone. Can someone help me with this conversion process?

scp or rsync with recursive copy should work

I’ve used the below code, it did create an .img file but when i falshed to sd card using Etcher and tried to boot another beaglebone black, it didn’t work. Not sure what the issue is. I’ve insetered SD card and creating image file directly there as I don’t have enough of space in BB-black:

Check Current Mount Points:
df -h

Unmount the Partition:
Unmount /dev/mmcblk0p1 from /mnt/sdcard if it is already mounted:
sudo umount /mnt/sdcard

Mount the Partition Again:
Mount the partition again to ensure it’s properly mounted:
sudo mount /dev/mmcblk0p1 /mnt/sdcard

After ensuring the SD card is correctly mounted, proceeding with copying the root filesystem and setting up the auto-start for your Python script:

Copy the Root Filesystem
sudo rsync -aAXv / /mnt/sdcard --exclude=/mnt/sdcard --exclude=/proc --exclude=/tmp --exclude=/sys --exclude=/dev/pts --exclude=/run

Set Up Auto-Start for Your Python Script
Using rc.local
sudo nano /mnt/sdcard/etc/rc.local

Add the following line before exit 0:
ln -s /etc/systemd/system/digital.service /etc/systemd/system/multi-user.target.wants/digital.service
/usr/bin/python3 /home/debian/digital.py &

Using systemd
sudo nano /mnt/sdcard/etc/systemd/system/digital.service

Add the following content:

[Unit]
Description=Run Digital Python Script

[Service]
ExecStart=/usr/bin/python3 /home/debian/digital.py

[Install]
WantedBy=multi-user.target

Modify rc.local to Create the Symbolic Link on Boot
Open the rc.local file on the SD card:
sudo nano /mnt/sdcard/etc/rc.local

Enable the service:
sudo ln -s /mnt/sdcard/etc/systemd/system/digital.service /mnt/sdcard/etc/systemd/system/multi-user.target.wants/digital.service

Finally, unmount the SD card and create an image file from it:
sudo umount /mnt/sdcard
sudo dd if=/dev/mmcblk0 of=/home/debian/sdcard_image.img bs=4M

I was trying to create an image file directly on the SD card as I don’t have enough space on my Beaglebone.

Lets see if I have this correct - you want to copy the files from your BBB to an sd card so that you can run another BBB from this card. Is that correct?

You can use the bbb flasher tool (sorry I dont recall it’s exact name) or, since you seem comfortable with dd, you can just use that.
dd if=/dev/mmcblkX of=/dev/mmcblkY bs=4M
where /dev/mmcblkX is the onboard mmc, and mmcblkY is the sd card. Change X and Y as appropriate.

This will flash the sd card with an exact copy of your running system. Once this is done then you will need to edit the /etc/systemd and /etc/rc.local files according to your requirements in your previous post.

Just to be clear - the *.img file is just a packaged representation of your sd card, for convenience - you dont put that on the card directly if you want to boot from the card.
If you want an *.img file that can be flashed later, then you cannot do this directly on the BBB if, as you stated, you dont have enough space. You will need another computer with an sd reader - insert the sd card you want to copy, then use the dd command (if linux) from your previous post to create the .img file. If using windows use some other utility (etcher?) to copy the card.

Hope this helps, let me know if anything’s not clear.

I’ve used the below code, it did create an .img file but when i falshed to sd card using Etcher and tried to boot another beaglebone black, it didn’t work. Not sure what the issue is. I’ve insetered SD card and creating image file directly there as I don’t have enough of space in BB-black:

Check Current Mount Points:
df -h

Unmount the Partition:
Unmount /dev/mmcblk0p1 from /mnt/sdcard if it is already mounted:
sudo umount /mnt/sdcard

Mount the Partition Again:
Mount the partition again to ensure it’s properly mounted:
sudo mount /dev/mmcblk0p1 /mnt/sdcard

After ensuring the SD card is correctly mounted, proceeding with copying the root filesystem and setting up the auto-start for your Python script:

Copy the Root Filesystem
sudo rsync -aAXv / /mnt/sdcard --exclude=/mnt/sdcard --exclude=/proc --exclude=/tmp --exclude=/sys --exclude=/dev/pts --exclude=/run

Set Up Auto-Start for Your Python Script
Using rc.local
sudo nano /mnt/sdcard/etc/rc.local

Add the following line before exit 0:
ln -s /etc/systemd/system/digital.service /etc/systemd/system/multi-user.target.wants/digital.service
/usr/bin/python3 /home/debian/digital.py &

Using systemd
sudo nano /mnt/sdcard/etc/systemd/system/digital.service

Add the following content:

[Unit]
Description=Run Digital Python Script

[Service]
ExecStart=/usr/bin/python3 /home/debian/digital.py

[Install]
WantedBy=multi-user.target

Modify rc.local to Create the Symbolic Link on Boot
Open the rc.local file on the SD card:
sudo nano /mnt/sdcard/etc/rc.local

Enable the service:
sudo ln -s /mnt/sdcard/etc/systemd/system/digital.service /mnt/sdcard/etc/systemd/system/multi-user.target.wants/digital.service

Finally, unmount the SD card and create an image file from it:
sudo umount /mnt/sdcard
sudo dd if=/dev/mmcblk0 of=/home/debian/sdcard_image.img bs=4M

I was trying to create an image file directly on the SD card as I don’t have enough space on my Beaglebone.

from your original post, it sounded like you just wanted to copy a folder and it’s sub directories containing python scripts.
now it looks like you want to make a copy of the sdcard and place it on another sdcard.

making a copy of an sdcard my or may not fit on the next sdcard of same size, even within the same brand.
if your goal is to make a copy of the sdcard and then copy it to another sdcard.
first make the copy, then mount the image with loopback and use gparted to shrink the last partition by a 1/2 Gig or so. this should eliminate the issue with fitting on the next sdcard.
if the last partition is almost full, then shrinking it most likely will cause issues.