#!/bin/bash

使用whiptail创建格式化硬盘和开机挂载

定义变量

DEVICE="" PARTITION="" UUID=""

使用whiptail获取设备名

DEVICE=$(whiptail --title "Format Hard Drive" --inputbox "Enter device name (e.g. /dev/sda):" 10 60 /dev/sda 3>&1 1>&2 2>&3)

确认是否要格式化设备

if (whiptail --title "Format Hard Drive" --yesno "Are you sure you want to format $DEVICE?" 10 60); then # 使用whiptail获取分区名 PARTITION=$(whiptail --title "Format Hard Drive" --inputbox "Enter partition name (e.g. $DEVICE1):" 10 60 "${DEVICE}1" 3>&1 1>&2 2>&3)

# 使用whiptail获取文件系统类型
FILESYSTEM=$(whiptail --title "Format Hard Drive" --menu "Select file system type:" 10 60 3 "ext4" "" "ntfs" "" "fat32" "" 3>&1 1>&2 2>&3)

# 格式化分区
mkfs.$FILESYSTEM $PARTITION

# 获取UUID
UUID=$(blkid -o value -s UUID $PARTITION)

# 添加到fstab
echo "UUID=$UUID /mnt $FILESYSTEM defaults 0 0" >> /etc/fstab

# 创建挂载点
mkdir /mnt

# 挂载硬盘
mount -a

# 显示成功信息
whiptail --title "Format Hard Drive" --msgbox "Hard drive formatted and mounted successfully!" 10 60

else # 显示取消信息 whiptail --title "Format Hard Drive" --msgbox "Formatting cancelled." 10 60 fi

exit

whiptail写一个硬盘格式化用UUID开机挂载

原文地址: https://www.cveoy.top/t/topic/eB4t 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录