WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Repack initramfs file script  (Read 3986 times)

Offline teh-botol

  • Newbie
  • *
  • Posts: 23
Repack initramfs file script
« on: January 18, 2017, 01:07:03 AM »
Hi Guys,

I just want to share a script to repack initramfs file with new files.

Background:
When we go custom (like creating kiosk), we need edit/add some file into the TC base.
Based on tinycorebook, many bootloader support more than one initramfs, but some is not.
I play with RPi to create appliances. Unfortunately, bootloader at piCore can't load 2 initramfs (CMIIW, I have tried many combination in config.txt).
Hence I create a script to ease the job.

Description:
Code: [Select]
Create a new initramfs file from original file overwritten with custom files.
Usage:
  repack_initrmfs.sh [args]
args:
  Ori.gz New.gz CustDir   Do the job.
  e Input.gz DestDir      Extract initramfs file.
  p Output.gz InDir       Pack initramfs file.
  g InDir Filter          gzip all filtered files inside directory.
  h (or no-args)          This help.
We create a custom directory for files we need to edit/add into TC base.
Using the script, it will:
1. Extract original TC base.
2. Copy all file from custom directory into extracted one (overwrite existing).
3. Repack into a new initramfs file.

Comment/feedback is appreciated.
Especially to make bootloader support more than one initramfs.


BR,
adit

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Repack initramfs file script
« Reply #1 on: January 18, 2017, 01:32:48 AM »
Review usage of sudo, better to drop it everywhere in the script. Just one line as example:

Code: [Select]
find . | sudo cpio -o -H newc | sudo gzip > $workdir/$OUT
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Repack initramfs file script
« Reply #2 on: January 18, 2017, 06:21:07 AM »
In my experience you should use sudo for find to get non-tc readable directories, but you don't need it for gzip and you can't redirect to a non-tc writable directory anyway unless you sudo a new shell.

Code: [Select]
sudo find . | sudo cpio -o -H newc | gzip >$workdir/$OUT