加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
partition-disk.sh 2.70 KB
一键复制 编辑 原始数据 按行查看 历史
#! /bin/sh
if [ -z "$@" ] ; then
cat << EOF
Usage:
% ${0} block-device-name
e.g. block-device-name is sda.
EOF
exit
fi
if [ ! -b /dev/${1} ] ; then
cat << EOF
/dev/${1} does not exist.
EOF
exit
fi
FSSIZE=$(( $(cat /sys/block/${1}/size)/2048-1 ))
if [ "${FSSIZE}" -gt 8192 ] ; then
cat << EOF
/dev/${1} has more than 8GB space. Enter 4GB to create a 4GB partition or between 8MB and 16MB:
EOF
read PCNT
[ "${PCNT}" = "4GB" ] && FSSIZE=4096
[ "${PCNT%MB}MB" = "${PCNT}" ] && FSSIZE=${PCNT%MB}
fi
cat << EOF
Wipe /dev/${1}? Enter YES to continue:
EOF
read WCNT
if [ "${WCNT}" != "YES" ] ; then
exit
fi
[ -b /dev/${1}2 ] && wipefs -a /dev/${1}2
[ -b /dev/${1}3 ] && dd if=/dev/zero of=/dev/${1}3 count=2014
wipefs -a /dev/${1}
parted /dev/${1} mklabel msdos
parted /dev/${1} mkpart primary fat32 1MiB "${FSSIZE}MiB"
parted /dev/${1} set 1 boot on
partprobe
sync
sleep 3
[ $FSSIZE -gt 16 ] || LABEL="-n DEEPINOS"
if [ "${#1}" -lt 4 ] ; then
mkfs.fat ${LABEL} /dev/${1}1
else
mkfs.fat ${LABEL} /dev/${1}p1
fi
[ $FSSIZE -gt 16 ] || {
parted /dev/${1} mkpart primary ext2 "${FSSIZE}MiB" -- -34s
[ "${#1}" -lt 4 ] && {
partprobe
sync
sleep 3
"${0%/*}/convert-to-gpt.sh" "${1}"
mkfs.f2fs -a 0 -e squashfs -l medium /dev/${1}2
[ -f "$(dirname ${0%/*})/Downloads/Deepin-Live.iso" ] && {
[ -d /tmp/iso ] || mkdir /tmp/iso
[ -d /tmp/usb ] || mkdir /tmp/usb
mount -o ro $(losetup --read-only --show -P -f "$(dirname ${0%/*})/Downloads/Deepin-Live.iso")p1 /tmp/iso
# Setting autoclear manually for the loop device is necessary when -P partition scan is used.
losetup --detach $(losetup -j "$(dirname ${0%/*})/Downloads/Deepin-Live.iso" | cut -d: -f1)
mount /dev/${1}1 /tmp/usb
tar cvf - -C /tmp/iso EFI | tar xf - -C /tmp/usb
tar cvf - --no-recursion -C /tmp/iso boot | tar xf - -C /tmp/usb
umount /tmp/usb
mount /dev/${1}2 /tmp/usb
tar cvf - --exclude EFI --exclude isolinux -C /tmp/iso . | tar xf - -C /tmp/usb
sync
umount /tmp/usb
umount --detach-loop /tmp/iso
rmdir /tmp/iso /tmp/usb
}
cat << EOF
Create BIOS/GPT boot partition? Type YES to continue:
EOF
read WCNT
if [ "${WCNT}" != "YES" ] ; then
exit
fi
parted /dev/${1} mkpart " " fat16 34s 2047s Ignore align-check min 3
parted /dev/${1} set 3 bios_grub on
partprobe
sync
sleep 1
udisksctl mount --block-device /dev/${1}2
findmnt --noheadings --output=target /dev/${1}2 && {
grub-install --target=i386-pc --debug --boot-directory="$(findmnt --noheadings --output=target /dev/${1}2)/boot" /dev/${1}
udisksctl unmount --block-device /dev/${1}2
}
}
exit
}
cat << EOF
Now, run Deepin Boot Maker to install your ISO to disk.
EOF
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化