Initial commit
This commit is contained in:
45
files/initramfs/crypt_unlock.sh
Normal file
45
files/initramfs/crypt_unlock.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
PREREQ="dropbear"
|
||||
|
||||
prereqs() {
|
||||
echo "$PREREQ"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
prereqs)
|
||||
prereqs
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
. "${CONFDIR}/initramfs.conf"
|
||||
. /usr/share/initramfs-tools/hook-functions
|
||||
|
||||
if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/crypttab" ] ; then
|
||||
cat > "${DESTDIR}/bin/unlock" << EOF
|
||||
#!/bin/sh
|
||||
if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then
|
||||
kill \`ps | grep cryptroot | grep -v "grep" | awk '{print \$1}'\`
|
||||
# following line kill the remote shell right after the passphrase has
|
||||
# been entered.
|
||||
kill -9 \`ps | grep "\-sh" | grep -v "grep" | awk '{print \$1}'\`
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
EOF
|
||||
|
||||
chmod 755 "${DESTDIR}/bin/unlock"
|
||||
|
||||
mkdir -p "${DESTDIR}/lib/unlock"
|
||||
cat > "${DESTDIR}/lib/unlock/plymouth" << EOF
|
||||
#!/bin/sh
|
||||
[ "\$1" == "--ping" ] && exit 1
|
||||
/bin/plymouth "\$@"
|
||||
EOF
|
||||
|
||||
chmod 755 "${DESTDIR}/lib/unlock/plymouth"
|
||||
|
||||
echo To unlock root-partition run "unlock" >> ${DESTDIR}/etc/motd
|
||||
|
||||
fi
|
||||
19
files/initramfs/expand-premount
Executable file
19
files/initramfs/expand-premount
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Check for cryptdevice variable
|
||||
if [ -z "$cryptdevice" ] ; then
|
||||
echo "unable to get cryptdevice variable (local-premount)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$ROOT" ] ; then
|
||||
# Resize encrypted root partition
|
||||
cryptsetup resize "${ROOT}"
|
||||
e2fsck -fp "${ROOT}"
|
||||
resize2fs -f "${ROOT}"
|
||||
e2fsck -fp "${ROOT}"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
19
files/initramfs/expand-tools
Executable file
19
files/initramfs/expand-tools
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Use initramfs utility functions
|
||||
. /usr/share/initramfs-tools/hook-functions
|
||||
|
||||
# Add binaries required for resizing the filesystem
|
||||
copy_exec /bin/grep /bin
|
||||
copy_exec /usr/bin/awk /bin
|
||||
copy_exec /usr/bin/cut /bin
|
||||
copy_exec /usr/bin/tail /bin
|
||||
copy_exec /sbin/fdisk /sbin
|
||||
copy_exec /sbin/parted /sbin
|
||||
copy_exec /sbin/e2fsck /sbin
|
||||
copy_exec /sbin/resize2fs /sbin
|
||||
copy_exec /sbin/partprobe /sbin
|
||||
|
||||
exit 0
|
||||
96
files/initramfs/expand_encrypted_rootfs
Normal file
96
files/initramfs/expand_encrypted_rootfs
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
# expand_encrypted_rootfs initramfs-tools boot script
|
||||
|
||||
# dependencies: grep awk cut tail fdisk parted e2fsck resize2fs
|
||||
|
||||
set -e
|
||||
|
||||
# Wait for USB devices to be ready
|
||||
sleep 5
|
||||
|
||||
# Use initramfs utility functions
|
||||
if [ -r "/scripts/functions" ] ; then
|
||||
. /scripts/functions
|
||||
fi
|
||||
|
||||
# Check for cryptdevice variable
|
||||
if [ -z "$cryptdevice" ] ; then
|
||||
echo "unable to get cryptdevice variable (init-premount)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Detect root partition device
|
||||
ROOT_PART=$(echo $cryptdevice | awk -F"/|:" '{ print $3 }')
|
||||
if [ -z "$ROOT_PART" ] ; then
|
||||
log_warning_msg "unable to detect encrypted root partition device (cryptdevice)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract root device name
|
||||
case "${ROOT_PART}" in
|
||||
mmcblk0*) ROOT_DEV=mmcblk0 ;;
|
||||
sda*) ROOT_DEV=sda ;;
|
||||
esac
|
||||
|
||||
# Check detected root partition name
|
||||
PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
|
||||
if [ "$PART_NUM" = "$ROOT_PART" ] ; then
|
||||
log_warning_msg "$ROOT_PART is not an SD card. Don't know how to expand"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
|
||||
# agree to work with a sufficiently simple partition layout
|
||||
if [ "$PART_NUM" -gt 2 ] ; then
|
||||
log_warning_msg "Your partition layout is not currently supported by this tool."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if last partition number
|
||||
LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
|
||||
log_warning_msg "$ROOT_PART is not the last partition. Don't know how to expand"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get the starting offset of the root partition
|
||||
PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
|
||||
if [ -z "$PART_START" ] ; then
|
||||
log_warning_msg "${ROOT_DEV} unable to get starting sector of the partition"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get the current last sector of the root partition
|
||||
PART_END=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 3 -d: | sed 's/[^0-9]//g')
|
||||
if [ -z "$PART_END" ] ; then
|
||||
log_warning_msg "${ROOT_DEV} unable to get last sector of the partition"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get the possible last sector for the root partition
|
||||
PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
|
||||
if [ -z "$PART_LAST" ] ; then
|
||||
log_warning_msg "${ROOT_DEV} unable to get last possible sector of the partition"
|
||||
return 1
|
||||
fi
|
||||
|
||||
### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
|
||||
if [ $PART_END != $PART_LAST ] ; then
|
||||
fdisk /dev/${ROOT_DEV} 2> /dev/null <<EOF2 || true
|
||||
p
|
||||
d
|
||||
$PART_NUM
|
||||
n
|
||||
p
|
||||
$PART_NUM
|
||||
$PART_START
|
||||
$PART_LAST
|
||||
p
|
||||
w
|
||||
EOF2
|
||||
|
||||
partprobe
|
||||
log_success_msg "Root partition successfully resized."
|
||||
else
|
||||
log_success_msg "Root partition already resized."
|
||||
fi
|
||||
Reference in New Issue
Block a user