Created
July 10, 2018 09:47
-
-
Save pandax381/757a0c941b6ce03ad85b7164c85827d0 to your computer and use it in GitHub Desktop.
/usr/share/initramfs-tools/scripts/image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- shell-script -*- | |
image_mount_storage() | |
{ | |
local mnt="$1" | |
local_top | |
local_device_setup "${ROOT}" "usb storage" | |
ROOT="${DEV}" | |
# Default delay is around 10s | |
delay=${ROOTDELAY:-10} | |
retry_count=0 | |
# loop until usb storage found | |
while [ ${retry_count} -lt ${delay} ] && [ ! -e ${ROOT} ] ; do | |
[ "$quiet" != "y" ] && log_begin_msg "Wait ${ROOT} found" | |
/bin/sleep 1 | |
retry_count=$(( ${retry_count} + 1 )) | |
[ "$quiet" != "y" ] && log_end_msg | |
done | |
# Get the root filesystem type if not set | |
if [ -z "${ROOTFSTYPE}" ]; then | |
FSTYPE=$(get_fstype "${ROOT}") | |
else | |
FSTYPE=${ROOTFSTYPE} | |
fi | |
local_premount | |
if [ "${readonly}" = "y" ]; then | |
roflag=-r | |
else | |
roflag=-w | |
fi | |
# FIXME This has no error checking | |
modprobe ${FSTYPE} | |
checkfs ${ROOT} ${mnt} "${FSTYPE}" | |
# FIXME This has no error checking | |
# Mount root | |
if [ "${FSTYPE}" != "unknown" ]; then | |
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${mnt} | |
else | |
mount ${roflag} ${ROOTFLAGS} ${ROOT} ${mnt} | |
fi | |
} | |
image_mount_root() | |
{ | |
local mnt="/boot" | |
local image="rootfs.cpio.gz" | |
local tmpfs= | |
for x in $(cat /proc/cmdline); do | |
case ${x} in | |
image=*) | |
image=${x#image=} | |
;; | |
tmpfs=*) | |
tmpfs=${x#tmpfs=} | |
;; | |
esac | |
done | |
modprobe usb_storage | |
wait_for_udev 10 | |
[ "$quiet" != "y" ] && log_begin_msg "Creating tmpfs ${tmpfs}" | |
if [ -z "${tmpfs}" ]; then | |
mount -t tmpfs tmpfs ${rootmnt} | |
else | |
mount -t tmpfs -o size=${tmpfs} tmpfs ${rootmnt} | |
fi | |
[ "$quiet" != "y" ] && log_end_msg | |
if [ ! -e ${mnt} ]; then | |
mkdir ${mnt} | |
fi | |
image_mount_storage ${mnt} | |
[ "$quiet" != "y" ] && log_begin_msg "Extracting ${image}" | |
cd ${rootmnt} && zcat ${mnt}/${image} | cpio -idm | |
[ "$quiet" != "y" ] && log_end_msg | |
umount ${mnt} | |
} | |
mountroot() | |
{ | |
image_mount_root | |
} | |
mount_top() | |
{ | |
: | |
} | |
mount_premount() | |
{ | |
: | |
} | |
mount_bottom() | |
{ | |
: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of GRUB entry