Files
new_install/operation/format_partition.sh
lizhi-rocky 220e6bfe40 add Qin Bo's operating shell scripts in
rename directory 'python' to 'interface', for I think it is a better name for its included python scripts function.
2010-09-03 15:59:49 +08:00

107 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
#
# DESCRIPTION: formating partition with a filesystem
# NOTICE: if have duplicate partition, it will format the final filesystem type.
#
# SCRIPT NAME: format_partition.sh
#
# Usage: echo "/dev/sda1 ext2" | ./format_partition.sh
#
# Input: stdin
# 1. partition
# 2. filesystem type
# 1,2 separate with space
#
# Output:
# 0 success
# 1 argument error
# 2 lack input (reserve)
# 3 deivce node doesn't exist
# 4 filesystem no implement
# 127 format partition utils not found
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-05
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-05 create
#
#
#
source ./functions
# ex: format_partition /dev/sda1 ext3
format_partition ()
{
if [ $# -ne 2 ];then
err "$FUNCNAME function argument error, it must be 2 !"
return 1
fi
devname="$1"
fs_type="$2"
if [ ! -e "$devname" ];then
err "$devname node doesn't exist !"
return 3
fi
# partition may be used to swap, or has already mounted
if grep -q "^$devname " /proc/swaps ;then
swapoff "$devname"
elif grep -q "^$devname " /proc/mounts;then
reumount $devname >"$dev_LOG" 2>&1
fi
info "formating device "$devname" as "$fs_type" filesystem"
case ${fs_type} in
ext2)
mkfs.ext2 -F "$devname" 1>"$dev_LOG" 2>&1
;;
ext3)
mkfs.ext3 -F "$devname" 1>"$dev_LOG" 2>&1
;;
reiserfs)
yes | mkfs.reiserfs -f "$devname" 1>"$dev_LOG" 2>&1
;;
xfs)
yes | mkfs.xfs -f "$devname" 1>"$dev_LOG" 2>&1
;;
jfs)
yes | mkfs.jfs -q "$devname" 1>"$dev_LOG" 2>&1
;;
swap)
mkswap -f "$devname" 1>"$dev_LOG" 2>&1
swapon "$devname"
;;
fat)
mkfs.vfat "$devname" 1>"$dev_LOG" 2>&1
;;
*)
err ""$fs_type" filesystem no implement yet !"
return 4
;;
esac
}
main ()
{
while read line;do
if [ -n "$line" ];then
# Notice: don't use "$line"
format_partition $line
erv
fi
done
}
main $@
# vim:set ts=4 sw=4;