raidoo9
Posts: 4
Joined: Sat Apr 25, 2020 2:17 pm

Putting a file in Pi user home directory before install/initial boot.

Sat Apr 25, 2020 2:27 pm

Hi,

I am looking for a way to put a file onto my SD card after flashing it with the Raspbian image, so it appears in the Pi user home directory on initial boot.

Is this possible?

Thanks

deepo
Posts: 574
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 10:17 am

Maybe have a look at this thread:
viewtopic.php?f=63&t=265248&p=1612640

User avatar
kerry_s
Posts: 741
Joined: Thu Jan 30, 2020 7:14 pm

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 11:01 am

i been thinking about something like that, but never got around to testing it.
my idea was to put the files/folder on the sdcard(/boot) & then add something to /etc/xdg/autostart to run a script to copy/move whatever to where I wanted to.

just a thought

User avatar
kerry_s
Posts: 741
Joined: Thu Jan 30, 2020 7:14 pm

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 11:17 am

sorry, i was on my tablet.
so let me explain.
autostart uses the desktop files format.

example /etc/xdg/autostart/copy-to.desktop

Code: Select all

[Desktop Entry]
Type=Application
Exec=cp /boot/file /home/pi/Desktop/
something like that, in theory should work.

User avatar
thagrol
Posts: 2961
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 11:18 am

raidoo9 wrote:
Sat Apr 25, 2020 2:27 pm
Hi,

I am looking for a way to put a file onto my SD card after flashing it with the Raspbian image, so it appears in the Pi user home directory on initial boot.

Is this possible?

Thanks
Yes, but it depends on which operating system you're using to flash the SD card.

Linux: just mount the relevant partition of the SD card.
Windows: you'll need to find and install software that can read & write ext4 partitions. Once you have that open the SD card partition the same way you would any other USB drive.
MacOS: no idea. Don't have a Mac.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

User avatar
kerry_s
Posts: 741
Joined: Thu Jan 30, 2020 7:14 pm

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 11:28 am

just thinking a little more, you might want to run a script instead, cause you'd want to delete it after first run, so it's not running at every boot.
:?: :?

hippy
Posts: 7459
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 5:39 pm

This inquiry crops up enough times that I believe it would be worth implementing some official mechanism which allows it to be done, expanding on the way by which SSH is set-up to make that a more general purpose mechanism.

Just being able to drop stuff in a 'setup' directory in the FAT formatted partition and have those files copied elsewhere and/or executed upon first boot would be a godsend.

Not sure to whom or where such a request would need to be directed to have it brought about.

User avatar
HawaiianPi
Posts: 5711
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 5:48 pm

If this is something you want to do on lots of cards, you can embed your file in a Raspbian image before writing.

STICKY: Making your own custom burn-n-boot Raspbian image.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
procount
Posts: 2209
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 5:55 pm

PiBakery did this. I know it has not been maintained in a while so I don't know if it still works with the latest Buster, but worth a look.

If you want to install your OS with PINN, you can make use of it's flavours to install any files you want AFTER the OS has been installed but BEFORE it is first booted. See https://github.com/procount/pinn/blob/m ... sconfig.md
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
Botspot
Posts: 1241
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 10:32 pm

If you want to edit an .IMG file (before flashing it to a SD card) - have a look at Pi Power Tools. It's a GUI bash script that runs on Raspberry Pi, and lets you customize your own Raspbian IMG file.
img-mode.png
img-mode.png (21.47 KiB) Viewed 277 times
(In your case you would want to push the View button to mount the IMG file. After that, file manager will open and let you change stuff)

All feedback is welcome! :D
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

User avatar
thagrol
Posts: 2961
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Putting a file in Pi user home directory before install/initial boot.

Sun Apr 26, 2020 11:24 pm

Botspot wrote:
Sun Apr 26, 2020 10:32 pm
If you want to edit an .IMG file (before flashing it to a SD card) - have a look at Pi Power Tools. It's a GUI bash script that runs on Raspberry Pi, and lets you customize your own Raspbian IMG file.

[...]

All feedback is welcome! :D
Isn't that a bit chicken and egg?* In order to customise an image you first have to witre one to an SD card? And don't forget you can't write the modified image back to the SD card you're running from.

Not to denegrate your work, but to use it you'd either need two SD cards or you'd need to faff around with USB or network storage and another computer.

*: as in which came first, the chicken or the egg?
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

User avatar
Botspot
Posts: 1241
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: Putting a file in Pi user home directory before install/initial boot.

Mon Apr 27, 2020 12:36 am

thagrol wrote:
Sun Apr 26, 2020 11:24 pm
Botspot wrote:
Sun Apr 26, 2020 10:32 pm
If you want to edit an .IMG file (before flashing it to a SD card) - have a look at Pi Power Tools. It's a GUI bash script that runs on Raspberry Pi, and lets you customize your own Raspbian IMG file.
In order to customise an image you first have to witre one to an SD card? And don't forget you can't write the modified image back to the SD card you're running from.
If the OP wants to do this for a lot of cards, HawaiianPi's answer applies as well as my answer. But if not, then I'm sure these answers will help others who were thought to google it.
Last edited by Botspot on Thu Apr 30, 2020 4:52 pm, edited 1 time in total.
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

raidoo9
Posts: 4
Joined: Sat Apr 25, 2020 2:17 pm

Re: Putting a file in Pi user home directory before install/initial boot.

Thu Apr 30, 2020 4:51 pm

Thanks for all the replies. Looks like there are a couple of good options here, been a bit busy to try during the week but i'll have a look this weekend.

Return to “Beginners”