Files
new_install/operation/format_partition.sh
Qin Bo 02dbaa792b modify follow files for new datastructure
modified:   interface/ri_data.py
    remove MountPoint use new datastructure for instead

modified:   interface/ri_install.py
    add MakePartitions for partition

modified:   interface/ri_oper.py
    1.add MakePartitions class
    2.modify Format, Mount, ConfigureFstab class

modified:   new_partition/partition_data.py
    1.add disk_from_os attribute to Partition class for disk
    2.add process linux-swap(v1) in Partition class
    3.force convert num and sn to int, beacause when read from install.xml
      sn and num is still string.

modified:   operation/format_partition.sh
    1.add timeout beacause use MakePartitions, need time to generate
    device file
    2.add linux-swap for swap

modified:   operation/functions
    1.add % support, beacause of partition may use 1% to partition
    disks.

new file:   operation/partition_disks.sh
    1.use partition_disks as parted stdin wrapper.

Signed-off-by: Qin Bo <bqin@linx-info.com>
2013-12-04 19:16:16 +08:00

120 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
#
# DESCRIPTION: formating partition with a filesystem
# if have duplicate partition, it will format the finally filesystem type.
#
# SCRIPT NAME: format_partition.sh
#
# Usage: echo "/dev/sda1 ext2" | ./format_partition.sh
#
# Input: stdin
# 1. partition
# 2. filesystem type
#
# Output:
# success:
# @ format $devname success
# Return value:
# 1 argument error
# 2 deivce node doesn't exist
# 3 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 have 2 arguments !"
return 1
fi
local devname="$1"
local fs_type="$2"
if [ ! -e "$devname" ];then
# wait for device
for((i=0;i<10;i++))do
[ -e "$devname" ] && break
sleep $i
done
if [ ! -e "$devname" ];then
err "$devname node doesn't exist !"
return 2
fi
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 1>>"$DEV_LOG" 2>&1
fi
info "formating device "$devname" as "$fs_type" filesystem"
case ${fs_type} in
ext2)
mkfs.ext2 -F -I 128 "$devname" 1>>"$DEV_LOG" 2>&1
;;
ext3)
mkfs.ext3 -F -I 128 "$devname" 1>>"$DEV_LOG" 2>&1
;;
ext4)
mkfs.ext4 -F -I 128 "$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|linux-swap)
mkswap -f "$devname" 1>>"$DEV_LOG" 2>&1
;;
vfat)
mkfs.vfat "$devname" 1>>"$DEV_LOG" 2>&1
;;
*)
err ""$fs_type" filesystem no implement yet !"
return 3
;;
esac
}
main ()
{
local line
while read line;do
if [ -n "$line" ];then
# Notice: don't use "$line"
format_partition $line
erv
info "format $(echo $line|awk '{print $1}') success" stdout
fi
done
}
main "$@"
# vim:set ts=4 sw=4;