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

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

Force reloading partition schema when creating partitions

  • Property svn:executable set to *
File size: 2.9 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 -l ${device}? || true
71# Delete partitions table
72dd if=/dev/zero of=$device bs=512 count=1
73# Refresh partitions
74partprobe ${device}
75# Create new partitions table
76parted -s $device mklabel msdos
77# Create vfat 35 Mb partition with boot flag
78parted -a minimal -s $device mkpart primary fat32 '0%' 50
79parted -a minimal -s $device set 1 boot on
80parted -a minimal -s $device mkpart primary ext4 50 '100%'
81# Refresh partitions
82partprobe ${device}
83# Format partition
84partition_boot=$(get_first_partition $device boot)
85partition_system=$(get_first_partition $device system)
86if [ "$partition_boot" = "" -o "$partition_system" = "" ];then
87        echo "error"
88        exit 1
89fi
90mkfs.vfat -F 32 ${partition_boot}
91mkfs.ext4 -q -F ${partition_system}
92# Mount partition
93path_sd="/media/llxberry_$RANDOM"
94mkdir -p $path_sd
95mount ${partition_system} $path_sd
96mkdir -p $path_sd/boot
97mount ${partition_boot} $path_sd/boot
98
99if [ ! -d "${temp_dir}/fs/etc" ]; then
100    data_path=$(llx-berry-manager ${temp_dir}/fs/)
101else
102    data_path=$temp_dir/fs/
103fi
104
105# Cp berryboot files
106rsync -aHAXS "$data_path"/ $path_sd/
107
108# TODO
109# Modify cmdline.txt and replace _@_server_@_ by SRV_IP n4d var
110#
111#eval `n4d-vars getvalues SRV_IP`
112#sed -i -e "s%_@_SRV_IP_@_%${SRV_IP}%g" ${path_sd}/cmdline.txt
113echo 0 > /proc/sys/kernel/hung_task_timeout_secs
114sync
115echo 120 > /proc/sys/kernel/hung_task_timeout_secs
116umount $path_sd/boot
117umount $path_sd
118rm -rf $path_sd
119
120rm /var/run/remove_partitions
121rm $temp_dir/.lock
122# This line is very important to n4d clients
123echo "Ok"
Note: See TracBrowser for help on using the repository browser.