_Mark_
Posts: 99
Joined: Sun Jun 02, 2013 8:04 am

Prepare a Rasbian image using chroot

Wed Jun 28, 2017 7:55 pm

Hello,
before reinvent the wheel I wonder if there is a guide to do the following.
I want to create a custom image of Rasbian Jessie Lite with these features:
  • the customization should be on a dev machine using chroot, not on the RPi itself. This because I want to keep track of all the changes and to keep the image as small as possible
  • ro filesystem
  • a script that prepare the sd-card at the first boot as follow: create a new partition that fills all the available space
I should be able to do all this stuff, but it will require a lot of effort to discover all the caveats for each point. Does anyone know a tutorial for this?

I guess it's a common request for an embedded environment.

User avatar
topguy
Posts: 5685
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Prepare a Rasbian image using chroot

Thu Jun 29, 2017 1:19 pm

the customization should be on a dev machine using chroot, not on the RPi itself.
You still would have to do this on A Raspberry Pi, you cant use chroot into a filesystem with binaries from a different architecture.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5880
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Prepare a Rasbian image using chroot

Thu Jun 29, 2017 2:05 pm

Read "Appendix: chrooting into target file systems" here:
https://wiki.debian.org/QemuUserEmulation

_Mark_
Posts: 99
Joined: Sun Jun 02, 2013 8:04 am

Re: Prepare a Rasbian image using chroot

Sat Jul 01, 2017 2:43 pm

I already chrooted the Raspberry image from my desktop pc! Why you say it's not possible?
Anyway, I was looking for any ready-to-use guides, because I thought it's a common usage of Raspbian image: I can't imagine how to customize the image for each unit if you have dozens to prepare.

User avatar
topguy
Posts: 5685
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Prepare a Rasbian image using chroot

Sat Jul 01, 2017 5:51 pm

_Mark_ wrote:Why you say it's not possible?
Then we are not talking about the same thing.

_Mark_
Posts: 99
Joined: Sun Jun 02, 2013 8:04 am

Re: Prepare a Rasbian image using chroot

Sun Jul 02, 2017 9:09 am

I'm saying I chroot the img of Raspbian to customize it before burn the sd card, from my desktop pc. Something like this:
  • sudo mount -o loop,offset=$((137216*512)) 2016-05-27-raspbian-jessie-lite.img /mnt/rasp-pi-rootfs
  • sudo cp /usr/bin/qemu-arm-static /mnt/rasp-pi-rootfs/usr/bin/
  • sudo mount --rbind /dev /mnt/rasp-pi-rootfs/dev
  • sudo mount -t proc none /mnt/rasp-pi-rootfs/proc
  • sudo mount -o bind /sys /mnt/rasp-pi-rootfs/sys
  • sudo chroot /mnt/rasp-pi-rootfs

User avatar
topguy
Posts: 5685
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Prepare a Rasbian image using chroot

Sun Jul 02, 2017 11:32 am

You didnt mention Qemu in your first post so I had trouble seeing how you would do anything useful after the"chroot" command.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5880
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Prepare a Rasbian image using chroot

Sun Jul 02, 2017 2:06 pm

Instead of worrying about the /proc, /dev and /sys mountpoints, you can also use systemd-nspawn instead of chroot. That will set everything up for you and clean up afterwards.

_Mark_
Posts: 99
Joined: Sun Jun 02, 2013 8:04 am

Re: Prepare a Rasbian image using chroot

Sun Jul 02, 2017 2:26 pm

I didn't know systemd-nspawn! It's great and works fine, thanks for the hint!

Return to “Advanced users”