Added dependencies and extracted source since it needs to be tracked
This commit is contained in:
34
Makefile
34
Makefile
@@ -8,38 +8,19 @@
|
|||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
DEPENDS =
|
DEPENDS = find,kmod,psmisc,sed
|
||||||
ARCH = x86_64
|
ARCH = x86_64
|
||||||
URL =
|
URL =
|
||||||
DESC =
|
DESC = This package includes scripts to build an initrd image
|
||||||
SNAPVER = sr0
|
SNAPVER = sr1
|
||||||
|
|
||||||
ARCHIVE := $(PWD)/SRC/$(shell ls SRC|egrep '(bz2|gz|tar|xz)$$'|tail -1)
|
ARCHIVE := ''
|
||||||
TYPE := $(shell file -ib $(ARCHIVE)|cut -d';' -f1|tr -d '\n')
|
SRCDIR := $(PWD)/SRC/mkinitramfs-*
|
||||||
SRCDIR := $(shell tar -tf $(ARCHIVE)|head -1|sed 's/\/.*//')
|
|
||||||
PATCHDIR := $(PWD)/SRC/patches
|
PATCHDIR := $(PWD)/SRC/patches
|
||||||
VERSION := $(shell echo $(SRCDIR)|egrep -o '\-[0-9].*'|sed 's/^-//')$(SNAPVER)
|
VERSION := $(shell echo $(SRCDIR)|egrep -o '\-[0-9].*'|sed 's/^-//')$(SNAPVER)
|
||||||
|
|
||||||
MAKEINST = make install
|
|
||||||
SNAPHACKS =
|
|
||||||
|
|
||||||
include /usr/share/snap/Makefile.snaplinux
|
include /usr/share/snap/Makefile.snaplinux
|
||||||
|
|
||||||
$(SRCDIR)/Makefile: $(ARCHIVE)
|
|
||||||
@if [ '$(TYPE)' == 'application/x-bzip2' ]; then \
|
|
||||||
tar -jxf $(ARCHIVE); \
|
|
||||||
elif [ '$(TYPE)' == 'application/x-gzip' ]; then \
|
|
||||||
tar -zxf $(ARCHIVE); \
|
|
||||||
elif [ '$(TYPE)' == 'application/x-tar' ]; then \
|
|
||||||
tar -xf $(ARCHIVE); \
|
|
||||||
elif [ '$(TYPE)' == 'application/x-xz' ]; then \
|
|
||||||
tar -xf $(ARCHIVE); \
|
|
||||||
else \
|
|
||||||
echo 'Unable to determine archive type'; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
@touch $(SRCDIR)/Makefile
|
|
||||||
|
|
||||||
$(ROOT): $(SRCDIR)/Makefile
|
$(ROOT): $(SRCDIR)/Makefile
|
||||||
@if [ -d $(ROOT) ]; then \
|
@if [ -d $(ROOT) ]; then \
|
||||||
touch $(ROOT); \
|
touch $(ROOT); \
|
||||||
@@ -47,10 +28,7 @@ $(ROOT): $(SRCDIR)/Makefile
|
|||||||
mkdir -v $(ROOT); \
|
mkdir -v $(ROOT); \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@cd $(SRCDIR); \
|
@cd $(SRCDIR) && make install DESTDIR=$(ROOT)
|
||||||
$(MAKEINST) DESTDIR=$(ROOT)
|
|
||||||
|
|
||||||
@$(SNAPHACKS)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rvf $(ROOT) \
|
@rm -rvf $(ROOT) \
|
||||||
|
|||||||
Binary file not shown.
10
SRC/mkinitramfs-0.0/Makefile
Normal file
10
SRC/mkinitramfs-0.0/Makefile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
dirs:
|
||||||
|
install -d -m 755 $(DESTDIR)/sbin
|
||||||
|
install -d -m 755 $(DESTDIR)/usr/share/mkinitramfs
|
||||||
|
|
||||||
|
files:
|
||||||
|
install -m 755 sbin/mkinitramfs $(DESTDIR)/sbin/mkinitramfs
|
||||||
|
install -m 755 usr/share/mkinitramfs/init.in \
|
||||||
|
$(DESTDIR)/usr/share/mkinitramfs/init.in
|
||||||
|
|
||||||
|
install: dirs files
|
||||||
199
SRC/mkinitramfs-0.0/sbin/mkinitramfs
Executable file
199
SRC/mkinitramfs-0.0/sbin/mkinitramfs
Executable file
@@ -0,0 +1,199 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# This file based in part on the mkinitrafms script for the LFS LiveCD
|
||||||
|
# written by Alexander E. Patrakov and Jeremy Huntwork.
|
||||||
|
|
||||||
|
copy()
|
||||||
|
{
|
||||||
|
local file
|
||||||
|
|
||||||
|
if [ "$2" == "lib" ]; then
|
||||||
|
file=$(PATH=/lib:/usr/lib type -p $1)
|
||||||
|
else
|
||||||
|
file=$(type -p $1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n $file ] ; then
|
||||||
|
cp $file $WDIR/$2
|
||||||
|
else
|
||||||
|
echo "Missing required file: $1 for directory $2"
|
||||||
|
rm -rf $WDIR
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z $1 ] ; then
|
||||||
|
KERNEL_VERSION=`uname -r`
|
||||||
|
else
|
||||||
|
KERNEL_VERSION=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
INITRAMFS_FILE=initrd.img-$KERNEL_VERSION
|
||||||
|
|
||||||
|
if [ -n "$KERNEL_VERSION" ] && [ ! -d "/lib/modules/$1" ] ; then
|
||||||
|
echo "No modules directory named $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Creating $INITRAMFS_FILE...\n"
|
||||||
|
|
||||||
|
binfiles="dmesg sh cat cp dd killall ls mkdir mknod mount"
|
||||||
|
binfiles="$binfiles umount sed sleep ln rm uname"
|
||||||
|
|
||||||
|
# Systemd installs udevadm in /bin. Other udev implementations have it in /sbin
|
||||||
|
if [ -x /bin/udevadm ] ; then binfiles="$binfiles udevadm"; fi
|
||||||
|
|
||||||
|
sbinfiles="modprobe blkid switch_root zfs zpool"
|
||||||
|
|
||||||
|
#Optional files and locations
|
||||||
|
for f in mdadm udevd udevadm; do
|
||||||
|
if [ -x /sbin/$f ] ; then sbinfiles="$sbinfiles $f"; fi
|
||||||
|
done
|
||||||
|
|
||||||
|
unsorted=$(mktemp /tmp/unsorted.XXXXXXXXXX)
|
||||||
|
|
||||||
|
DATADIR=/usr/share/mkinitramfs
|
||||||
|
INITIN=init.in
|
||||||
|
|
||||||
|
# Create a temporrary working directory
|
||||||
|
WDIR=$(mktemp -d /tmp/initrd-work.XXXXXXXXXX)
|
||||||
|
|
||||||
|
# Create base directory structure
|
||||||
|
mkdir -p $WDIR/{bin,dev,lib/firmware,run,sbin,sys,proc}
|
||||||
|
mkdir -p $WDIR/etc/{modprobe.d,udev/rules.d}
|
||||||
|
touch $WDIR/etc/modprobe.d/modprobe.conf
|
||||||
|
cp /etc/modprobe.d/* $WDIR/etc/modprobe.d
|
||||||
|
ln -s lib $WDIR/lib64
|
||||||
|
|
||||||
|
# Create necessary device nodes
|
||||||
|
mknod -m 640 $WDIR/dev/console c 5 1
|
||||||
|
mknod -m 664 $WDIR/dev/null c 1 3
|
||||||
|
|
||||||
|
# Install the udev configuration files
|
||||||
|
if [ -f /etc/udev/udev.conf ]; then
|
||||||
|
cp /etc/udev/udev.conf $WDIR/etc/udev/udev.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in $(find /etc/udev/rules.d/ -type f) ; do
|
||||||
|
cp $file $WDIR/etc/udev/rules.d
|
||||||
|
done
|
||||||
|
|
||||||
|
# Install any firmware present
|
||||||
|
if [ -d /lib/firmware ]; then
|
||||||
|
cp -a /lib/firmware $WDIR/lib
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy the RAID configuration file if present
|
||||||
|
if [ -f /etc/mdadm.conf ] ; then
|
||||||
|
cp /etc/mdadm.conf $WDIR/etc
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install the init file
|
||||||
|
install -m0755 $DATADIR/$INITIN $WDIR/init
|
||||||
|
|
||||||
|
if [ -n "$KERNEL_VERSION" ] ; then
|
||||||
|
if [ -x /bin/kmod ] ; then
|
||||||
|
binfiles="$binfiles kmod"
|
||||||
|
else
|
||||||
|
binfiles="$binfiles lsmod"
|
||||||
|
sbinfiles="$sbinfiles insmod"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install basic binaries
|
||||||
|
for f in $binfiles ; do
|
||||||
|
ldd /bin/$f | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
||||||
|
copy $f bin
|
||||||
|
done
|
||||||
|
|
||||||
|
# Add lvm if present
|
||||||
|
if [ -x /sbin/lvm ] ; then sbinfiles="$sbinfiles lvm dmsetup"; fi
|
||||||
|
|
||||||
|
for f in $sbinfiles ; do
|
||||||
|
ldd /sbin/$f | sed "s/\t//" | cut -d " " -f1 >> $unsorted
|
||||||
|
copy $f sbin
|
||||||
|
done
|
||||||
|
|
||||||
|
# Add module symlinks if appropriate
|
||||||
|
if [ -n "$KERNEL_VERSION" ] && [ -x /bin/kmod ] ; then
|
||||||
|
ln -s kmod $WDIR/bin/lsmod
|
||||||
|
ln -s kmod $WDIR/bin/insmod
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add lvm symlinks if appropriate
|
||||||
|
# Also copy the lvm.conf file
|
||||||
|
if [ -x /sbin/lvm ] ; then
|
||||||
|
ln -s lvm $WDIR/sbin/lvchange
|
||||||
|
ln -s lvm $WDIR/sbin/lvrename
|
||||||
|
ln -s lvm $WDIR/sbin/lvextend
|
||||||
|
ln -s lvm $WDIR/sbin/lvcreate
|
||||||
|
ln -s lvm $WDIR/sbin/lvdisplay
|
||||||
|
ln -s lvm $WDIR/sbin/lvscan
|
||||||
|
|
||||||
|
ln -s lvm $WDIR/sbin/pvchange
|
||||||
|
ln -s lvm $WDIR/sbin/pvck
|
||||||
|
ln -s lvm $WDIR/sbin/pvcreate
|
||||||
|
ln -s lvm $WDIR/sbin/pvdisplay
|
||||||
|
ln -s lvm $WDIR/sbin/pvscan
|
||||||
|
|
||||||
|
ln -s lvm $WDIR/sbin/vgchange
|
||||||
|
ln -s lvm $WDIR/sbin/vgcreate
|
||||||
|
ln -s lvm $WDIR/sbin/vgscan
|
||||||
|
ln -s lvm $WDIR/sbin/vgrename
|
||||||
|
ln -s lvm $WDIR/sbin/vgck
|
||||||
|
# Conf file(s)
|
||||||
|
cp -a /etc/lvm $WDIR/etc
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add mtab symlink for zfs
|
||||||
|
ln -s /proc/mounts $WDIR/etc/mtab
|
||||||
|
|
||||||
|
# Install libraries
|
||||||
|
sort $unsorted | uniq | while read library ; do
|
||||||
|
if [ "$library" == "linux-vdso.so.1" ] ||
|
||||||
|
[ "$library" == "linux-gate.so.1" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
copy $library lib
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -d /lib/udev ]; then
|
||||||
|
cp -a /lib/udev $WDIR/lib
|
||||||
|
fi
|
||||||
|
|
||||||
|
#ls -lR $WDIR
|
||||||
|
mkdir -p $WDIR/lib/modules/$KERNEL_VERSION
|
||||||
|
touch $WDIR/lib/modules/$KERNEL_VERSION/modules.{builtin,order}
|
||||||
|
|
||||||
|
# Install the kernel modules in use
|
||||||
|
# May want to work on removing unnecessary modules at some point
|
||||||
|
# though in most cases this should probably be good enough
|
||||||
|
printf "Copying modules...\n"
|
||||||
|
|
||||||
|
for module in `cat /proc/modules|awk '{print $1}'`; do
|
||||||
|
cp --parents `modinfo -F filename $module` $WDIR/;
|
||||||
|
done
|
||||||
|
|
||||||
|
depmod -b $WDIR $KERNEL_VERSION
|
||||||
|
|
||||||
|
#if [ -n "$KERNEL_VERSION" ]; then
|
||||||
|
# find \
|
||||||
|
# /lib/modules/$KERNEL_VERSION/kernel/{crypto,fs,lib} \
|
||||||
|
# /lib/modules/$KERNEL_VERSION/kernel/drivers/{block,ata,md,firewire} \
|
||||||
|
# /lib/modules/$KERNEL_VERSION/kernel/drivers/{scsi,message,pcmcia,virtio} \
|
||||||
|
# /lib/modules/$KERNEL_VERSION/kernel/drivers/usb/{host,storage} \
|
||||||
|
# /lib/modules/$KERNEL_VERSION/extra/{avl,nvpair,spl,unicode,zcommon,zfs} \
|
||||||
|
# -type f 2> /dev/null | cpio --make-directories -p --quiet $WDIR
|
||||||
|
#
|
||||||
|
# cp /lib/modules/$KERNEL_VERSION/modules.{builtin,order} \
|
||||||
|
# $WDIR/lib/modules/$KERNEL_VERSION
|
||||||
|
#
|
||||||
|
# depmod -b $WDIR $KERNEL_VERSION
|
||||||
|
#fi
|
||||||
|
|
||||||
|
printf "Creating gzipped cpio...\n";
|
||||||
|
( cd $WDIR ; find . | cpio -o -H newc --quiet | gzip -9 ) > /boot/$INITRAMFS_FILE
|
||||||
|
|
||||||
|
# Remove the temporary directory and file
|
||||||
|
rm -rf $WDIR $unsorted
|
||||||
|
printf "done.\n"
|
||||||
108
SRC/mkinitramfs-0.0/usr/share/mkinitramfs/init.in
Normal file
108
SRC/mkinitramfs-0.0/usr/share/mkinitramfs/init.in
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
problem()
|
||||||
|
{
|
||||||
|
printf "Encountered a problem!\n\nDropping you to a shell.\n\n"
|
||||||
|
sh
|
||||||
|
}
|
||||||
|
|
||||||
|
no_device()
|
||||||
|
{
|
||||||
|
printf "The device %s, which is supposed to contain the\n" $1
|
||||||
|
printf "root file system, does not exist.\n"
|
||||||
|
printf "Please fix this problem and exit this shell.\n\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
no_mount()
|
||||||
|
{
|
||||||
|
printf "Could not mount device %s\n" $1
|
||||||
|
printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n"
|
||||||
|
printf "Maybe the device is formatted with an unsupported file system?\n\n"
|
||||||
|
printf "Or maybe filesystem type autodetection went wrong, in which case\n"
|
||||||
|
printf "you should add the rootfstype=... parameter to the kernel command line.\n\n"
|
||||||
|
printf "Available partitions:\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
do_mount_root()
|
||||||
|
{
|
||||||
|
mkdir /.root
|
||||||
|
[ -n "$rootflags" ] && rootflags="$rootflags,"
|
||||||
|
rootflags="$rootflags$ro"
|
||||||
|
|
||||||
|
case "$root" in
|
||||||
|
/dev/* ) device=$root ;;
|
||||||
|
UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID" ;;
|
||||||
|
LABEL=*) eval $root; device="/dev/disk/by-label/$LABEL" ;;
|
||||||
|
ZFS=*) eval $root; device="$ZFS"; zfs=true; rootfstype=zfs ;;
|
||||||
|
"" ) echo "No root device specified." ; problem ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$zfs" == 'true' ] ; then
|
||||||
|
zpool import -N -a
|
||||||
|
else
|
||||||
|
while [ ! -b "$device" ] ; do
|
||||||
|
no_device $device
|
||||||
|
problem
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then
|
||||||
|
no_mount $device
|
||||||
|
cat /proc/partitions
|
||||||
|
while true ; do sleep 10000 ; done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
init=/sbin/init
|
||||||
|
root=
|
||||||
|
rootdelay=
|
||||||
|
rootfstype=auto
|
||||||
|
ro="ro"
|
||||||
|
rootflags=
|
||||||
|
device=
|
||||||
|
|
||||||
|
mount -n -t devtmpfs devtmpfs /dev
|
||||||
|
mount -n -t proc proc /proc
|
||||||
|
mount -n -t sysfs sysfs /sys
|
||||||
|
mount -n -t tmpfs tmpfs /run
|
||||||
|
|
||||||
|
read -r cmdline < /proc/cmdline
|
||||||
|
|
||||||
|
for param in $cmdline ; do
|
||||||
|
case $param in
|
||||||
|
init=* ) init=${param#init=} ;;
|
||||||
|
root=* ) root=${param#root=} ;;
|
||||||
|
rootdelay=* ) rootdelay=${param#rootdelay=} ;;
|
||||||
|
rootfstype=*) rootfstype=${param#rootfstype=} ;;
|
||||||
|
rootflags=* ) rootflags=${param#rootflags=} ;;
|
||||||
|
ro ) ro="ro" ;;
|
||||||
|
rw ) ro="rw" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# udevd location depends on version
|
||||||
|
if [ -x /sbin/udevd ]; then
|
||||||
|
UDEVD=/sbin/udevd
|
||||||
|
elif [ -x /lib/udev/udevd ]; then
|
||||||
|
UDEVD=/lib/udev/udevd
|
||||||
|
else
|
||||||
|
echo "Cannot find udevd"
|
||||||
|
problem
|
||||||
|
fi
|
||||||
|
|
||||||
|
${UDEVD} --daemon --resolve-names=never
|
||||||
|
udevadm trigger
|
||||||
|
udevadm settle
|
||||||
|
|
||||||
|
if [ -f /etc/mdadm.conf ] ; then mdadm -As ; fi
|
||||||
|
if [ -x /sbin/vgchange ] ; then /sbin/vgchange -a y > /dev/null ; fi
|
||||||
|
if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi
|
||||||
|
|
||||||
|
do_mount_root
|
||||||
|
|
||||||
|
killall -w ${UDEVD##*/}
|
||||||
|
|
||||||
|
exec switch_root /.root "$init" "$@"
|
||||||
Reference in New Issue
Block a user