Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pandax381
Created July 10, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandax381/757a0c941b6ce03ad85b7164c85827d0 to your computer and use it in GitHub Desktop.
Save pandax381/757a0c941b6ce03ad85b7164c85827d0 to your computer and use it in GitHub Desktop.
/usr/share/initramfs-tools/scripts/image
# -*- 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()
{
:
}
@pandax381
Copy link
Author

Example of GRUB entry

menuentry 'Debian GNU/Linux (USB Boot)' {
  load_video
  insmod gzio
  insmod ext2
  echo 'Loading vmlinuz ...'
  linux /vmlinuz root=LABEL=USB_BOOT ro boot=image image=rootfs.cpio.gz tmpfs=8192M
  echo 'Loading initrd ...'
  initrd /initrd.img
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment