(none) /root> cat `which setup.sh`
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# Harddisk Partition
# /dev/sda1: /boot
# /dev/sda2: /apps
# /dev/sda3: swap
# /dev/sda4: extend
# /dev/sda5: /db
# /dev/sda6: /var/log
# /dev/sda7: /storage
cd /
umask 077
RAID_CHECK=""
#RAID_USE=`product -r`
RAID_USE="off"
devfind
OS="/dev/os"
APPS="/dev/apps"
SWAP="/dev/swap"
DB="/dev/db"
LOG="/dev/varlog"
STORAGE="/dev/storage"
if [ $RAID_USE = on ] ; then
RAID_CHECK="set"
HARD_DISK="/dev/md"
else
RAID_CHECK="unset"
CHECK_DISK0="`fdisk -l "/dev/sda" |grep "/dev/sda:" |awk '{print $4 }'|tr -d "," | tr -d "\n"`"
CHECK_DISK1="`fdisk -l "/dev/sdb" |grep "/dev/sdb:" |awk '{print $4 }'|tr -d "," | tr -d "\n"`"
if [ $CHECK_DISK0 = "GB" ]; then
HARD_DISK0="/dev/sda"
HARD_DISK1="/dev/sdb"
elif [ $CHECK_DISK1 = "GB" ]; then
HARD_DISK0="/dev/sdb"
HARD_DISK1="/dev/sdc"
fi
fi
umount_dev()
{
killall5
sleep 5
umount $STORAGE
umount $DB
umount $APPS
umount $OS
swapoff -a
umount $LOG
}
partitioning()
{
DEV="$1"
dd if=/dev/zero of=$DEV bs=512 count=1
fdisk $DEV <<EOF
n
p
1
+8192
n
p
2
+20480M
n
p
3
+10240M
n
e
n
+102400M
n
+20480M
n
w
EOF
}
change_raid_type()
{
DEV="$1"
fdisk $DEV <<EOF
t
1
fd
t
2
fd
t
3
fd
t
5
fd
t
6
fd
t
7
fd
w
EOF
}
create_md()
{
if [ CHECK_DISK0 = "GB" ]; then
yes | mdadm --create /dev/md0 -f -e 0.90 --level=mirror --raid-devices=2 /dev/sda1 /dev/sdb1
yes | mdadm --create /dev/md1 -f --level=mirror --raid-devices=2 /dev/sda2 /dev/sdb2
yes | mdadm --create /dev/md2 -f --level=mirror --raid-devices=2 /dev/sda3 /dev/sdb3
yes | mdadm --create /dev/md3 -f --level=mirror --raid-devices=2 /dev/sda5 /dev/sdb5
yes | mdadm --create /dev/md4 -f --level=mirror --raid-devices=2 /dev/sda6 /dev/sdb6
yes | mdadm --create /dev/md5 -f --level=mirror --raid-devices=2 /dev/sda7 /dev/sdb7
else
yes | mdadm --create /dev/md0 -f -e 0.90 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sda1
yes | mdadm --create /dev/md1 -f --level=mirror --raid-devices=2 /dev/sdb2 /dev/sda2
yes | mdadm --create /dev/md2 -f --level=mirror --raid-devices=2 /dev/sdb3 /dev/sda3
yes | mdadm --create /dev/md3 -f --level=mirror --raid-devices=2 /dev/sdb5 /dev/sda5
yes | mdadm --create /dev/md4 -f --level=mirror --raid-devices=2 /dev/sdb6 /dev/sda6
yes | mdadm --create /dev/md5 -f --level=mirror --raid-devices=2 /dev/sdb7 /dev/sda7
fi
}
change_normal_type()
{
DEV="$1"
fdisk $DEV <<EOF
t
3
83
w
EOF
}
make_fdisk()
{
#DISK_SIZE="`fdisk -l "/dev/sda" |grep Disk |awk '{print $3 }'`"
#echo ""
#echo "### Make disk partition: $DISK_SIZE GB"
#partitioning "/dev/sdb"
partitioning $HARD_DISK0
if [ $RAID_CHECK = "set" ]; then
#partitioning "/dev/sdb"
partitioning $HARD_DISK0
fi
if [ $RAID_CHECK = "set" ]; then
change_raid_type $HARD_DISK0
change_raid_type $HARD_DISK1
else
change_normal_type $HARD_DISK0
fi
}
create_mkfs() {
echo ""
echo "### [create_mkfs] Make disk filesystem -------------------------------------"
devfind
mkfs.ext3 $OS
mkfs.ext3 $APPS
mkswap $SWAP
mkfs.ext3 $DB
mkfs.ext3 $LOG
mkfs.ext3 $STORAGE
}
copy_files() {
TMP=""
SRC_DEV=""
echo ""
echo "### [copy_files] -------------------------------------"
devfind
SRC=/mnt/src
TARGET=/mnt/target
TMP=$(blkid /dev/usb | grep "SNACK_BOOT" | awk '{print $1}' | tr -d ":")
if [ -n $TMP ]; then
SRC_DEV=$TMP
else
TMP=$(blkid | grep "SNACK_BOOT" | awk '{print $1}' | tr -d ":")
SRC_DEV=$TMP
fi
mkdir -p $SRC
mkdir -p $TARGET
mount $SRC_DEV $SRC
mount $OS $TARGET
cp -rf $SRC/$(uname -m)/* $TARGET/
#opkg install $SRC/$(uname -m)/apps/ac-app_*.opk
umount $SRC
umount $TARGET
}
install_grub() {
echo ""
echo "### [install_grub] -------------------------------------"
HD="$1"
grub <<EOF
root ($HD,0)
find /boot/grub/stage1
setup ($HD)
quit
EOF
}
create_hard_disk() {
echo ""
echo "### [create_hard_disk] -------------------------------------"
umount_dev
devfind
make_fdisk
if [ $RAID_USE = on ] ; then
create_md
fi
create_mkfs
copy_files
if [ $HARD_DISK0 = "/dev/sda" ]; then
install_grub hd0
elif [ $HARD_DISK0 = "/dev/sdb" ]; then
install_grub hd1
fi
if [ $RAID_USE = on ] ; then
install_grub hd1
fi
}
recovery() {
echo ""
echo "### [recovery] -------------------------------------"
TARGET=/mnt/target
mkdir -p $TARGET
mount $OS $TARGET
if [ "_$?" != "_0" ]; then
umount_dev
make_fdisk
mkfs.ext3 $OS
fi
umount $TARGET
copy_files
install_grub hd0
if [ $RAID_USE = on ] ; then
install_grub hd1
fi
}
disk_sync()
{
partitioning "/dev/sdb"
change_raid_type "/dev/sdb"
mdadm -S --scan
create_md
/etc/init.d/raid.sh
}
disk_check()
{
DISK=$1
geometry_num=`fdisk -l "$DISK" | grep Linux |wc -l | awk '{print $1}'`
if [ "_$geometry_num" != "_6" ]; then
echo "WARNING: Data disk is $DISK incorrect"
echo " Please repair filesystem ($0 force-start)"
return 1;
else
echo "Data disk $DISK is OK"
return 0;
fi
return 0;
}
devfind
case "$1" in
start)
geometry_num=`fdisk -l "/dev/sda" | grep Linux |wc -l | awk '{print $1}'`
if [ "_$geometry_num" != "_6" ]; then
create_hard_disk ;
fi
;;
status)
disk_check "/dev/sda"
if [ $RAID_USE = on ] ; then
disk_check "/dev/sdb"
fi
;;
force-start)
devfind
create_hard_disk
echo "Data disk is initialized... please reboot"
echo -n "Do you want to reboot this system right now? [NO/yes] "
read answer
if [ x$answer = "xyes" ]; then
/sbin/reboot
else
echo "You may reboot this system later."
echo ""
fi
;;
boot)
if [ $HARD_DISK0 = "/dev/sda" ]; then
install_grub hd0
elif [ $HARD_DISK0 = "/dev/sdb" ]; then
install_grub hd1
fi
if [ $RAID_USE = on ] ; then
install_grub $HARD_DISK1
fi
;;
sync)
if [ $RAID_USE = on ] ; then
disk_check "/dev/sdb"
ret=$?
if [ $ret = 1 ] ; then
disk_sync
fi
fi
;;
recovery)
echo "Recover boot file & grub"
echo ""
recovery
;;
file-copy)
echo "***Copy File"
echo ""
copy_files
;;
test-fdisk)
echo "*** test fdisk"
echo ""
make_fdisk
;;
*)
echo "USAGE: $0 {start|status|force-start|boot|recovery|sync|file-copy}"
exit 1
;;
esac
exit 0
(none) /root>
'프로...Linux' 카테고리의 다른 글
[FS/mtd] mtd 관련 작업 (0) | 2019.01.10 |
---|---|
[Info] Check HW information (0) | 2018.12.21 |
[util] partition/mount - fdisk/lsblk(blkid)/df/mount (0) | 2018.12.14 |
[SVN] Repository 추가 생성 (0) | 2018.11.15 |
[sh] bourne shell(sh)에서 rand 사용법 (0) | 2018.11.06 |