Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Does anyone know how to modify mkinitcpio.conf in a script

Go to solution Solved by Nayr438,

You can use sed.

 

sed -i '/^HOOKS=/ s/filesystems/encrypt lvm2 &/g' /etc/mkinitcpio.conf

 

I'm making an arch install script for myself and one of the things I need to do is modify mkinitcpio.conf to change the line

"HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)" to

"HOOKS=(base udev autodetect modconf block encrypt lvm2 filesystems keyboard fsck)"

automatically how would I do this

Link to comment
Share on other sites

Link to post
Share on other sites

Adding data to the middle of a file like that isn't possible (at least AFAIK). Its much simpler to either delete the old file and replace it entirely or append a new version of the file over the old one.

 

1) Keep a copy of the modified file with your script and have it delete the existing file then download the modified one in its place.

 

2) something like this

sudo tee <<EOF > /etc/mkinitcpio.conf
***********full file content goes here*****************
EOF

which would overwrite the current contents of /etc/mkinitcpio.conf with whatever you put between the first EOF and the last EOF.

 

Edit - Now thatt I've said that, actually yes, it is possible to replace lines in files. Its used to apply patches to source code. Its called diff, no idea how to use it to create patches though, only ever used it to apply them.

 

Edit 2

4 hours ago, Linus No Beard said:
"HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)"

Almost all of those hooks can be replaced with a single systemd hook, check out the Arch Wiki page on mkinitcpio for a nice comparison table.

Main Rig:-

Ryzen 7 3800X | Asus ROG Strix X570-F Gaming | 16GB Team Group Dark Pro 3600Mhz | Corsair MP600 1TB PCIe Gen 4 | Sapphire 5700 XT Pulse | Corsair H115i Platinum | WD Black 1TB | WD Green 4TB | EVGA SuperNOVA G3 650W | Asus TUF GT501 | Samsung C27HG70 1440p 144hz HDR FreeSync 2 | Ubuntu 20.04.2 LTS |

 

Server:-

Intel NUC running Server 2019 + Synology DSM218+ with 2 x 4TB Toshiba NAS Ready HDDs (RAID0)

Link to comment
Share on other sites

Link to post
Share on other sites

Posted (edited)

You can use sed.

 

sed -i '/^HOOKS=/ s/filesystems/encrypt lvm2 &/g' /etc/mkinitcpio.conf

 

Edited by Nayr438
Use Insert instead of Replace. Cleanup, im bad at expressions.
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×