Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Exotic custom initramfs.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Unb0rn
n00b
n00b


Joined: 12 Jun 2012
Posts: 63

PostPosted: Thu Nov 03, 2016 5:45 pm    Post subject: Exotic custom initramfs. Reply with quote

Hello everyone! First of all, I don't mean to insult someone, but I really need more than just an advice =)
I am trying to install Gentoo on Lenovo Yoga 3 Pro with EFI Stub booting, while placing my system on a single btrfs partition with subvolumes on top of lvm2 (swap and btrfs root here), which, in turn is "on top" of LUKS-encrypted partition(which uses encrypted keyfile along with bootable efi kernel on the external USB flash).
I was following THIS guide, it basicly covers all the stuff I need, but without btrfs and manual initramfs installation.
At the moment I have partitioned my drive, copied stage3, re-bootstrapped system(as it was recommended in the guide), made all the edits in config files(as per guide and handbook), successfully re-emerged @world and built bootable bootx64.efi kernel, the only problem so far-Sakaki(author of the guide mentioned above) uses his own build script to build kernel with generic settings, and he uses it to build and embed initramfs into the kernel itself.
The problem is-Sakaki uses simple ext4 partitioning scheme, while I am using btrfs.

At the moment I've compiled static versions of gpg(1.4, without pinentry), bash and btrfs-progs. And... I am stuck-

1)Is it possible to dismantle bootx64.efi kernel to extract cpio with initramfs?(I am using LZ4 compression for the kernel itself and no compression for initramfs as it's mentioned in EFIStub article)
Maybe I could get better understanding from it's init...

2)Is there anyone who uses similar setup who can share init from initramfs(I have very basic understanding of bash scripting, so inits from btrfs articles(even without lvm and cryptsetup) are making me cry)-
-Boot process according to the Sakaki's guide should be something like this (using usb key with bootx64.efi and luks-key.gpg,-initramfs should ask for password to luks-key.gpg, after that rootfs should be mounted using /dev/mapper(and btrfs-progs, I suppose)

3)Any additional advices?

If it helps, I am using amd64-nomultilib configuration with USE="dri gtk systemd udev wayland X" flags.
Partitioning scheme is so:
/dev/sda6 is a whole crypto_LUKS partition

/dev/mapper/gentoo is a LVM Physical Volume on top of LUKS
vg1 is a Volume Group hosting this PV
It has two logical volumes:
/dev/mapper/vg1-swap is a swap partition and
/dev/mapper/vg1-btroot is a btrfs root partition

Btrfs has two subvolumes:
btroot/activeroot (I wanted it to be a rootfs)
btroot/activeroot/home (It is self-explaining, "/home" inside "/")
I was trying to learn myself this way, but it got too complicated and now I really need some help... Tried to build some understanding from Gentoo wiki articles like "Native BTRFS root" and "Custom Initramfs", still I don't get how to build such an "exotic" initramfs...
Thanks!
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1746

PostPosted: Thu Nov 03, 2016 9:20 pm    Post subject: Reply with quote

Quote:
1)Is it possible to dismantle bootx64.efi kernel to extract cpio with initramfs?
Yes. AFAIR it's simply appended at th end of kernel's image, so you can simply split it out once you know the correct position. You can try to find it based on magic numbers defining filetype. Hint: initramfs is a cpio archive.
Quote:
2)Is there anyone who uses similar setup who can share init from initramfs
You can use genkernel to build initramfs and then extract it and have a look. It will not be the perfect fit for your purpose, and aiming at automation and flexibility it's much more complex than you need, but you may only need to change a few lines inside to make it work the way you want.
Quote:

3)Any additional advices?
Do it yourself. Initramfs is organized the very same way any linux is.
Run
emerge --root=<some custom subdirectory> --deps=rdeps
to build baselayout, busybox, libc (usually glibc, though you can use another one to get smaller binaries if you feel like cross-compiling it), and add stuff you need at boot. Most likely you don't need udev, but you will need tools for lvm and btrfs
Write your tricky stuff to /init (remember to mount /proc first, then /dev and /sys, and then do whatever you wanted to start with)
Remember that syntax used by busybox is simplified compared to bash, so avoid fancy expressions.
Once you have the very very minimal system ready, pack it with cpio (and optionally gzip it) and you're set.
Tip: Start using /bin/sh here and there across the init script. Dropping to shell will let you look around and think what has to be done next. when you have the whole sequence figured out, you can remove those "debug" lines.
Back to top
View user's profile Send private message
Unb0rn
n00b
n00b


Joined: 12 Jun 2012
Posts: 63

PostPosted: Sat Nov 05, 2016 5:16 pm    Post subject: Reply with quote

szatox wrote:
Quote:
1)Is it possible to dismantle bootx64.efi kernel to extract cpio with initramfs?
Yes. AFAIR it's simply appended at th end of kernel's image, so you can simply split it out once you know the correct position. You can try to find it based on magic numbers defining filetype. Hint: initramfs is a cpio archive.
Quote:
2)Is there anyone who uses similar setup who can share init from initramfs
You can use genkernel to build initramfs and then extract it and have a look. It will not be the perfect fit for your purpose, and aiming at automation and flexibility it's much more complex than you need, but you may only need to change a few lines inside to make it work the way you want.
Quote:

