3

I'm working in an embedded Linux system trying to get it booting its root file system in ram using initramfs. The system comes up for the most part but then has trouble in the init scripts. I've narrowed the problem down to the following.

The system cannot recognize any relative paths. Let me explain more...

Not only are symlinks that point to files in relative locations broken, but simply running a simple command like such doesn't work:

$ pwd
/etc/network
$ cat ../inittab
cat: can't open '../inittab': No such file or directory

But this works fine:

$ cat /etc/inittab
<inittab output ...>

Any idea what could be going on?

UPDATE1

A standard ls .. command appears to function as expected. Also, the inode references look ok I believe?

   $ ls ..
    default/                inputrc                 moduli                  random-seed             ssh_config              sshd_config
    dhcp/                   issue                   mtab@                   resolv.conf@            ssh_host_dsa_key        ssl/
    fstab                   ld.so.conf              network/                rsyslog.conf            ssh_host_dsa_key.pub    sysconfig/
    fstab.bak               ld.so.conf.d/           nsswitch.conf           rsyslog.d/              ssh_host_ecdsa_key      ts.conf
    group                   logrotate.conf          os-release              screenrc*               ssh_host_ecdsa_key.pub  udev/
    hostname                logrotate.d/            passwd                  securetty               ssh_host_key
    hosts                   ltrace.conf             passwd-                 services                ssh_host_key.pub
    init.d/                 memstat.conf            profile                 shadow                  ssh_host_rsa_key
    inittab                 mke2fs.conf             protocols               shadow-                 ssh_host_rsa_key.pub
    $ cd / ; ls -lid /etc
       1547 drwxr-xr-x   12 root     root             0 Jan  1 00:49 /etc/
    $ cd /etc ; ls -lid .
       1547 drwxr-xr-x   12 root     root             0 Jan  1 00:49 ./
    $ cd /etc/network ; ls -lid ..
       1547 drwxr-xr-x   12 root     root             0 Jan  1 00:49 ../

With even more digging, I've discovered that relative paths work AS LONG AS you do not cross the "boundry" of the root of the file system:

$ cd usr/
$ ls ../etc
ls: ../etc: No such file or directory
$ cd ../etc
$ cd network/
$ ls ..
default/                inputrc                 moduli                  random-seed             ssh_config              sshd_config
dhcp/                   issue                   mtab@                   resolv.conf@            ssh_host_dsa_key        ssl/
fstab                   ld.so.conf              network/                rsyslog.conf            ssh_host_dsa_key.pub    sysconfig/
fstab.bak               ld.so.conf.d/           nsswitch.conf           rsyslog.d/              ssh_host_ecdsa_key      ts.conf
group                   logrotate.conf          os-release              screenrc*               ssh_host_ecdsa_key.pub  udev/
hostname                logrotate.d/            passwd                  securetty               ssh_host_key
hosts                   ltrace.conf             passwd-                 services                ssh_host_key.pub
init.d/                 memstat.conf            profile                 shadow                  ssh_host_rsa_key
inittab                 mke2fs.conf             protocols               shadow-                 ssh_host_rsa_key.pub
$ ls ../../usr
ls: ../../usr: No such file or directory

This leads me to believe that I have not properly mounted the root filesystem. Perhaps this output is the most telling of that?

$ df
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                204.2M         0    204.2M   0% /dev
tmpfs                   251.7M         0    251.7M   0% /dev/shm
tmpfs                   251.7M     76.0K    251.6M   0% /tmp

UPDATE2

After additional searching, I believe the following best describes my scenario:

2) The newer initial ramfs image, initramfs. Here one populates a directory, and then creates a compressed cpio archive which is expanded into ramfs upon boot and becomes the root filesystem. The kernel must be configured with CONFIG_BLK_DEV_INITRD=y but one does not need to set CONFIG_BLK_DEV_RAM_SIZE, nor does one need to set CONFIG_TMPFS=y. When the system is up, "df" does not report the root filesystem and one cannot interact with it by doing things like "mount --bind / dir". Also the distinction between what RAM is set aside for the filesystem and what RAM is used for processes is blurred. "df" reports nothing and "free" reports total usage without distinction, ie. used RAM = RAM used for files (as reported by "du") plus RAM used for processes.

However, I am a bit surprised by this. Does this imply I will not be able to interact around the root of the file system when using initramfs?

UPDATE3

This post indicates that what I am trying to accomplish is not unreasonable:

Now normally an initramfs is temporary, only used to run some programs extremely early in the boot process. After those programs run, control is turned over to the real filesystem running on a physical disk. However you do not have to do that. There is nothing stopping you from running out of the initramfs indefinitely

How can I run out of the initramfs indefinitely but yet also be able to "traverse" across the root of the file system?

  • 2
    Is this also true for ls, i.e, what is the output of ls ..? – eyoung100 Jun 30 '15 at 22:43
  • 1
    Is /etc/network a symlink pointing to something outside /etc? – lcd047 Jun 30 '15 at 22:49
  • 2
    Are you using a filesystem that doesn't implement ..? What is output of cd / ; ls -lid /etc and cd /etc ; ls -lid . and cd /etc/networks ; ls -lid .., with particular reference to the inode numbers. – roaima Jun 30 '15 at 23:23
  • Is it only happening with symlinks only or regular files as well? – VaTo Jun 30 '15 at 23:47
  • @SaulOrtega The problem is not exclusive to symlinks – dtmland Jul 1 '15 at 15:17
0

After reading this post, the problem is solved!

I had noticed when running the mount command that two entries appeared for /:

rootfs on / type rootfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=209064k,nr_inodes=52266,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on / type tmpfs (rw,relatime)

I had added an entry to fstab that I needed to remove:

# /etc/fstab: static file system information.
#
# <file system> <mount pt>     <type>   <options>         <dump> <pass>
none            /              tmpfs    defaults          0      0
proc            /proc          proc     defaults          0      0
devpts          /dev/pts       devpts   defaults,gid=5,mode=620   0      0
tmpfs           /dev/shm       tmpfs    mode=0777         0      0
tmpfs           /tmp           tmpfs    defaults          0      0
sysfs           /sys           sysfs    defaults          0      0

After removing the entry (and performing a reboot):

none            /              tmpfs    defaults          0      0

The problem goes away!

  • 1
    If this solves the issue, then the answer should ideally also be accepted (click the checkmark to the left). – Kusalananda Feb 14 '18 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.