Gentoo Archives: gentoo-user

From: "J. Roeleveld" <joost@××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] hard disk name changes within initramfs
Date: Thu, 06 Dec 2012 16:57:03
Message-Id: 71ddbd47-2c9d-4b5a-9bd0-7b47409d401d@email.android.com
In Reply to: [gentoo-user] hard disk name changes within initramfs by Helmut Jarausch
1 Helmut Jarausch <jarausch@××××××××××××××××.de> wrote:
2
3 >Hi,
4 >
5 >on one of several machines I have a problem with initramfs.
6 >
7 >The machine has a single SATA drive. When the kernel boots it shows
8 >that it is called /dev/sda,....
9 >Now, within the init script of my initramfs it tries to mount /dev/sda2
10 >
11 >as root but fails.
12 >Since the initramfs spawns a shell (busybox) I can see the device files
13 >
14 >for /dev/sda?
15 >but fdisk /dev/sda fails.
16 >As it turns out, the harddisk is now named /dev/sdb with /dev/sdb?
17 >partition names.
18 >
19 >Since this setup is identical to that of several other machines where
20 >it just works,
21 >I'm puzzled.
22 >
23 >Has anybody an idea what might be going on?
24 >
25 >Many thanks,
26 >Helmut.
27 >
28 >This is my init script
29 >
30 >#!/bin/busybox sh
31 >
32 >rescue_shell() {
33 > echo "$@"
34 > echo "Something went wrong. Dropping you to a shell."
35 > busybox --install -s
36 > exec /bin/sh
37 >}​
38 >
39 >uuidlabel_root() {
40 > for cmd in $(cat /proc/cmdline) ; do
41 > case $cmd in
42 > root=*)
43 > type=$(echo $cmd | cut -d= -f2)
44 > echo "Mounting rootfs"
45 > if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
46 > uuid=$(echo $cmd | cut -d= -f3)
47 > mount -o ro $(findfs "$type"="$uuid") /mnt/root
48 > else
49 > mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root
50 > fi
51 > ;;
52 > esac
53 > done
54 >}​
55 >
56 >check_filesystem() {
57 > # most of code coming from /etc/init.d/fsck
58 >
59 > local fsck_opts= check_extra= RC_UNAME=$(uname -s)
60 >
61 > # FIXME : get_bootparam forcefsck
62 > if [ -e /forcefsck ]; then
63 > fsck_opts="$fsck_opts -f"
64 > check_extra="(check forced)"
65 > fi
66 >
67 > echo "Checking local filesystem $check_extra : $1"
68 >
69 > if [ "$RC_UNAME" = Linux ]; then
70 > fsck_opts="$fsck_opts -C0 -T"
71 > fi
72 >
73 > trap : INT QUIT
74 >
75 > # using our own fsck, not the builtin one from busybox
76 > /sbin/fsck ${fsck_args--p} $fsck_opts $1
77 >
78 > case $? in
79 > 0) return 0;;
80 > 1) echo "Filesystem repaired"; return 0;;
81 > 2|3) if [ "$RC_UNAME" = Linux ]; then
82 > echo "Filesystem repaired, but reboot needed"
83 > reboot -f
84 > else
85 > rescue_shell "Filesystem still have errors;
86 >manual fsck required"
87 > fi;;
88 > 4) if [ "$RC_UNAME" = Linux ]; then
89 > rescue_shell "Fileystem errors left
90 >uncorrected, aborting"
91 > else
92 > echo "Filesystem repaired, but reboot needed"
93 > reboot
94 > fi;;
95 > 8) echo "Operational error"; return 0;;
96 > 12) echo "fsck interrupted";;
97 > *) echo "Filesystem couldn't be fixed";;
98 > esac
99 > rescue_shell
100 >}​
101 >
102 ># temporarily mount proc and sys
103 >mount -t proc none /proc
104 >mount -t sysfs none /sys
105 >
106 >echo /sbin/mdev > /proc/sys/kernel/hotplug
107 >mdev -s
108 >
109 ># only do this if you've built devtmpfs support into your kernel
110 ># mount -t devtmpfs none /dev HJ: done by the kernel itself
111 >
112 ># disable kernel messages from popping onto the screen
113 >echo 0 > /proc/sys/kernel/printk
114 >
115 ># clear the screen
116 ># clear
117 >
118 >
119 ># ====================== start doing stuff
120 >
121 ># mounting rootfs on /mnt/root
122 >uuidlabel_root || rescue_shell "Error with uuidlabel_root"
123 >
124 >btrfs device scan
125 >
126 ># space separated list of mountpoints that ...
127 >mountpoints="/usr"
128 >
129 ># ... we want to find in /etc/fstab ...
130 ># ln -s /mnt/root/etc/fstab /etc/fstab
131 >
132 ># ... to check filesystems and mount our devices.
133 >for m in $mountpoints ; do
134 > check_filesystem $m
135 >
136 > echo "Mounting $m"
137 > # mount the device and ...
138 > mount $m || rescue_shell "Error while mounting $m"
139 >
140 > # ... move the tree to its final location
141 > mount --move $m "/mnt/root"$m || rescue_shell "Error while moving
142 >$m"
143 >done
144 >
145 >echo "All done. Switching to real root."
146 >
147 ># ====================== end doing stuff
148 >
149 >mount -o remount,rw /mnt/root
150 >cp /proc/mounts /mnt/root/mtab
151 >
152 ># clean up. The init process will remount proc sys and dev later
153 >umount /proc
154 >umount /sys
155 ># umount /dev # fails, since it's automounted by the kernel
156 >
157 ># switch to the real root and execute init
158 >exec switch_root /mnt/root /sbin/init "$@"
159
160 Did you have anything connected via USB? Or maybe a CD/DVD?
161 Am thinking something got detected first.
162 Solution could be to put non-boot devices (like usb-storage) as modules.
163
164 --
165 Joost
166 --
167 Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Replies

Subject Author
Re: [gentoo-user] hard disk name changes within initramfs Helmut Jarausch <jarausch@××××××××××××××××.de>