3)Any additional advices?
Do it yourself. Initramfs is organized the very same way any linux is.
Run
emerge --root=<some custom subdirectory> --deps=rdeps
to build baselayout, busybox, libc (usually glibc, though you can use another one to get smaller binaries if you feel like cross-compiling it), and add stuff you need at boot. Most likely you don't need udev, but you will need tools for lvm and btrfs
Write your tricky stuff to /init (remember to mount /proc first, then /dev and /sys, and then do whatever you wanted to start with)
Remember that syntax used by busybox is simplified compared to bash, so avoid fancy expressions.
Once you have the very very minimal system ready, pack it with cpio (and optionally gzip it) and you're set.
Tip: Start using /bin/sh here and there across the init script. Dropping to shell will let you look around and think what has to be done next. when you have the whole sequence figured out, you can remove those "debug" lines.


Thank you! Trying to make everything "the right way" now, with parsing kernel cmdline and so on... However, the part with compiling static binaries adds some questions. First, after building everything inside /tmp/initramfs should I unmerge or cleanup some way, or removing dir itself is enough? Second, running USE="static static-libs nettle -gcrypt" emerge --root=/tmp/initramfs --root-deps=rdeps sys-fs/cryptsetup fails with dependency conflict for systemd, should I exclude systemd flag for initramfs, or it has to be set to boot systemd from initramfs?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43198
Location: 56N 3W

PostPosted: Sat Nov 05, 2016 5:27 pm    Post subject: Reply with quote

Unb0rn,

Don't get too hung up about static builds.
It used to be the way but if you include all the libraries that lddtree shows you need, dynamically linked code in the initrd works too.
e.g.
Code:
$ sudo lddtree /bin/mount
/bin/mount (interpreter => /lib64/ld-linux-x86-64.so.2)
    libmount.so.1 => /lib64/libmount.so.1
        libblkid.so.1 => /lib64/libblkid.so.1
            libuuid.so.1 => /lib64/libuuid.so.1
        librt.so.1 => /lib64/librt.so.1
            libpthread.so.0 => /lib64/libpthread.so.0
    libc.so.6 => /lib64/libc.so.6

so /bin/mount, in the initrd needs all of those libs too.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1746

PostPosted: Sat Nov 05, 2016 10:12 pm    Post subject: Reply with quote

Quote:
First, after building everything inside /tmp/initramfs should I unmerge or cleanup some way, or removing dir itself is enough?
/tmp is wiped on every boot. If you want to get rid of it sooner, just uninstall french language pack ( rm -fr :lol: )
Quote:
Should I exclude systemd flag for initramfs, or it has to be set to boot systemd from initramfs?

Yes, you don't need systemd in initramfs. Actually I tend to start clean and then enable flags as I find out I really need them. For my holy trinity of bl/bb/glc it would be:
USE="-* build make-symlinks" emerge --root=(...)
Then emerge whatever you need on top of that. Disabling all flags first will help you reduce the total size - less stuff demanded -> less dependencies -> less stuff included. You're not going to actively use it anyway, so it doesn't have to look pretty.

Oh, make sure you have /dev/null and /dev/console inside your initramfs. Nothing works without those. Really.
Back to top
View user's profile Send private message
Unb0rn
n00b
n00b


Joined: 12 Jun 2012
Posts: 63

PostPosted: Sun Nov 06, 2016 4:33 pm    Post subject: Reply with quote

szatox wrote:
Quote:
First, after building everything inside /tmp/initramfs should I unmerge or cleanup some way, or removing dir itself is enough?
/tmp is wiped on every boot. If you want to get rid of it sooner, just uninstall french language pack ( rm -fr :lol: )
Quote:
Should I exclude systemd flag for initramfs, or it has to be set to boot systemd from initramfs?

Yes, you don't need systemd in initramfs. Actually I tend to start clean and then enable flags as I find out I really need them. For my holy trinity of bl/bb/glc it would be:
USE="-* build make-symlinks" emerge --root=(...)
Then emerge whatever you need on top of that. Disabling all flags first will help you reduce the total size - less stuff demanded -> less dependencies -> less stuff included. You're not going to actively use it anyway, so it doesn't have to look pretty.

Oh, make sure you have /dev/null and /dev/console inside your initramfs. Nothing works without those. Really.


Great! Thanks! And one more thing, it looks like while building lvm2 with "static" and "static-libs" USE flags an arror occurs, "/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/bin/ld cammot find -lblkid and the same -luuid".I've also emerged util-linux to /tmp/initramfs, but it didn't help-according to error it looks like it searches for blkid in wrong dir or something? Any way to fix it?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13848

PostPosted: Sun Nov 06, 2016 5:56 pm    Post subject: Reply with quote

Please post the exact output of the failure and the output of emerge --pretend --verbose sys-apps/util-linux sys-fs/lvm2.
Back to top
View user's profile Send private message
Unb0rn
n00b
n00b


Joined: 12 Jun 2012
Posts: 63

PostPosted: Sun Nov 06, 2016 6:18 pm    Post subject: Reply with quote

Hu wrote:
Please post the exact output of the failure and the output of emerge --pretend --verbose sys-apps/util-linux sys-fs/lvm2.

Of course! Full build log:Here
About "--pretend --verbose" should I add --root and --root-deps which I am using to build everything in temp dir?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13848

PostPosted: Sun Nov 06, 2016 7:00 pm    Post subject: Reply with quote

You should not pass --root, since I want to see the options used by the packages to which lvm2 will link. It links to your host system packages, not the ones in the temporary directory. I suspect that the output will show that you have not set USE=static-libs on the package that provides blkid and uuid. Is there a reason you need to build all of this statically?
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1746

PostPosted: Sun Nov 06, 2016 7:15 pm    Post subject: Reply with quote

Just don't use static on lvm2. It's not needed.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum