LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 01-14-2018, 07:52 PM   #1
jr_bob_dobbs
Member
 
Registered: Mar 2009
Distribution: Bedrock, Devuan, Slackware, Linux From Scratch, Void
Posts: 651
Blog Entries: 135

Rep: Reputation: 188Reputation: 188
initrd for booting from an LVM on an encrypted partition


So for my 8.0 system I was lazy and just used betterinitramfs to boot from my LUKS LVM system. For my 8.1 system I wanted to see if I could do it differently, using tools within BLFS. This has been done before, as evidenced by threads like this one:

https://www.linuxquestions.org/quest...es-4175603530/

Browsing through the 8.1 BLFS book, I saw that it has full instructions for doing this, including two scripts to copy and paste. One to make the initrd, the other to act as the init within the initrd. Cool!

The book says that this script will not handle encrypted partitions, but I found that it was not difficult to add that capability. I got it to work. My 8.1 system boots fine. One shortcut I took to make things easier on myself: all the crypt, lvm, USB and HID stuff needed to boot was compiled into the kernel, not as modules.

diff from the book's init.in to mine:
Code:
2c2,4
< 
---
> # This gets copied in to be the initrd's "init" script
> # They put it in /usr/share/mkinitramfs/
> # we'll put it in /etc/lfs_initramfs/
77a80
>     enc_root=*  ) enc_root=${param#enc_root=}     ;;
94a98
> # start up udev daemon
98a103,108
> # Open the encrypted partiton enc_root. It will
> # become /dev/mapper/waffles. Do this *before*
> # any lvm operations!
> /sbin/cryptsetup luksOpen $enc_root waffles
> 
> # mdadm appears to deal with RAID devices
99a110
> # become aware of available lvm volumes, activate them
107a119
>
Mostly what I added was comments to myself. I added the "enc_root" parameter. One has to pass that from the boot loader to kernel command line.

So "enc_root=/dev/sda6" or some such.

"waffles" is a silly name for a device, but is clearly distinguished from a command or a parameter to a command.

Oh: and my init.in file is named init.in.txt just to make it clear to my future self what is going on. My initrd maker script expects it by that name.

diff from the books's initrd maker to mine:
Code:
3a4
> # they put it in /sbin/
53,54c54,55
< DATADIR=/usr/share/mkinitramfs
< INITIN=init.in
---
> DATADIR=/etc/lfs_initramfs
> INITIN=init.in.txt
64a66,68
> # Create directory needed for cryptsetup
> mkdir -pv $WDIR/usr/sbin
> 
103a108,115
> # Add cryptsetup if present.  Bit of a kludge, because it is in /usr/sbin
> # and this script expects everything to be in sbin
> echo "begin copying cryptsetup from /usr/sbin to work directory /sbin"
> cp -pv /usr/sbin/cryptsetup $WDIR/sbin/
> # Add needed libraries to to-copy queue via the variable "unsorted"
> ldd /usr/sbin/cryptsetup | sed "s/\t//" | cut -d " " -f1 >> $unsorted
> # end cryptsetup handling
> 
106a119
> # For the given binaries, determine which libraries are needed
186a200,201
> 
>
The big things here are the hard-coded copying of the cryptsetup program (I attempted conditional copying and failed) and some of the libraries. The reason: I had its library in a directory that the script was not expecting.


Note:

My script hard-codes things. Not flexible. Works fine but not easily modified for future changes.

Works on my machine. Might not work on yours.

I'm sure it can be improved.

p.s.

The coding style of the original versions of these two scripts in the LFS is clean: this helps understanding and allows not-to-difficult modification. Thumbs up.

Last edited by jr_bob_dobbs; 01-14-2018 at 07:58 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Initrd requires LVM option for RAID/LUKS root partition TracyTiger Slackware 5 09-19-2016 03:31 AM
Grub booting entire partition as initrd and running in memory Practically Speaking Linux - General 1 04-21-2011 01:26 AM
Trouble booting up to LVM partition on Raid1. gammahermit Linux - General 2 07-11-2010 11:37 AM
boot from lvm without initrd pgb205 Red Hat 1 03-01-2009 03:57 PM
boot fails when booting from lvm partition jlatl69 Linux - Newbie 6 03-07-2006 06:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration