Gentoo Archives: gentoo-embedded

From: Gareth McClean <disneysw@×××××××.com>
To: gentoo-embedded@l.g.o
Subject: RE: [gentoo-embedded] planning a flash DOM x86 embedded system
Date: Sun, 20 Oct 2013 22:50:36
Message-Id: BAY178-DS15563F75D60FA370FDF181C7000@phx.gbl
In Reply to: Re: [gentoo-embedded] planning a flash DOM x86 embedded system by Francisco Ares
1 Check your /etc/mtab on the failing system to see how the kernel believes the root partition has been mounted.
2
3
4
5 I ended up including a fix-up in at the end of my init script to ensure /etc/mtab correctly reflected my aufs root file system
6
7
8
9 # Insert our new root into the mtab
10
11 sed -i '1i none / aufs dirs=/rw=rw:/ro=ro' ${NEW_ROOT}/etc/mtab
12
13
14
15 this is performed just before performing the “switch_root” process.
16
17
18
19
20
21
22
23 Also are you sure "/etc/initramfs.mounts" is actually being processed?
24
25
26
27 If you are passing the “aufs” option into the init script using grub then the code to process "/etc/initramfs.mounts" is never called.
28
29
30
31 It’s been a few years since I set this up but like you I use genkernel to create the initramfs (yes I’m lazy). However I replace the default genkernel init script with a slightly modified version using the ‘--linuxrc’ option. This replacement script includes my additional aufs mounts and manages a few additional functions such as performing software updates which for obvious reasons can’t take place on a fully running system.
32
33
34
35 I use the ‘loop’, ‘looptype’, ‘ramdisk’ and ‘aufs’ init options which are passed in via the grub boot manager. These options are normally used for live CD builds to overlay a small ram disc on top of the CD using aufs. In essence my change simply maps another physical partition over the top to allow for permanent data storage.
36
37
38
39 Gareth.
40
41
42
43
44
45
46
47 From: Francisco Ares [mailto:frares@×××××.com]
48 Sent: 18 October 2013 18:16
49 To: gentoo-embedded@l.g.o
50 Subject: Re: [gentoo-embedded] planning a flash DOM x86 embedded system
51
52
53
54 Thanks, Gareth.
55
56 But it is very interesting that with no special customizations, I am almost able to have a fully functional system.
57
58 That new thing about having to use a initramfs when the root filesystem and the /usr directory are not present in the same physical partition, it turns out that it helps on having the "genkernel" generated initramfs do the job of mounting different arrangements for partitions, directories and unionfs mounts. That is because of the file "/etc/initramfs.mounts" where the specified mount entries, are extracted from the "/etc/fstab" and mounted before the initram gives way to the real root environment.
59
60 For instance, in this system, for now, there is the directory structure bellow:
61
62 /.var.rw - here a r/w ext4 partition is to be mounted;
63
64 /.var.ro - here there are all files and directories expected to be on a usual /var;
65
66 /var - here a unionfs mount is to join the ones above
67
68 The part from fstab for this is ("/.var.ro" is present on the squashfs root file system):
69
70 /dev/sda2 / squashfs noatime,ro 0 1
71 /dev/sda3 /.var.rw ext4 noatime,defaults 0 2
72 none /var unionfs nonempty,cow,umask=022,dirs=/.var.rw/=rw:/.var.ro/=ro 0 0
73
74 I said it is not yet fully functional because it seems there is something wrong with permissions, because it ends up with a unknown user prompt from which I could list the root directories (something similar is being made to "/etc"):
75
76 total 9,0K
77 drwxr-xr-x 23 root root 385 Out 18 14:18 ./
78 drwxr-xr-x 4 root root 4,0K Set 24 09:46 ../
79 drwxr-xr-x 47 root root 2,6K Out 17 16:03 .etc.ro/
80 drwxr-xr-x 2 root root 40 Out 18 15:09 .etc.rw/
81 drwxr-xr-x 11 root root 262 Out 17 16:03 .var.ro/
82 drwxr-xr-x 6 root root 4,0K Out 18 14:33 .var.rw/
83 drwxr-xr-x 2 root root 1,4K Out 7 14:46 bin/
84 drwxr-xr-x 4 root root 1,0K Out 18 14:15 boot/
85 d????????? 3 root root 2,3K Ago 1 00:17 dev/
86 drwxr-xr-x 1 root root 2,6K Out 17 16:03 etc/
87 drwxr-xr-x 3 root root 54 Ago 22 07:55 home/
88 lrwxrwxrwx 1 root root 5 Out 7 14:05 lib -> lib64/
89 drwxr-xr-x 12 root root 3,2K Out 17 08:51 lib64/
90 drwxr-xr-x 2 root root 28 Ago 1 00:16 media/
91 drwxr-xr-x 2 root root 28 Ago 1 00:16 opt/
92 drwxr-xr-x 2 root root 3 Jul 31 22:22 proc/
93 drwxr-xr-x 2 root root 136 Out 18 14:18 root/
94 drwxr-xr-x 5 root root 120 Ago 30 08:59 run/
95 drwxr-xr-x 2 root root 2,9K Out 17 08:51 sbin/
96 drwxr-xr-x 2 root root 28 Ago 1 00:16 sys/
97 drwxrwxrwt 2 root root 3 Out 18 14:18 tmp/
98 drwxr-xr-x 13 root root 267 Out 17 11:18 usr/
99 d????????? 1 root root 262 Out 17 16:03 var/
100
101 Any hints or suggestions? I will post this to the "gentoo-user" list, also, I guess it is an interesting thing that might be called a cool side effect of the recent issues.
102
103 Thanks
104 Francisco
105
106
107
108
109
110 2013/10/17 Gareth McClean <disneysw@×××××××.com>
111
112
113
114 I do this using a slightly modified init script, aufs3 and a squashfs.
115
116
117
118 Basically the system setups a tmpfs as a RW overlay on top of the squashfs. Then for permanent storage there is a physical Ext4 partition overlaid again on top of the /home directory.
119
120
121
122 Symbolic links are then used for any configuration files (such as network configuration) that require persistent storage. These links obviously reference locations within the /home directory that is stored on an Ext4 physical partition.
123
124
125
126 My init script is slightly more complicated than this since it caters for both live (squash plus aufs) and development (normal disc access) modes but basically it boils down to:
127
128
129
130
131
132 mount -t aufs aufs "${NEW_ROOT}" -o dirs=/rw=rw:/ro=rr
133
134
135
136 # Mount RW_PERM
137
138 echo "Mounting RW"
139
140 mkdir -p /rw-perm
141
142 mount "UUID=${RW_PERM_UUID}" /rw-perm
143
144 mount -o bind /ro/home "${NEW_ROOT}/home"
145
146 mount -t aufs aufs "${NEW_ROOT}/home" -o dirs=/rw-perm=rw:/ro/home=rr
147
148
149
150 where
151
152 ro = squashfs
153
154 rw = tmpfs
155
156 rw-perm = physical Ext4 partition
157
158
159
160 Note you need the “mount -o bind" command to allow an overlay on top of an overlay with aufs3 otherwise you will get an error message.
161
162
163
164 BTW, Unless you have a good reason for doing this I would not recommend doing this since you have a physical hard drive. The reason I still do this is mainly for backward compatibility. Of course it is nice to have the ability to run our system from a liveUSB stick and it minimises software download size when doing updates but debugging the init script is a very time consuming process……
165
166
167
168
169
170
171
172
173
174 From: Francisco Ares [mailto:frares@×××××.com]
175 Sent: 16 October 2013 13:49
176 To: gentoo-embedded@l.g.o
177 Subject: [gentoo-embedded] planning a flash DOM x86 embedded system
178
179
180
181 Hi.
182
183 I am planning to build a system to be deployed in a SATA flash disk, and most of the file system will be read-only. There will be a tempfs on /temp and a read-write partition for /var (perhaps a unionfs with the static part of /var and that read-write partition)
184
185 Is there any resources on how to do this using Gentoo?
186
187 There is already a development system with everything working as expected on the final system. But when I put it to a squashfs, the system boots with several errors, like when trying to write to /etc and /var.
188
189 Looking on the new issue regarding /usr and / being on a different partitions, I have found the file in /etc/initramfs.mounts. I have added the needed fstab entries to be mounted before the system switches to the real-root, (as the comments on top of this file claims) but there are still errors during boot.
190
191
192
193 Thanks
194 Francisco

Replies

Subject Author
Re: [gentoo-embedded] planning a flash DOM x86 embedded system Francisco Ares <frares@×××××.com>