Solved: Customize initramfs SD fallback
|
31st Jul, 2014, 05:58 PM
Post: #1
|
|||
|
|||
Customize initramfs SD fallback
Hi everybody, I'm here to ask help in doing something I've never had to do before in my past Linux experience: customize the initramfs.
Problem: I want to run XBian on my RPi model B from USB hard drive, but I want to be able to power off my RPi and disconnect the USB disk while still being able to boot my RPi. To achieve such goal I was initially thinking to just use the recovery shell and have two lines in my cmdline.txt file, one commented out so just a quick edit could do. Sadly my USB Cherry G320 keyboard is not recognized by the kernel modules and I'm back to square one. I was thinking I can put a simple shell script in the recovery console init sequence: check if the USB disk is connected and if it is not try to switch the cmdline arguments and continue booting. The problem is I don't know where I can put such script so to see it executed when entering the rescue console. I know I have to alter the initramfs.gz content and I can use the /etc/initramfs-tools folder, but by putting a simple echo "Testing now!!!!" inside a test.sh file in the scripts/premount-init and/or scripts/premount-local folder didn't produce any output change in my boot sequence (and yes, I did run the xbian-update-initramfs and I did uncomment the initramfs directive in the config.txt file). Now I'm questioning myself regarding my comprehension of initramfs... Should the scripts located in those folders get executed before the root filesystem gets mounted? What is the difference between those prefixed with init and those with local? Where those scripts should end up in the newly created initramfs? Should them be visible from within the rescue console? My plan for the sd-fallback.sh script is: 1. check for usb disk by LABEL/UUID (blkid) 2. check for /rootfs content (ls) 3. in case one of the above fails and cmdline.txt.usb does not exist 3.1. copy current cmdline.txt onto cmdline.txt.usb 3.2 copy cmdline.txt.sd onto cmdline.txt (force) 3.3 exit rescue mode I believe this could be useful in many situations.... Any help is appreciated |
|||
31st Jul, 2014, 06:20 PM
Post: #2
|
|||
|
|||
RE: Customize initramfs
No, as i said in the other topic. You have to alter the files in /etc/xbian-initramfs/.
I would suggest you put the following in the init file at line 182: Code: . /sd-fallback.sh || drop_shell Of course, make sure the sd-fallback script is executable and exits with either 0 for success or 1 for failure. Just put the sd-fallback.sh script in the /etc/xbian-initramfs/ folder and add the following line to the update-initramfs.sh file after cp /etc/xbian-initramfs/splash_updater.sh ./ Code: cp /etc/xbian-initramfs/sd-fallback.sh ./ pilight - modular domotica solution
|
|||
31st Jul, 2014, 07:41 PM
Post: #3
|
|||
|
|||
RE: Customize initramfs
(31st Jul, 2014 06:20 PM)CurlyMo Wrote: No, as i said in the other topic. You have to alter the files in /etc/xbian-initramfs/. Ok, now I better understand the initramfs creation process I'll let you know and eventually attach my script for other to reuse. |
|||
3rd Aug, 2014, 01:26 AM
Post: #4
|
|||
|
|||
RE: Customize initramfs for SD fallback
Ok, I have it running now and it works nicely!
I'm going to write a blog post on this, but in the meanwhile: Please find the little shell script attached. The script accepts one option which can either be fallback which tries to restore the SD as root filesystem, or restore which tries to restore the USB hard drive as rootfs. The modified init script is attached as well: the initial suggestion to slightly alter line 182 wasn't perfect as that line happen to get executed too late in the init process, but the suggestion was more or less correct. The altered init scripts tries to fallback to SD card root fs and, if it succeeds, it automatically restart your RPi to apply the modifications. Don't worry the script doesn't keep rebooting your RPi indefinitely The other steps are the same as suggested by CurlyMo and I'll update this post to a link to my blog once I've the post published. To use this script you need to copy your cmdline.txt file into cmdline.sd.txt before altering it to use the USB as rootfs: this file will be used by the fallback proceedure. Once the fallback proceedure is applied, in case you want to restore your USB rootfs you just have to execute the same script with the restore option. Thanks a million to CurlyMo and everybody else. Next step: automatically sync the root filesystem between USB and SD: going to open another topic! |
|||
4th Aug, 2014, 08:21 PM
Post: #5
|
|||
|
|||
RE: Customize initramfs SD fallback
Here is my blog post... http://rlogiacco.wordpress.com/2014/08/04/xbian-from-usb-with-sd-fallback/
|
|||
6th Aug, 2014, 09:02 PM
Post: #6
|
|||
|
|||
RE: Customize initramfs SD fallback
@rlogiacco
to merge idea like this into XBian I would prefer more generalised approach. let's define some fix points during initramfs run (after-virtual-filesystems; before-root-mount; after-network-done; before-move-root). then we can create folders Code: /etc/xbian-initramfs/after-virtual-filesystems then any script existing there will be always copied to initramfs and started at the specific stage. that way we never have to update init script or update-initramfs again. user can just put / remove scripts from the directories. Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
6th Aug, 2014, 10:02 PM
Post: #7
|
|||
|
|||
RE: Customize initramfs SD fallback
(6th Aug, 2014 09:02 PM)mk01 Wrote: @rlogiacco Totally with you! Please consider though I had to mount /boot inside my script as it was not mounted yet at that stage: to avoid any possible mess I unmounted it as well. If those dirs did exist I would definitely have used them... I actually tried to use those named premount-init and premount-local under /etc/initramfs-tools but they aren't used for the purpose I thought.... |
|||
6th Aug, 2014, 10:08 PM
Post: #8
|
|||
|
|||
RE: Customize initramfs SD fallback
@rlogiacco
just between us - I would happily go for standard initramfs-tools package. with current initramfs-tools structure it is possible to convert our scripts to it, ... but it would require significant time for testing. so I won't do it, but will support (Q&A) anyone who will commit to that ! Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
« Next Oldest | Next Newest »
|