On Wednesday 22 January 2014 00:15, Peter Chant conveyed the following
to alt.os.linux.slackware...
> On 01/21/2014 10:24 PM, Aragorn wrote:
>
>> On Tuesday 21 January 2014 22:57, Peter Chant conveyed the following
>> to alt.os.linux.slackware...
>>
>>> [...] Likely about to install a new system.
>>>
>>> 1. Dislike and don't get on with initrd.
>>
>> Copy that.
>>
>>> 2. Like to use btrfs but can't seem to boot directly from lilo etc.
>>
>> You can use something else there. I myself always maintain a
>> separate /boot partition anyway. I tend to favor xfs, but if you're
>> not familiar with it, then just use ext2/3/4 for /boot. Or reiserfs,
>> even.
>
> I sort of dispense with a separate /boot, but in effect what I use is:
> <maintenence root>/boot
>
> If I build a new kernel, which is not often, I have to remember to
> copy over the relent bits to that boot directory on the maintenance
> file system, put the kernel in place, boot to the maintenance system
> and update lilo.
Well, that's why having a common /boot - mounted read-only during normal
operation - is a better approach, in my humble opinion.
> [...]
>
>>> 4. Usually install kernel and lilo on the maintenance partition and
>>> then set up an additional partition I normally use.
>>
>> I would propose something like...
>>
>> - /dev/sda1 = /boot
>> - /dev/sda2 = your maintenance partition's root filesystem
>> - /dev/sda3 = your real root filesystem
>
> I'd go:
> /dev/sda1 swap
> /dev/sda2 maintenance, ext4
> /dev/sda3 btrfs pool for root, home subvolumes etc.
>
> as the working /boot is within maintenance effectively. However, this
> moves from a practical to a religious argument very rapidly...
I wouldn't put swap as the first partition on the drive, even if only
because some partitioning tools don't like that. I remember that cfdisk
used to complain about that when I did that too, and it stopped
complaining when I put /boot first.
>>> Thought. My maintenance partition is almost a initial ram disk.
>>> Could I set up a script within the maintenance partition and supply
>>> a parameter to the kernel so that I could run the script on boot?
>>> I.e.
>>> add a parameter to the kernel in my lilo config so that would boot
>>> to the maintenance partition but instead of running init it would
>>> run the script, mount the final root and switch root?
>>
>> Yes, that is possible. Add the parameter
>>
>> init=/path/to/the/script/my_init
>>
>> ... (where "my_init" is the name of your script) to your kernel's
>> "append" line in /etc/lilo.conf.
>
> Cool. Man pages or whatever said init was a _binary_. If it is a
> script with #/bin/sh as its shell then fantastic.
No, /sbin/init *is* indeed a binary. But the kernel allows for an
alternative init specification. Using a pre-init script - which /may/
need to invoke busybox as its shell - is a trick I picked up from the
Gentoo mailing lists, because of screwups by Poettering and Sievers
which broke the booting with a separate /usr filesystem without that
there is an initramfs.
So I do think you need busybox for that, but don't pin me down on it.
In theory you should be able to do with bash as well, but bear in mind
that no environment has been declared yet at that point, so you would
need to specify the full path to the executables you invoke from within
your script, e.g. /bin/mount.
> I'm thinking along the lines:
> . . . . . .
> #!/bin/sh
>
> mount /dev/sda3 /mnt
>
defaults,autodefrag,inode_cache,noatime,compress=lzo,subvol=_root_sl14.1
> 0 0
That would then have to be /bin/mount. There is no $PATH declared yet
at that point in time, and it's a non-interactive non-login shell.
> #Any other stuff that is nice to do here.
> #But minimise if possible.
>
> exec switch_root /newroot /sbin/init
Yes, my bad. I wrote that you had to deamonize that and then exit the
script, but I was wrong. You have to use exec, indeed, so as to make
/sbin/init PID 1.
> So I presume after this that the system is none the wiser to these
> boot shenanigans and all will be well in the world.
It should, yes.
>>> Alternatively could I get init to run the script from inittab? I.e.
>>> could I set rc.S to be a special script in certain cases?
>>
>> You could do that, but I would be careful because of any udev
>> invocations and possibly the mounting of /proc and /sys _before_ the
>> chroot step.
>
> Oooh. Don't like the sound of that. Sounds less robust than above.
I forgot to add /dev to that list. You definitely need that one mounted
too. In a normal system, this can be taken care of at any stage in the
boot process, depending on what kernel you use. With a very recent
kernel, it shouldn't be a problem because then it's mounted by the
kernel itself.
> I did wonder if using runlevel 5 and cutting down the initialisation
> for that runlevel as much as possible. However, if init=/myscript
> works it sound better.
That /should/ work, yes. The kernel does accept an "init=" parameter.
>> In other words, you will want to trap the init call as early as
>> possible when userspace comes up, and if /proc and /sys already get
>> mounted before your script completes - and hopefully your script
>> won't depend on their presence - then you'll need to make sure they
>> get bind-mounted into the chroot environment _before_ you issue the
>> chroot.
>
> I think that switch_root moves them across - but I don't speak from
> experience.
Well, I don't know, really. That's why I wrote the above as a concern.
>> Also make sure that the last command in your script is one that
>> invokes /sbin/init (in the chroot environment, after the chroot
>> itself) and that you allow the script to terminate properly, or
>> otherwise put, that you daemonize /sbin/init by putting an ampersand
>> behind it, before your "exit" command.
Discard the above paragraph, this is wrong. You need to exec /sbin/init
in order to give it PID 1.
>>> # System initialization (runs when system boots). - Normal
>>> si:S:sysinit:/etc/rc.d/rc.S
>>>
>>> # System initialization switch root - only runs when specified by
>>> #argument passed to kernel (somehow)
>>> si:S:sysinit:/etc/rc.d/peteSwitchRootScript
>>>
>>> I note that there is an init script in the root of some initial ram
>>> disks that I have seen. What happens if I put one in the root of a
>>> regular filesystem?
>>
>> It's a different thing. The one in the initramfs is invoked by the
>> mechanism of the initramfs itself. Anything else [*] needs to be
>> invoked via a kernel parameter, because the kernel by default will
>> run /sbin/init if nothing else has been specified and when there is
>> no initramfs - the initramfs will invoke /sbin/init itself after the
>> switch_root command, which is specific to the initramfs environment.
>
> So /init is specific to initramfs.
Well, it does the same thing as what you're doing, really, except that
at that stage, the initramfs is still mounted as the root filesystem,
and thus the kernel will look for /sbin/init in the initramfs. And that
particular init is a script which uses busybox to execute a number of
commands, such as mounting the real root filesystem and possibly setting
up /proc and /sys, and possibly also launching udev.
I'm not sure on the latter anymore because there has been a change in
"recent" kernels. Originally /dev was populated with static nodes which
were on-disk and which had been created using mknod. Then, when udev
came around - let's skip devfs and the 2.4 kernel generation for
convenience's sake - /dev still contained some static on-disk nodes, but
was then overlaid with a mount from udev. Then, /dev was empty and udev
did everything, launched from the initramfs. But there were problems on
account of firmware loading by udev etc, so eventually /dev was now
populated from within the kernel itself, via devtmpfs, instead of a
regular tmpfs. Modern kernels normally use devtmpfs, and then kernel
will then automount /dev and populate it, before userspace is initiated,
and thus before udev starts running.
Mind you that the booting of udev is normally also taken care of from
within the initrd/initramfs, so you'll have to keep that into account.
And that is also how you have to mount /proc and /sys - /dev will be
mounted by the kernel itself - before you run anything else.
>> [*] You could for instance also use "init=/bin/bash" in the "append"
>> line to simply boot up to a root shell, but this is typically
>> deprecated (except for real emergencies) because it will not
>> initialize anything else, so there is no $PATH, for instance.
>
> Yep, been there with bad disk errors in the past. Seem to often end
> up in a system so limited all I can do is reboot and pray!
Well, it /is/ a very minimal system that you get then. Single-user
maintenance mode and no environment set, and nothing mounted but the
root filesystem itself. Not even udev running.
> Thanks for that, appreciated.
Welcome. ;-)