source: n4d-lliurexberry/trunk/fuentes/install/usr/sbin/create_llxberry_sd @ 5876

Last change on this file since 5876 was 5876, checked in by mabarracus, 3 years ago

Avoid hung task kernel warnings when sync data

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/bin/bash
2today=$(date '+%Y%m%d')
3data_version=$(dpkg-query -f='${Version}' -W lliurexberry-data|tr -c '[:alnum:]' '_')
4diff_version=$(dpkg-query -f='${Version}' -W n4d-lliurexberry|tr -c '[:alnum:]' '_')
5
6temp_dir="/tmp/llxberry_${today}_${data_version}_${diff_version}"
7
8if [ -f "${temp_dir}/.lock" ];then
9    logger "Unable to run 'create_llxberry_sd', ${temp_dir} is locked!"
10    exit 1
11else
12    if [ ! -d "${temp_dir}" ]; then
13        mkdir -p ${temp_dir}/fs
14    fi
15    touch ${temp_dir}/.lock
16fi
17
18
19if [ ! -e /var/run/remove_partitions ]; then
20        echo "not exists /var/run/remove_partitions."
21        rm ${temp_dir}/.lock
22        exit 1
23fi
24#
25# Check root permission
26#
27token_name="/var/run/remove_partitions_root_$RANDOM"
28touch $token_name 2> /dev/null || true
29if [ ! -e "$token_name" ]; then
30        echo "not exists /var/run/remove_partitions."
31        rm ${temp_dir}/.lock
32        exit 1
33fi
34rm $token_name
35
36#
37# Device is not null
38#
39if [ "$1" = "" ];then
40        echo "device is null"
41        exit 1
42fi
43
44#
45# Device exist
46#
47device="/dev/$1"
48if [ ! -e "$device" ]; then
49        echo "device not exists"
50        exit 1
51fi
52
53#
54# Device is removable
55#
56if [ "$2" != "--ignore-removable"  ];then 
57        removable=$(cat /sys/block/$1/removable)
58        if [ "$removable" = "0" ]; then
59                echo "device isn't removable"
60                ##
61                ## Dialog para preguntar si se esta seguro
62                echo "Device $1 isn't removable. Write yes to continue"
63                read pass
64                if [ "$pass" != "yes" ]; then
65                        exit 1
66                fi
67        fi
68fi
69
70umount ${device}? || true
71# Delete partitions table
72dd if=/dev/zero of=$device bs=512 count=1
73# Create new partitions table
74parted -s $device mklabel msdos
75# Create vfat 35 Mb partition with boot flag
76parted -a minimal -s $device mkpart primary fat32 '0%' 50
77parted -a minimal -s $device set 1 boot on
78parted -a minimal -s $device mkpart primary ext4 50 '100%'
79# Format partition
80partition_boot=$(get_first_partition $device boot)
81partition_system=$(get_first_partition $device system)
82if [ "$partition_boot" = "" -o "$partition_system" = "" ];then
83        echo "error"
84        exit 1
85fi
86mkfs.vfat -F 32 ${partition_boot}
87mkfs.ext4 -q -F ${partition_system}
88# Mount partition
89path_sd="/media/llxberry_$RANDOM"
90mkdir -p $path_sd
91mount ${partition_system} $path_sd
92mkdir -p $path_sd/boot
93mount ${partition_boot} $path_sd/boot
94
95if [ ! -d "${temp_dir}/fs/etc" ]; then
96    data_path=$(llx-berry-manager ${temp_dir}/fs/)
97else
98    data_path=$temp_dir/fs/
99fi
100
101# Cp berryboot files
102rsync -aHAXS "$data_path"/ $path_sd/
103
104# TODO
105# Modify cmdline.txt and replace _@_server_@_ by SRV_IP n4d var
106#
107#eval `n4d-vars getvalues SRV_IP`
108#sed -i -e "s%_@_SRV_IP_@_%${SRV_IP}%g" ${path_sd}/cmdline.txt
109echo 0 > /proc/sys/kernel/hung_task_timeout_secs
110sync
111echo 120 > /proc/sys/kernel/hung_task_timeout_secs
112umount $path_sd/boot
113umount $path_sd
114rm -rf $path_sd
115
116rm /var/run/remove_partitions
117rm $temp_dir/.lock
118# This line is very important to n4d clients
119echo "Ok"
Note: See TracBrowser for help on using the repository browser.