On 05.02.2017 08:34, J. Roeleveld wrote:
> On February 5, 2017 6:26:27 AM GMT+01:00, meino.cra...@gmx.de wrote:
>> Hi,
>>
>> since my old Gentoo installation seems to be screwed up (regarding
>> the update process) beyond repair I decided to install a new one
>> instead of waiting for help.
>>
>> I already made space at a certain of my harddisk and installed the
>> stage3 there.
>> Chrooting is one of the first steps to check, whether what I have
>> done so is valid.
>>
>> But before deleting the old root and install the new one at its
>> place I would like to do a atmost identical boot into the new
>> root.
>>
>> As far as I know the kernel only allows to boot into a partition
>> (instead of a directory on a partition containing the root
>> installation) and I am still using devices to boot from instead
>> of GPT.
>>
>> Is there any neat trick to do a real boot into the new root via
>> the normal boot process (grub2) nevertheless ?
>>
>> Cheers
>> Meino
> If I understand correctly. The answer is no. (Unless you write some clever 
> initramfs)
>
> Afaik, the kernel takes the entire partition and mounts it at '/'. If you 
> want it to use a directory (which would then be at '/newinstall') you need to 
> get the kernel to chroot into that directory and run init in there.
>
> Only option I see is to use an extra disk. Maybe a USB drive and use that.
>
> --
> Joost


Hi!

If I understand correctly, the answer is YES! You even needn't write an
initramfs, although that wouldn't have to be very clever: An initramfs
simply loads the necessary kernel modules for mounting the root
partition, mounts it and in the end does this:

exec switch_root <newroot> <init> <init args>

The manpage for switch_root says that <newroot> must be the root of a
mount and gives a trick for mounting arbitrary dirs: Just run a 'mount
--bind <newroot> <newroot>' before.
So, assuming your system is installed to /newinstall, you can just place
the following shell script  in e.g.  /newinstall/switch_root.sh:

#!/bin/sh

ROOT=/newinstall

mount --bind "$ROOT" "$ROOT"
exec switch_root "$ROOT" /sbin/init

#EOF

Then run 'chmod +x /newinstall/switch_root.sh'.

Now you add 'init=/newinstall/switch_root.sh' to your kernel commandline
(grub.cfg) and just boot  ist.
If you have some esoteric mount setup and need to use fstab in the
initramfs, then it is probably better to do it in an initramfs. I can
post a link to some easy initramfs setup, if you like. I'd need to
comment mine a bit so that everybody understands why I do what.

I haven't tried this specific script but have once created my own
initramfs for a special btrfs setup with some subvolumes.
If you try this, please let me know if it works!

Sorry for replying so late, i sent this mail last Sunday but from the
wrong email address. So it was probably dropped.


Cheers

Johannes



Reply via email to