Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Classic very old grub kernel & initramfs
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Sat Feb 10, 2024 1:04 am    Post subject: Classic very old grub kernel & initramfs Reply with quote

BACKGROUND:

I've been running gentoo for 20 years, and I have always built my kernels the old fashioned way, but I haven't built a kernel in several years now, and I am trying to clean up my Lenovo Thinkpad W530. Since I need to keep the old system running for my paying work, I bought a new SSD and just popped the old SSD out and put the new one in, so I would always have a bootable backup by swapping the disks back to the original SSD. So I started with an empyt disk.

I use LVM directly on the SSD without any partition table at all. I boot the system with a USB drive I carry on my keychain in my pocket, so the USB drive is like my ignition key for my laptop. The main SSD is LUKS encrypted as the entire disk -- remember, no partition table.

The USB boot drive has an init script that first mounts /proc and /sys, then runs cryptsetup luksOpen to ask for the pass phrase to decrypt the SSD. Next, it runs vgscan and vgchange to get LVM going, and then mounts what will eventually be root on /mnt/root.

Finally, it unmounts /proc and /sys and does the switch_root to make the system on the SSD appear at / and runs /sbin/init to start the full blown gentoo system.

THE PROBLEM:

I have built my kernel, but I can't remember where make menuconfig puts the resulting kernel, and the handbook now omits that information because everything has been automated by config-kernel or kernel-config and by making things so automatic and easy, so I need to know where the compiled kernel image lies after running make to build the kernel. I guess I could look into the Makefile and figure it out, but I thought I would ask first.

Also, to boot into a LUKS encrypted LVM managed disk, I need an initrd/initramfs. As it now stands, I have an initramfs directory that holds everything I need, and I have foggy memories of having to tar and gzip the initramfs directory and then having to use cpio to combine the kernel image with the initramsf.tar.gz file. Then I copy this resulting file to my /boot drive (the USB stick), and edit the /boot/grub/grub.conf file to tell grub which kernel to boot.

I would prefer to do all this manually again, the good old fashioned way, but the handbook thinks evrybody wants automatic transmission and driver assist, while I still prefer to shift my own gears and be the only one working the controls. I do understand that newer users expect everything to be one click of the mouse easy, like ubunto, but when you are doing custom stuff, which is gentoo's strength, fully manual is more versatile, and educates you on the details so you can more easily troubleshoot problems.

THE REQUEST

Can someone tell me how to setup up my nice shiny new linux-6.6.13-gentoo kernel so I can boot it with my boot stick?

I need to know where the built kernel resides after doing the make in /usr/src/linux to build it.

I need to know how to package my initramfs directory into a combined kernel and initramfs.

I can take it from there.

Please excuse the long post, but I am trying to explain the situation I am in.

Here is my initramfs directory:

Code:

  /usr/src/initramfs:
  drwxr-xr-x 12 root root 146 Feb 12  2019 .
  drwxr-xr-x  5 root root  90 Feb  9 14:53 ..
  drwxr-xr-x  2 root root  63 Jan 30  2010 bin
  drwxr-xr-x  2 root root  59 Feb 10  2019 dev
  drwxr-xr-x  2 root root   6 Jan 30  2010 etc
  -rwxr-xr-x  1 root root 824 Feb 12  2019 init
  -rwxr-xr-x  1 root root 823 Feb 11  2019 init~
  drwxr-xr-x  2 root root 214 Jan 30  2010 lib
  drwxr-xr-x  2 root root  34 Jan 30  2010 lib64
  drwxr-xr-x  3 root root  18 Jan 30  2010 mnt
  drwxr-xr-x  2 root root   6 Jan 30  2010 proc
  drwxr-xr-x  2 root root   6 Jan 30  2010 root
  drwxr-xr-x  2 root root   6 Jan 30  2010 sbin
  drwxr-xr-x  2 root root   6 Jan 30  2010 sys


And here is the init file in the initramfs directory:

Code:

#!/bin/busybox sh

