2

I'm trying to symlink file /etc/systemd/network/00-default.link to /boot/00-default.link. This allows me to force a change to my MAC address from the boot directory, which is the only directory accessible from my Mac computer when I plug in the SD card.

However, when I use the command:

sudo ln -s /etc/systemd/network/00-default.link /boot/00-default.link

I receive the error:

ln: failed to create symbolic link '/boot/00-default.link': Operation not permitted

Any idea what might be causing this?

Note: I've created /etc/systemd/network/00-default.link already but I have not yet created /boot/00-default.link

Matt
  • 426
  • 2
  • 6
  • 16

2 Answers2

3

/boot is a FAT filesystem that unfortunately does not support symbolic links.

So this cannot work

sudo ln -s /etc/systemd/network/00-default.link /boot/00-default.link

Turning it around and placing the file itself (source) on /boot and the link (target) on /etc however should do

sudo ln -s /boot/00-default.link /etc/systemd/network/00-default.link

This would however lack unixoid access permissions for the file - if that is an issue.

Ghanima
  • 15,855
  • 15
  • 61
  • 119
  • Interesting. I've noticed that if I move the file into /boot/ then symlink that file into somewhere else it works fine though, how is it able to work in one direction and not the other though? – Matt Oct 15 '18 at 21:21
  • Follow up question - since /boot/ requires a hard copy of the file and /etc/systemd/network/ also requires a hard copy to change the MAC address, would it be possible to use an intermediary third symlinked file as a bridge between the two hard files (meaning I could edit hard file /boot/00-default.link, which would edit the symlink /home/Pi/Desktop/bridge.link which in turn would edit hard copy of /etc/systemd/00-default.link)? Hopefully that made sense – Matt Oct 15 '18 at 21:25
  • 1
    w.r.t. the first comment, so you have a link from a unixoid FS to the vfat partition? That's just fine. – Ghanima Oct 15 '18 at 21:26
  • correct, I have a hard file /boot/my_script.py with symlink /home/Pi/Desktop/my_symlinked_script.py – Matt Oct 15 '18 at 21:27
  • Thanks for adding that edit @Ghaninma, that clarified a lot. I believe in this case the lack of unixoid access permissions is causing an issue for whatever reason. Can you think of any way to get around that while still linking the file to /boot/ – Matt Oct 15 '18 at 21:42
2

From your earlier questions, I know why you want to do this from boot, and symlinking /boot/00-default.link to /etc/systemd/network/00-default.link doesn't help, because /etc/systemd/network/00-default.link seems to be processed before /boot is mounted - therefore /etc/systemd/network/00-default.link is a broken link at the time it is being processed

I don't know if this is fact, but I know that linking that way also doesn't help, so I am assuming it to be fact :p

Here's a solution I came up with :p

Create a service in /etc/systemd/system - lets call it macoverride.service

[Unit]
Description=Copy user mac_override.link
ConditionPathExists=/boot/mac_override.link
After=local-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/mv /boot/mac_override.link /etc/systemd/network/00-default.link
ExecStartPost=/sbin/reboot

[Install]
WantedBy=multi-user.target

note about After=local-fs.target - I played around with this a bit, there may be an earlier target you can use, or use Before= - but this one works

Now, enable it

sudo systemctl enable /etc/systemd/system/macoverride.service

What this service does is

  1. if /boot/mac_override.link exists - move it to /etc/systemd/network/00-default.link
  2. reboot

Now, since step 1 moves the file, it won't exist after the reboot - so there's no chance of a reboot loop :p

Here's a more generic solution, by generic, I mean you'll be able to change what the file on the boot partition can do

Create a file for example, /etc/systemd/system/ssmatt.service

[Unit]
Description=Super special Matt code (change this to suit :p)
ConditionPathExists=/boot/matt.sh
After=basic.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh /boot/matt.sh

[Install]
WantedBy=multi-user.target

and

systemctl enable ssmatt.service
systemctl start ssmatt.service

Now, create a matt.sh file in the boot partition

#!/bin/sh
ifconfig eth0 down
ifconfig eth0 hw ether 10:00:00:00:00:11
ifconfig eth0 up

again After=basic.target is just the earliest target I found where this code was reliable for changing MAC

Using this method, the one downside is that matt.sh must exist in boot partition for the MAC to be changed, however the up side is that you can use matt.sh to do more than just changing the MAC

Jaromanda X
  • 2,415
  • 1
  • 13
  • 14
  • 1
    The OP might want to consider accepting this answer as it addresses the "implicit" issue of the question far better than mine ;) Your approach reminds me of what Raspbian is doing with the wpa_supplicant.conf file that is magically transferred from /boot to the correct spot somewhere in /etc. – Ghanima Oct 16 '18 at 01:03
  • @Ghanima - your answer actually answers the question though, so more useful for "future readers" - I've helped the OP in two other questions, so I kinda know the overall picture of what he's trying to achieve - as such, while this answer does provide a possible solution (there are others) this doesn't really answer the question, and so, not really helpful to anyone but Matt :p – Jaromanda X Oct 16 '18 at 01:13
  • This is beautiful. Can't thank you enough again @JaromandaX. Spot on as always. Cheers – Matt Oct 16 '18 at 05:26
  • Which do you think you'll use? the mac override or the "super special" :p – Jaromanda X Oct 16 '18 at 05:27
  • @Ghanima agreed, although your answer more directly addressed my question, this answer provides a solution to address the underlying issue. To any future readers take a look at Ghanima's answer to see why this issue is occurring. – Matt Oct 16 '18 at 05:41
  • @JaromandaX I'm leaning towards the mac override solution for simplicities sake but even just having the knowledge to execute a shell script from /boot using service files provides me with options I didn't previously have. I'm learning a ton from your answers. – Matt Oct 16 '18 at 05:44
  • @JaromandaX Ok weird follow up issue: so the mac_override method worked once and then randomly stopped working for me. When I create /boot/mac_override.link and use it to overwrite /etc/systemd/network/00-default.link it works (the file is moved successfully and pi reboots) but then doesn't change the MAC address. I thought this seemed weird so I tried forcing a change again with ifconfig eth0 down; ifconfig eth0 hw ether 21:21:21:21:00:11; ifconfig eth0 up; ifconfig eth0 and that too has stopped working. It now gives the error ether: Host name lookup failure – Matt Oct 16 '18 at 20:38
  • Maybe this should be moved to chat now? Or I should start a new question? – Matt Oct 16 '18 at 20:39
  • The full output from ifconfig eth0 down; ifconfig eth0 hw ether 21:21:21:21:00:11; ifconfig eth0 up; ifconfig eth0 can be seen here – Matt Oct 16 '18 at 20:42
  • Actually, I've created a follow up question here – Matt Oct 16 '18 at 21:02