2

I am trying to create a startup script on Ubuntu Core to enable usb_modeswitch to change the mode of one of the devices connected to the device. I am running Ubuntu Core on the Dragonboard410c.

As in classic Ubuntu desktops, I tried editing /etc/rc.local

However, even though I do sudo vi /etc/rc.local I can't edit rc.local as it complains that it is only a read-only file.

I tried editing the file directly from the SD card (This works for configuration files on netplan), but somehow rc.local is not visible in the SD card.

How are you supposed to use apt style packages on boot on Ubuntu Core. Do I need to create a separate snap for this?

Thank you in advance

  • 3
    I recommend that you edit this to include information about what errors, specifically have happened. Please describe exactly what actions you took, including how you tried to edit rc.local, and exactly what the error was. If you don't remember it in full then you should try to reproduce it; if you're not able to reproduce it but it still doesn't work, then you can describe what possibly other wrong thing happened instead. Right now I don't think this can really be answered -- we don't know what you've actually tried to do or what prevented it from working. – Eliah Kagan Apr 12 '18 at 16:13
  • @EliahKagan Thanks, I have edited my question. Hope it is clearer – jalim Apr 17 '18 at 15:50
1

Check if your root filesystem is mounted with read-write permissions ( via /etc/mountab or /etc/fstab ). Read-only filesystem won't allow editing files on it, i.e. it may not be the file problem itself.

If it is read-only, use sudo mount -o remount,rw / command. Note that snappy core, iirc, is meant to be a read only filesystem for security reasons

  • Doesn't work: sudo mount -o remount,rw /. Errors with: mount: cannot remount /dev/root read-write, is write-protected – F1Linux May 7 at 16:03
  • Check the filesystem. When SD cards say write protected it may be sign of corrupt filesystem. As for mount command it is a standard approach, works in 99% cases, so there has to be something unusual about your case – Sergiy Kolodyazhnyy May 7 at 17:12
  • Id recommend creating a new question specifically for that on the site – Sergiy Kolodyazhnyy May 7 at 17:13
  • @sergiykoloyazhnyy No SD card. Looks like it's an Ubuntu Core design "feature". – F1Linux May 7 at 17:16
  • Alright. Might be something changed since the past year when this was posted. Still, please post a question on the site. Someone may clarify if it is in fact Ubuntu Core's particular design or something unusual – Sergiy Kolodyazhnyy May 7 at 17:25
1

The reason you can't write to /etc/rc.local is found in the mount command's output (truncated here).

/dev/mmcblk0p4 on /writable type ext4 (rw,relatime,data=ordered)
/dev/loop0 on / type squashfs (ro,relatime)

Ubuntu Core mounts the root filesystem as squashfs which is read-only. Parts of the filesystem are mounted as rw as you'll see in non-truncated output of the mount command, however rc.local doesn't live on one of these.

HOW TO GET AROUND THE PROBLEM:

Firstly, rc.local is a legacy sysvinit file which has been supplanted by SystemD which is now default in Ubuntu and every other distro.

So you can't execute a script by calling it from rc.local because it's ro. A better- and more granular way of raising services on boot- is to use a SystemD Timer. This has the advantage of raising services relative to other services. It's a scalpel vs sysvinit's rc.local machete.

To execute the script at a precise point in the boot use a SystemD Timer. A specimen script is shown below; tweak to your specific use-case

#!/bin/bash

cat <<EOF> /etc/systemd/system/myscript.service
[Unit]
Description=Customise Networking
Requires=network-online.target
After=snap.wifi-ap.management-service.service

[Service]
User=root
Group=root
Type=oneshot
ExecStart=/home/myuser/scripts/myscript.sh

[Install]
WantedBy=multi-user.target

EOF

chmod 644 /etc/systemd/system/myscript.service

systemctl enable myscript.service

This has been tested and proven to raise the custom service I created at the desired point in the boot and survives a reboot. HTH-

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.