rescue_shell() {
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

echo Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys

echo doing luksOpen
cryptsetup luksOpen /dev/sda cryptoroot || rescue_shell "cryptsetup failed"
echo after luksOpen
#sleep 10

echo doing vgscan
lvm vgscan  || rescue_shell "vgscan failed"

echo doing vgchange
lvm vgchange -a y  || rescue_shell "vgchange failed"

echo mounting root
mount /dev/gentoo/rootfs /mnt/root  || rescue_shell "mount root failed"

echo unmounting /proc and /sys
umount /proc
umount /sys

echo doing the pivot root
exec switch_root /mnt/root /sbin/init

# if we get here, it means trouble!  :-(
echo "starting emergency rescue shell..."
rescue_shell()



I started doing initrd's back when the nash shell was how you did it...
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Sat Feb 10, 2024 2:10 am    Post subject: Reply with quote

The kernel has supported make install, without the aid of any fancy supporting packages, for a long time. I expect that make -n V=1 install would show you the commands it would run (V=1) and not do them (-n), so that you can see where it would copy the files from. Alternatively, you could set INSTALL_PATH and INSTALL_MOD_PATH to cause make install to write to a temporary area of your choosing, after which you could copy the files to the directory representing your USB stick.

As regards building the initramfs, my preference has always been to use the kernel's built-in support for composing an initramfs (CONFIG_INITRAMFS_SOURCE), which also embeds it into the resulting kernel image. This makes the image a bit bigger and is less space efficient, since every kernel has a copy of the initramfs, even if you never change it. On the other hand, since it is built into the kernel, the bootloader does not need to be informed of the initramfs, which simplifies configuring the bootloader.
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Sat Feb 10, 2024 3:20 am    Post subject: Reply with quote

Thanks Hu! Its just been so long since I built a kernel for this laptop that I forgot the details of packaging the initramfs and the kernel into a single file. This is the first kernel I have built for this box in 5 years. :(

The USB boot stick has 32 GB, so no problem with the wasted space.

I am finished playing with the new kernel build for today; I gotta do some work with the old SSD to earn some money. :wink:
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sat Feb 10, 2024 9:41 am    Post subject: Reply with quote

Moriah,

Be warned that if you have a separate /usr filesystem, the initrd must mount it just after root is mounted.
That's not new news but the breaking implementation is new this week.

My box didn't boot this morning after an update yesterday but I knew that this was coming so I had the initrd already prepared and on the boot menu.

Consider
Code:
# lddtree /bin/mount
/bin/mount (interpreter => /lib64/ld-linux-x86-64.so.2)
    libmount.so.1 => /usr/lib64/libmount.so.1
        libblkid.so.1 => /usr/lib64/libblkid.so.1
    libc.so.6 => /lib64/libc.so.6

The mount command depends on /usr/lib64/*, so localmount will fail if /usr is not already mounted.
_________________
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
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 13, 2024 12:00 am    Post subject: Reply with quote

I think I have found where the make leaves the kernel imags. Is it in /usr/src/linux/x86/boot/bzImage ?

So where do I find documentation on using CONFIG_INITRAMFS_SOURCE to combine the initramfs with the kernel? My initramfsdirectory is in /usr/src/initramfs. Do I need to manually cpio it and then gzip it and leave the resume somewhere, of does CONFIG_INITRAMFS_SOURCE just contain /usr/src/initramfs like so:

Code:
 CONFIG_INITRAMFS_SOURCE=/usr/src/initramfs Make


I am assuming that CONFIG_INITRAMFS_SOURCE is a shell environment symbol that the Makefile looks at, but its only my uneducated guess.

And finally, where does all this leave the resulting file that contains the kernel and the initramfs?
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4158
Location: Bavaria

PostPosted: Tue Feb 13, 2024 12:49 am    Post subject: Reply with quote

Moriah wrote:
I think I have found where the make leaves the kernel imags. Is it in /usr/src/linux/x86/boot/bzImage ?

Yes.

Moriah wrote:
So where do I find documentation on using CONFIG_INITRAMFS_SOURCE to combine the initramfs with the kernel?

Here: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Initramfs_Overview
You have 4 (5) options to build your own initramfs (... manually; if not using genkernel or dracut) ;-)

Moriah wrote:
And finally, where does all this leave the resulting file that contains the kernel and the initramfs?

Sorry, I dont understand the question. If you use an embedded initramfs then it is "IN" the kernel (not quite correct; exactly: It is in the file "bzImage" as a part). If you build an external initramfs (as CPIO archive) you choose yourself where it will be stored ... and you have put it yourself into correct directorys (depending if you boot with UEFI or with a bootmanager).


( I am using only an embedded initramfs with a signed, hardened, monolitihic stub kernel which will be booted by UEFI directly:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Boot_kernel_via_UEFI )
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 13, 2024 1:49 am    Post subject: Reply with quote

So:
Quote:

Embedded with a directory

1. Copy your init AND all files you need into a directory you like. In most articles here in our wiki /usr/src/initramfs is used.

2. Configure your kernel with:
KERNEL

General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
(/usr/src/initramfs/) Initramfs source file(s)
[*] Support initial ramdisk/ramfs compressed using gzip
Built-in initramfs compression mode (Gzip) --->

( You see the difference in "Initramfs source file(s)", do you ? )

3. Build your kernel with "make" and install it - as you always do.


I see now why I missed it; the setting to use a compressed initramfs image built right into the kernel is done inside the kernel configuration! I was looking for a tool or a command line using cpio or something. I have the /usr/src/initramfs directory ready to go and I thought I had to manually use cpio and gzip to prepare it, and then some unknown other tool to combine it with the kernel. It seems to me that is what we used to have to do a long time ago...

OK, I'll try that tomorrow afternoon, when I get a chance to work on it again.

Thanks! :D
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 13, 2024 10:20 pm    Post subject: Reply with quote

OK, I tried it today. Guess what? The settings to combine the initramfs at /usr/src/initramfs with the kernel were already there! They are now apparently the default. So that means I had already built the kernel with the initramfs incorporated into it. 8)

But it doesn't boot. It doesn't even get as far as trying to run the init script in my initramfs, at least not as far as I can see.

The kernel panics, but the screen won't hold enough for me to understand exactly where it was when it paniced.

I have copied the output of dmesg to the file at: http://www.elilabs.com/~rj/w530_dmesg.txt

A copy of the screen when the panic kills everythin is at: http://www.elilabs.com/~rj/w520_boot_fail.jpg

The last line of the panic screen says "Attempt to kill init"
the last line of the dmesg says "XFS (dm-1): Ending clean mount"

So my root filesystem did get mounted, but somehow the init script in my initramfs failed to get executed. My initramfs is shown earlier in this thread.

Since I haven't built a kernel in several years, I am very rusty at this. Can someone suggest what might be causing my problem?
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4158
Location: Bavaria

PostPosted: Tue Feb 13, 2024 11:20 pm    Post subject: Reply with quote

I guess you are using outdated binaries and libraries in your /usr/portage/initramfs (in your first post I see directory dates from 2010 ...)

You must provide every binary you use in your directory structure AND every library; you find out with "ldd" or "lddtree". Your first binary - cryptsetup - you start needs (I have amd64 stable) for example:
Code:
# lddtree /sbin/cryptsetup
cryptsetup => /sbin/cryptsetup (interpreter => /lib64/ld-linux-x86-64.so.2)
    libcryptsetup.so.12 => /usr/lib64/libcryptsetup.so.12
        libdevmapper.so.1.02 => /lib64/libdevmapper.so.1.02
            libudev.so.1 => /lib64/libudev.so.1
                libcap.so.2 => /lib64/libcap.so.2
                ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
            libm.so.6 => /lib64/libm.so.6
        libssl.so.3 => /usr/lib64/libssl.so.3
        libcrypto.so.3 => /usr/lib64/libcrypto.so.3
        libargon2.so.1 => /usr/lib64/libargon2.so.1
        libjson-c.so.5 => /usr/lib64/libjson-c.so.5
    libpopt.so.0 => /usr/lib64/libpopt.so.0
    libuuid.so.1 => /lib64/libuuid.so.1
    libblkid.so.1 => /lib64/libblkid.so.1
    libc.so.6 => /lib64/libc.so.6

Now this must be done for every binary you want start with "init". Dont forget busybox itself ;-)

BTW: Also this doesnt look like healthy (I assume it is sda; sdb seems to be fine):
Code:
[    3.857871] GPT:Primary header thinks Alt. header is not at the end of the disk.
[    3.857876] GPT:955739 != 60549119
[    3.857879] GPT:Alternate GPT header not at the end of the disk.
[    3.857881] GPT:955739 != 60549119
[    3.857883] GPT: Use GNU Parted to correct GPT errors.

_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Wed Feb 14, 2024 4:07 am    Post subject: Reply with quote

All the executables used by my initramfs are static linked and in the initramfs, so no dependencies to worry about there.

The weird messages about /dev/sda are because the disk is not partitioned and uses LVM directly on the raw disk, and it is fully whole disk LUKS encrypted. The main reason for the initramfs is to enable LVM and to run cryptsetup luksOpen and then mount the root filesystem, then chroot to it. This is the same initramfs I have used for years; it booted the disk I am running now to answer this post.

I suspect that the initramfs init script has not yet started to run, but I can check that by putting some sleeps in the script to slow things down so I can watch it. I will try that tomorrow and post here what happens.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4158
Location: Bavaria

PostPosted: Wed Feb 14, 2024 2:14 pm    Post subject: Reply with quote

To be on a safe side with device nodes you might do something we have in every modern init: Automounting of device nodes in /dev/*

If you use Gentoo Sources this is usually already enabled:
Code:
Device Drivers  --->
    Generic Driver Options  --->
        -*- Maintain a devtmpfs filesystem to mount at /dev

and THEN you can add one line into your "init": mount -t devtmpfs none /dev || rescue_shell "mount /devtmpfs failed"

This is the beginning of my "init":
Code:
#!/bin/busybox sh

[...]

abend() {
    echo "$@"
    echo "You are now in a rescue shell."
    busybox --install -s
    exec /bin/sh
}

echo "Mounting proc, sys, devtmpfs and securityfs ..."
mount -t devtmpfs none /dev || abend "Error: mount /devtmpfs failed !"
mount -t proc none /proc || abend "Error: mount /proc failed !"
mount -t sysfs none /sys || abend "Error: mount /sysfs failed !"
mount -t securityfs securityfs /sys/kernel/security || abend "Error: mount /sys/kernel/securityfs failed !"
[...]

Of course you will need always these in your /usr/src/initramfs/dev/ (independent if you use devtmpfs or not)
Code:
cp --archive /dev/{null,console,tty} /usr/src/initramfs/dev/

_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Thu Feb 15, 2024 1:13 am    Post subject: Reply with quote

It has nothing to do with the initramfs. The new kernel is panicking before it gets that far.

I am placing the .config for my old 4.14.83-gentoo system in:
Code:
http://www.elilabs.com/~rj/config-4.14.83-gentoo_bt

and the .config for my new 6.6.13-gentoo sysem in:
Code:
http://www.elilabs.com/~rj/config-6.6.13-gentoo


please take a look and see if you can determine what I messed up. :(

These 2 configs are really quite different...
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4158
Location: Bavaria

PostPosted: Thu Feb 15, 2024 2:51 am    Post subject: Reply with quote

It is not possible to proof if a kernel configuration fits to a machine, without knowing the machine ... or VM where it runs.

(our Wiki is not a great Help for your https://wiki.gentoo.org/wiki/Lenovo_Thinkpad_W530 )

Do you boot a GPT or MBR disk (CSM mode in BIOS enabled or disabled?) ? Do you use a bootmanager (which?) or UEFI to boot the kernel ? Output of "lsmod", "lspci -nnk" AND "dmesg" after booting with our GentooAdminCD (or LiveCD) ?

What I can say: You will get no output on your terminal because of missing FrameBuffer and FBConsole:
Code:
# CONFIG_FB is not set

See more here: https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_Configuring_Kernel_Version_6.6#Part_3_-_Must_Haves

I guess you run an Intel Machine (or in a VM?) because of DRM settings ... Because it is a Notebook you miss:
Code:
# CONFIG_X86_INTEL_LPSS is not set

and maybe more (LPSS*, IRQ_REMAP could be important also, ...):
Code:
# CONFIG_PINCTRL is not set

CONFIG_DRM_I915=y
CONFIG_DRM_VIRTIO_GPU=y

# CONFIG_I2C_HID_ACPI is not set

# CONFIG_IRQ_REMAP is not set

I would like to refer you to my article on this subject:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_Configuring_Kernel_Version_6.6

Maybe it is wise to start with a clean/new configuration; see more here:
https://wiki.gentoo.org/wiki/User:Pietinger/Tutorials/Manual_kernel_configuration

Back to your Kernel Panic:

You might use these additional kernel command line parameters to see more: initcall_debug ignore_loglevel earlycon=efifb

The last one works only if CONFIG_SERIAL_8250_CONSOLE=y (you have) AND if using a EFI system and efifb is enabled; see above MUST HAVE.
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 20, 2024 2:56 am    Post subject: Reply with quote

I have the disk containing the old system for my lenovo thinkpad w530 laptop. It boots and runs, but it is so out of date that it is unmaintainable. In particular, I have the old .config file for the 4.14.83-gentoo kernel that it currently is running.

Code:

rj@onesimus ~ $ uname -a
Linux onesimus 4.14.83-gentoo #39 SMP PREEMPT Thu Feb 28 14:40:05 EST 2019 x86_64 Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz GenuineIntel GNU/Linux
rj@onesimus ~ $


Would it be hoping for too much to expect makeoldconfig, or one of its variants, to be at all useful in generating a starting point for a new config for a 6.1.67-gentoo kernel? Or is there too much of a gap between what I have running now and what I want to move to?

I had previously thought that the two kernels were so separated in time that makeoldconfig would be useless. Maybe I was too pessimistic. This old kernel supports wifi, bluetooth, and the nouveau driver for my nvidia video chipset.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 4158
Location: Bavaria

PostPosted: Tue Feb 20, 2024 3:31 am    Post subject: Reply with quote

Moriah wrote:
Would it be hoping for too much to expect makeoldconfig, or one of its variants, to be at all useful in generating a starting point for a new config for a 6.1.67-gentoo kernel?

I must admit I thought you configured the new kernel with "make oldconfig". I don't know how big the gap is between 4.14 and 6.6 - theoretically it should work. So I would definitely give it a try. (If it doesn't work, there is still the possibility to go from 4.14 to e.g. 5.10 (stable) or 5.15 (stable) as an intermediate step).

Were you able to recognize where the kernel paniced ?
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 20, 2024 3:46 am    Post subject: Reply with quote

I had thought of "incrementally" increasing the kernel version uising makeoldconfig myself.

Regarding the kernel panic, no I haven't had much time to work on it the past few days. I had a big wedding to attend Saturday, and Sunday was filled with church and Monday was tied up with working on cabinetry in the laundry room. Seems a bit strange for woodworking to interfere with kernel building, but my wife is growing impatient waiting for the construction in the house to get finished. :?

Also, I keep having to interrupt kernel building (and a complete re-installation of gentoo in general ) on my laptop by re-installing the old disk so I can boot it and get some real work done. I get maybe 2 or 3 hours to tinker on the new system, then I have to switch back to the old disk.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Tue Feb 20, 2024 1:10 pm    Post subject: Reply with quote

Can your hardware support booting off an external drive? That might let you keep the working drive in the system, but boot into the new disk when you have time to work on this.
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 20, 2024 1:32 pm    Post subject: Reply with quote

Its not the time to swap disks that is the issue, its the loss of context on the running old system. I can swap the physical disk in a couple of minutes. Its the loss of all the context in the running old system when I shut it down and then later reboor it. One of the things I want to experimenrt with once the new system si working is using lxd coontainers like a slimmed down vm and saving and restoring the lxd container context across reboots. I used to do that with vm's back in the day by saving the state of a vmware vm. Then I could shut down the laptop, take it with me somewhere, then rebooty the laptop and restore the context of the vm. Voila! All my previously running windows, etc. are right back up just like the machine never got shut down.

Since I use whole disk LUKS encryption (and I boot from a usb stick on my keychain in my pocket) and hibernate function requires saving context on the disk, it won't work if the disk is fully encrypted, and worse yet, the encryption key is saved in the preserved memory image of the running system.

And to make it even worse, when I work on the new disk in the laptop, since the system is still in the unbootable beginning stages, I prefer to boot it with a live usb stick and then get networking running and connect via ssh from another system. But we are in the middle of moving from one location to another (5 minutes away), and my laptop is with me in the new location, but the rest of my machines and my network are still in the old location. So I have to drive the car to the old location to get on another machine to work on the new system disk.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Tue Feb 20, 2024 2:47 pm    Post subject: Reply with quote

Understood. Hibernation can work with an encrypted disk, though the standard advice in that case is that you should hibernate to encrypted swap, so that the filesystem device's encryption key is protected by the encryption of the swap device. I understand you may consider that insufficiently secure, and want to avoid it. For what it is worth, I have worked jobs where the IT security policy required an encrypted swap, encrypted filesystem device (ext4 inside LUKS on a partition), but permitted hibernating to that encrypted swap device. That was considered "secure enough" for the IT department.
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Tue Feb 20, 2024 2:53 pm    Post subject: Reply with quote

Well my laptop's old system runs 32 gb ram with no swap at all. I have configured my new disk for that laptop to have 64 gb of swap, and since the whole disk is LUKS encrypted and then LVM is used instead of partitioning, my swap is also encrypted. I am anticipating getting a new laptop, probably either a dell or another lenovo, with 128 gb ecc ram to support a kubernetes development environment. I will need it to handle kvm, lxd, docker, and kubernetes with ewnough room for multiple vm's that look like separate machines to kubernetes so clustered container configurations can be prototyped all on the laptop.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Wed Feb 21, 2024 12:46 am    Post subject: Reply with quote

You have to resolve that kernel panic first. Can you boot with init=/bin/sh, or modify your /init script to check /proc/cmdline and optionally give you a rescue shell ? If the kernel hasn't panicked yet you can look around and see what's wrong. (Just run a shell, don't exec one by calling rescue_shell.)

-----------------
If you get the kernel to work,
Moriah wrote:
Well my laptop's old system runs 32 gb ram with no swap at all. I have configured my new disk for that laptop to have 64 gb of swap, and since the whole disk is LUKS encrypted and then LVM is used instead of partitioning, my swap is also encrypted.
Then you are all set to hibernate to and resume from encrypted swap if you so choose.

In your /init script,
Code:
echo doing vgchange
lvm vgchange -a y  || rescue_shell "vgchange failed"

# THIS IS WHERE YOU TRY TO RESUME

echo mounting root
mount /dev/gentoo/rootfs /mnt/root  || rescue_shell "mount root failed"
To resume, you echo your swap device's major:minor numbers to /sys/power/resume. If there is a hibernation image, it is loaded and control is transferred to the suspended kernel. Otherwise, your /init continues and finishes booting. You can hard-code the major/minor in your script or, better, determine it dynamically. In my case, this would work:
Code:
ls -Ll /dev/vg0/swap |awk '{print $5,$6}' | sed -e 's/, /:/' > /sys/power/resume
I'm guessing would write ls -Ll /dev/gentoo/swap (I don't know what names you used for your swap logical volume).

Quote:
I am anticipating getting a new laptop, probably either a dell or another lenovo, with 128 gb ecc ram to support a kubernetes development environment. I will need it to handle kvm, lxd, docker, and kubernetes with ewnough room for multiple vm's that look like separate machines to kubernetes so clustered container configurations can be prototyped all on the laptop.
The hibernation image is smaller than RAM, so a 128 GB swap would allow you to hibernate. Resuming from swap would be faster than booting and restoring VM's one by one.

Hibernation to encrypted swap protects your data at rest. It doesn't help with the "evil maid" attack or if your laptop is stolen and returned (but I don't know what does). Also there is some risk if your laptop is taken from you while running, but that's probably true of your original setup.
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Wed Feb 21, 2024 3:19 am    Post subject: Reply with quote

I haven't used hibernation in a long time. Is it still possible to hibernate to a swap device that is under LVM on a LUKS encrypted SSD? As i said in an earlier post, I boot from a usb stick that loads the kernel and runs an init script that accepts the LUKS pass phrase, then decrypts the disk, activates LVN, and then does the pivot root to run on the decrypted LUKS managed disk. The LUKS/LVM disk is not partitioned, it runs LVM directly on the decrypted disk image.

Also, could my init script ask whether I what to resume from hibrenation, and possible bypass that step if wanted a fresh boot instead?

Evil maid is not generally a concern because the maid won't have my boot usb stick or my LUKS pass phrase, so she won't be able to boot the box or make sense of the disk if she steals an image of it.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Thu Feb 22, 2024 2:13 am    Post subject: Reply with quote

Moriah wrote:
I haven't used hibernation in a long time. Is it still possible to hibernate to a swap device that is under LVM on a LUKS encrypted SSD?
All I can say is that I hibernate to a swap that is under LVM on a LUKS encrypted HDD partition. Pretty close. An LVM logical volume is perfectly usable as a swap+hibernate device.

Quote:
As i said in an earlier post, I boot from a usb stick that loads the kernel and runs an init script that accepts the LUKS pass phrase, then decrypts the disk, activates LVN, and then does the pivot root to run on the decrypted LUKS managed disk. The LUKS/LVM disk is not partitioned, it runs LVM directly on the decrypted disk image.
Just attempt to resume after you have your logical volumes and BEFORE you mount the root partition. See my post 8816945 above.

Quote:
Also, could my init script ask whether I what to resume from hibrenation, and possible bypass that step if wanted a fresh boot instead?
Absolutely. A fresh boot of a hibernated machine will trigger an fsck, but with journaled filesystems it's quick and pretty safe. Parse /proc/cmdline and conditionally skip the attempt to resume. For example, genkernel uses noresume for that purpose. It's your script, you decide how the command line works; make it easy to parse.

Quote:
Evil maid is not generally a concern because the maid won't have my boot usb stick or my LUKS pass phrase, so she won't be able to boot the box or make sense of the disk if she steals an image of it.
Without your USB stick the evil maid can't modify the kernel, can't modify the initramfs; could still install a hardware keylogger though.
Back to top
View user's profile Send private message
1shot1kill
n00b
n00b


Joined: 09 Feb 2006
Posts: 17
Location: Akron, Ohio

PostPosted: Fri Feb 23, 2024 1:51 am    Post subject: Reply with quote

Maybe I am not fully understanding this fully. But they way I am understanding this is that the boot drive is USB and then mounts an encrypted LUKSFS.

Why not run sys-kernel/gentoo-kernel-bin that supports LUKS and everything else. Yes its over kill in a lot of regards, but it will get you up and running and then you can pull your .config from your old drive to the new one and go from there.

Also why not just use UUID's to mount your LUKS device off your USB stick?

Again I might be miss understanding your needs/layout
Back to top
View user's profile Send private message
Moriah
Advocate
Advocate


Joined: 27 Mar 2004
Posts: 2365
Location: Kentucky

PostPosted: Sat Feb 24, 2024 2:22 am    Post subject: Reply with quote

@1shot1kill:
Quote:
Why not run sys-kernel/gentoo-kernel-bin that supports LUKS and everything else.


You can't mount / without being able to read the mount executable. I use the initramfs to activate LVM and to mount the / filesystem so it is there when I do the switch_root command then and start running the /sbin/init executable.

If I were running an md RAID array that had / on it, which I do on some servers, then I would also need to activate the RAID array with mdadmin before mounting /, then I could do the switch_root.

AT ANY RATE: I successfully built the 5.15.32-gentoo-r1 kernel and booted it on my old disk, the one that was previously running the 4.14.83-gentoo kernel. It booted on the first attempt but had no ethernet devices. 8O

I instantly realized I had forgotten to install the kernel dirver after compiling the kernel. :oops:

So a quick reboot to the old 4.14.83 kernel to install those drivers in the 5.15.32 and copy the result to /boot and then reboot. Viola! It worked. Now I have ethernet devices. I tried a few things and determined that wifi support was working, bluetopoth support was working, and teh nouveau X driver was working.

The way I built the 5.15.32 kernel was to copy the .config from the 4.14.83 kernel into the new linux directory and do a make oldconfig, followed by a make menuconfig to verify that things looked sane. I then did a make to compile the new kernel, and after I installed the modules, it just worked. :D

So I was following the suggestion made earlier to incrementally upgrade from the version 4 kernel to the version 6 kernel by using the version 5 kernel as a stepping stone, and to do it all with make oldconfig.

Tomorrow, or early next week at least, I will copy the .config from the version 5 kernel into the version 6 kernel and point linux to it, then compile the version 6 kernel and install the modules and see if it boots.

If all that works, then I will use make menuconfig to make surwe I have all the options set to support kvm, lvm, docker, and kubernetes, then rebuild the linux-6.6.13-gentoo kernel aghain and boot it. If all goes well, I will be ready to install the new kernel onto the new disk where everything has been prepared from an empty disk. If that disk also boots, then I will need to copy my user files across and probably emerge a bunch of stuff that was already on my old disk. This should give me a nice clean system to work with.
_________________
The MyWord KJV Bible tool is at http://www.elilabs.com/~myword

Foghorn Leghorn is a Warner Bros. cartoon character.
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
Goto page 1, 2  Next
Page 1 of 2

 
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