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
- if
/boot/mac_override.link
exists - move it to /etc/systemd/network/00-default.link
- 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
/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/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/boot/my_script.py
with symlink/home/Pi/Desktop/my_symlinked_script.py
– Matt Oct 15 '18 at 21:27/boot/
– Matt Oct 15 '18 at 21:42