mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-07-28 03:01:54 +08:00
40 lines
1.3 KiB
Bash
40 lines
1.3 KiB
Bash
#!/bin/sh
|
|
|
|
function NEWPART(){
|
|
ROOT_DISK=$1
|
|
# 检查是否有未分配空间
|
|
DISK_SIZE=$(parted -s $ROOT_DISK unit MB print | grep '^Disk' | awk '{print $3}' | sed 's/MB//')
|
|
LAST_PART_END=$(parted -s $ROOT_DISK unit MB print | tail -n 2 | head -n 1 | awk '{print $3}' | sed 's/MB//')
|
|
[ $LAST_PART_END == "End" ] && return 0
|
|
UNALLOCATED_SPACE="$(awk "BEGIN {print $DISK_SIZE - $LAST_PART_END}")"
|
|
awk 'BEGIN {exit !('$UNALLOCATED_SPACE' >= '1024')}' && {
|
|
# 创建新分区
|
|
parted -s $ROOT_DISK mkpart primary ext4 ${LAST_PART_END}MB 100% && {
|
|
|
|
ROOT_DISK_NAME="$(echo $ROOT_DISK | cut -d / -f 3)"
|
|
LAST_PART_NAME="$(lsblk -nlo NAME | grep $ROOT_DISK_NAME | tail -n 1)"
|
|
# 格式化新分区
|
|
mkfs.ext4 -F -L "docker" /dev/${LAST_PART_NAME}
|
|
pgrep -x /usr/bin/dockerd > /dev/null && /etc/init.d/dockerd stop
|
|
mkdir -p /opt/docker
|
|
eval $(block info /dev/${LAST_PART_NAME} | grep -o -e 'UUID="\S*"')
|
|
[ ! -f /etc/config/fstab ] && ( block detect > /etc/config/fstab )
|
|
uci set fstab.mountdocker="mount"
|
|
uci set fstab.mountdocker.uuid="${UUID}"
|
|
uci set fstab.mountdocker.target="/opt/docker"
|
|
uci commit fstab
|
|
umount -f /dev/${LAST_PART_NAME}
|
|
/sbin/block mount
|
|
}
|
|
}
|
|
}
|
|
|
|
cat /etc/mtab | grep -q "/opt/docker" || {
|
|
uci -q get fstab.mountdocker || {
|
|
disk="$(lsblk | awk '/disk/ {print $1; exit}')"
|
|
NEWPART /dev/$disk
|
|
}
|
|
}
|
|
|
|
exit 0
|