Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Initramfs question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
yee
n00b
n00b


Joined: 16 Sep 2004
Posts: 39

PostPosted: Sun Nov 24, 2013 4:48 pm    Post subject: Initramfs question Reply with quote

I was reading https://wiki.gentoo.org/wiki/Early_Userspace_Mounting and have a question concerning the init file

Within the subroutine, check_filesystem(), /sbin/fsck is used to avoid the busybox fsck. On my system, it is linked to shared libraries in /lib. OK so far since /sbin and /lib is on the same filesystem.

As far as the script goes, /proc, /dev and /sys are first mounted before the root partition.

Root is mounted on /mnt/root using the uuidlabel_root() subroutine. Thus, /sbin is actually found on /mnt/root/sbin.

After softlinking /etc/fstab, the first step is to check the filesystem in the loop. The check_filesystem() subroutine is called looking for /sbin/fsck which should even exist (it is /mnt/root/sbin/fsck) ! Further, the shared libraries are supposed to be in /lib are actually in /mnt/root/lib.

Why should the initscript actually WORK? What am I missing?

Thanks.
Conway Yee
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sun Nov 24, 2013 5:07 pm    Post subject: Reply with quote

You're probably missing that these files are supposed to be included in the Initramfs in this case. So /sbin/fsck is part of the Initramfs, while it may be a copy of /mnt/root/sbin/fsck it's not strictly related anymore at this point.

I still think this is badly done, though. In particular the /forcefsck check - that probably won't work, as there should never be a /forcefsck in the Initramfs really. And although you could craft a boot entry that does create this file, you'd usually go for a custom kernel parameter instead.

The primary function of Initramfs is to mount the root partition in read-only mode. No more, no less. You can leave the entire fsck out of it. fsck will be done by the real system, same way it works in a system that does not use an Initramfs. If your filesystem is that badly off that this breaks, you're probably better off with a real rescue system anyway. Unless you're trying to turn your Initramfs into such, you're probably better off leaving the fsck out of it.
Back to top
View user's profile Send private message
yee
n00b
n00b


Joined: 16 Sep 2004
Posts: 39

PostPosted: Sun Nov 24, 2013 5:45 pm    Post subject: Reply with quote

frostschutz wrote:
The primary function of Initramfs is to mount the root partition in read-only mode. No more, no less. You can leave the entire fsck out of it. fsck will be done by the real system, ...


Aah! That would be lovely and what I have been doing for years, mainly to allow access the LABEL=ROOT notation in grub. With multiple hard drives in my system, things started getting confusing and I used labels instead.

The problem is that as far I am aware, separately mounted /usr is not OFFICIALLY supported in gentoo anymore. I have been using a /usr mounted read-only to protect my system. The root partition is left read/write.

As such, I am forced to mount /usr in initramfs. There in lies the problem. As I understand it, once mounted in initramfs, fsck can not safely check /usr.

Ideas? My currently preferred option would be to rebuild /sbin/fsck* as a completely static binary and use /mnt/root/fsck*. I use the same cpio archive for BOTH 32 bit and 64 bit systems and deliberately built uclibc busybox as a 32 bit binary. I would prefer to avoid cluttering up initramfs with excess specially built garbage. Complexity does not belong in initramfs.

Conway Yee
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sun Nov 24, 2013 7:10 pm    Post subject: Reply with quote

yee,

There is a patch to the init scripts to start udev after localmount.
The allows the use of a separate /usr without it being mounted in the initrd.
This patch is supported by the user community.
_________________
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
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sun Nov 24, 2013 7:56 pm    Post subject: Reply with quote

yee wrote:
As such, I am forced to mount /usr in initramfs. There in lies the problem. As I understand it, once mounted in initramfs, fsck can not safely check /usr.


There should be no difference. Of course, I don't know how it's implemented in the init scripts.

As for separate /usr, what I did when this started was to get rid of separate /usr altogether. If you have a partition for everything anyway, your / partition will be pretty much empty and therefore useless. So merging it with /usr is no problem at all, and at the same time it solves a bunch of problems.

Something along these lines:

Code:

mkdir /mnt/root
mkdir /mnt/usr
mount /dev/yourroot /mnt/root
mount /dev/yourusr /mnt/usr
mkdir /mnt/usr/usr
mv /mnt/usr/* /mnt/usr/usr/
rsync -a /mnt/root/. /mnt/usr/.


Update any dependencies (grub, fstab, initramfs, ...) along with it and your usr device is your new root device.

No more problems with separate usr, no more patches to initscripts, no initramfs you don't need if you don't encrypt stuff, no downsides.
Back to top
View user's profile Send private message
yee
n00b
n00b


Joined: 16 Sep 2004
Posts: 39

PostPosted: Thu Nov 28, 2013 3:31 am    Post subject: Reply with quote

I wanted to keep the initramfs as lightweight as possible. I see absolutely NO reason why fsck needs to be in the archive since the init script ALREADY knows where root is. Thus, after mounting root, I added a bit of code to place fsck* into /sbin and create the necessary symbolic links for /lib*

This way my initramfs ONLY contains the init script and the busybox binary.

Conway Yee



Code:


                                # mount / and other filesystems
mount -o ro "${root}" /mnt || exec sh

ln -s /mnt/etc/fstab /etc/fstab


                                         # allow access to fsck
for i in $(ls /mnt | grep lib ); do
    ln -s /mnt/$i /
done
rm /sbin/fsck*                          # get rid of busybox fsck
for i in $(ls /mnt/sbin/fsck* ); do
    ln -s $i /sbin
done


Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things 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