1

I am trying to install Ubuntu base(Ubuntu from scratch) but I have a problem...after the installation I get a system with read-only file system and also, /boot is not automounted.

here is my /etc/fstab:

/dev/sda1   /boot vfat defaults,noatime 0 2
/dev/sda2   /     ext4 defaults,noatime 0 1

here is how I chroot into the base system for installation:

mount /dev/sda2 /mnt
cp /etc/resolv.conf /mnt/etc/resolv.conf
mount --types proc /proc /mnt/proc
mount --rbind /sys /mnt/sys
mount --make-rslave /mnt/sys
mount --rbind /dev /mnt/dev
mount --make-rslave /mnt/dev
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm
chroot /mnt /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"
<installation steps>
exit
cd
umount -l /mnt/dev{/shm,/pts,}
umount -R /mnt
reboot

when I run the following command the system becomes writable:

mount -o remount,rw /

what did I do wrong ?

4
  • Can you provide more details about what happens after you reboot? What gets printed on the console before you run the mount command? Commented Oct 23, 2020 at 2:41
  • I get kernel messages and then get a # prompt.. Commented Oct 23, 2020 at 4:20
  • Most likely your installation steps are wrong. A correct Ubuntu install shouldn't dump you directly into a root shell with a plain # prompt like that, even with a broken filesystem. Sounds like you're getting /bin/sh for init instead of systemd. You'll need to provide more details about your installation steps, or link to instructions that you followed. Also, why are you installing into a chroot rather than using the Ubuntu installer? Sounds like a possible XY Problem. Commented Oct 23, 2020 at 5:32
  • Here is my installation steps: pastebin.com/GbwtEDsV Commented Oct 23, 2020 at 13:52

1 Answer 1

0

Short Answer

In your installation steps, you need to install the systemd-sysv package.

Long Answer

Looks like you're installing Ubuntu Focal. The Ubuntu Base image for Focal does not include a /sbin/init. Assuming you're using systemd, which is the default, this binary is provided by the systemd-sysv package. Note that the Ubuntu Base image for some earlier version of Ubuntu do include /sbin/init, so older instructions may not mention this. (Why doesn't the image have /sbin/init anymore? Probably because it's generally not needed in containers, which is an increasingly large use case of images like this.)

So how did you end up at a shell prompt without an init? The init script in the initrd, which is responsible for execing a "real" init, has a fallback. If /sbin/init isn't found, it tries a list of alternate executables, one of which is /bin/sh. You probably also got a message like Target filesystem doesn't have requested /sbin/init printed to the console.

So how come your root filesystem was mounted read only? Because that's what your GRUB config tells it to do. Run cat /proc/cmdline and you should see that the ro option is included, which instructs the initrd to mount / read-only initially. This allows init to, if necessary, run fsck to fix errors on your root filesystem. Init will then remount / read-write.

4
  • Should I install systemd after installing grub+initramfs+kernel or before ? Commented Oct 23, 2020 at 17:36
  • I suspect the regular Ubuntu installer installs systemd-sysv first, so that probably what I'd choose. But order probably doesn't matter. Commented Oct 23, 2020 at 17:41
  • Also, How do I change GRUB's config so that it wouldn't make the filesystem read-only ? Commented Oct 23, 2020 at 17:42
  • You don't need to make it mount read-write, systemd remounts it read-write for you. If you really want to mount it read-write at boot, I suggest asking a new question. Commented Oct 23, 2020 at 17:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.