|
15
by Oliver Grawert
add proper headers to initramfs scripts |
1 |
#!/bin/sh -e
|
2 |
||
|
117
by Oliver Grawert
add fixrtc to prereqs |
3 |
PREREQ="fixrtc" |
|
15
by Oliver Grawert
add proper headers to initramfs scripts |
4 |
|
5 |
# Output pre-requisites
|
|
6 |
prereqs()
|
|
7 |
{
|
|
8 |
echo "$PREREQ" |
|
9 |
}
|
|
10 |
||
11 |
case "$1" in |
|
12 |
prereqs)
|
|
13 |
prereqs |
|
14 |
exit 0
|
|
15 |
;; |
|
16 |
esac
|
|
|
1
by Oliver Grawert
initial checkin |
17 |
|
18 |
DISK=mmcblk0 |
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
19 |
SEP="p" |
20 |
||
|
26
by Oliver Grawert
jasper_growroot: rework logging |
21 |
LOG=/dev/.initramfs/jasper.log |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
22 |
CACHE=/dev/.initramfs/jasper-vfat |
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
23 |
|
|
26
by Oliver Grawert
jasper_growroot: rework logging |
24 |
touch ${LOG} |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
25 |
mkdir -p ${CACHE} |
26 |
||
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
27 |
BOOTPATH="" |
28 |
PARTITION="" |
|
|
116
by Oliver Grawert
add plymouth support to user readable output |
29 |
MYECHO="echo " |
30 |
||
31 |
if [ -x /bin/plymouth ] && plymouth --ping; then |
|
32 |
MYECHO="plymouth message --text=" |
|
33 |
fi
|
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
34 |
|
35 |
# we only handle mmc and sdX disk types atm if a UUID is already set we dont want
|
|
36 |
# to do any action since we assume the system was configured before
|
|
37 |
[ -z "`grep root=UUID /proc/cmdline`" ] || exit 0 |
|
38 |
for arg in $(cat /proc/cmdline) |
|
39 |
do
|
|
40 |
case $arg in |
|
41 |
root=*) |
|
42 |
BOOTPATH=${arg#root=} |
|
43 |
PARTITION=${BOOTPATH#/dev/} |
|
44 |
case $PARTITION in |
|
45 |
mmcblk*)
|
|
46 |
DISK=$(echo ${PARTITION}|sed -e 's/p[0-9]*$//') |
|
47 |
;; |
|
48 |
sd*)
|
|
49 |
DISK=$(echo ${PARTITION}|sed -e 's/[0-9]*$//') |
|
50 |
SEP="" |
|
51 |
;; |
|
52 |
*)
|
|
|
116
by Oliver Grawert
add plymouth support to user readable output |
53 |
$MYECHO"E: Jasper error, can not handle this disk type" |
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
54 |
exit 1
|
55 |
;; |
|
56 |
esac
|
|
57 |
;; |
|
58 |
esac
|
|
59 |
done
|
|
60 |
||
|
114
by Oliver Grawert
scripts/local-premount/jasper_growroot fix exporting of root device |
61 |
export ROOTDEV="/dev/${DISK}${SEP}" |
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
62 |
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
63 |
# We save the vfat contents because we adjust the CHS gemoetry to match the SD card,
|
64 |
# MLO/u-boot wont work without re-formatting the vfat with the new values
|
|
65 |
cache_vfat()
|
|
66 |
{
|
|
67 |
mount -t tmpfs -o mode=0755 none ${CACHE} |
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
68 |
mkdir -p /mnt |
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
69 |
mount -t vfat ${ROOTDEV}1 /mnt |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
70 |
cp -a /mnt/* ${CACHE}/ |
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
71 |
umount ${ROOTDEV}1 |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
72 |
}
|
73 |
||
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
74 |
# Format the new vfat and write the cached content back in the right order
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
75 |
write_vfat()
|
76 |
{
|
|
|
35
by Oliver Grawert
add TODO note for partition label |
77 |
# TODO: find a better LABEL and add it to list of hidden partitions in udisk
|
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
78 |
/sbin/mkdosfs -n "SERVICEV001" -F 32 ${ROOTDEV}1 |
79 |
mount ${ROOTDEV}1 /mnt |
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
80 |
for file in MLO boot.scr u-boot.bin uImage uInitrd; do |
81 |
cp ${CACHE}/$file /mnt/${file} |
|
|
43
by Oliver Grawert
jasper_growroot: dont call sync with full path, it makes the script choke |
82 |
sync |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
83 |
done
|
84 |
umount ${CACHE} |
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
85 |
umount /mnt |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
86 |
}
|
87 |
||
88 |
# The actual resizing function
|
|
|
1
by Oliver Grawert
initial checkin |
89 |
resize_partitions()
|
90 |
{
|
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
91 |
# Get size in blocks of first partition and cylinder count
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
92 |
SIZE_P1=`LANG=C /sbin/fdisk -l /dev/${DISK} | grep ${DISK}${SEP}1 | awk '{print $4}'` |
|
25
by Oliver Grawert
jasper_growroot: rework partitioning code |
93 |
DISKSIZE=`LANG=C /sbin/fdisk -l /dev/${DISK} | grep Disk | awk '{print $5}' | tr -d '\n'` |
94 |
CYLS=$(($DISKSIZE/255/63/512)) |
|
|
1
by Oliver Grawert
initial checkin |
95 |
sync |
|
28
by Oliver Grawert
jasper_setup: fix fstab creation, extend comments. jasper_growroot: extend logging and code comments |
96 |
# Enlarge the OS partition to fill the rest of the disk, we need to maintain
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
97 |
# the new CHS geometry for the bootloader
|
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
98 |
/sbin/sfdisk -H 255 -S 63 -C ${CYLS} --no-reread -D -q /dev/${DISK} <<EOF >>${LOG} 2>&1 |
99 |
,$SIZE_P1,c,*
|
|
|
25
by Oliver Grawert
jasper_growroot: rework partitioning code |
100 |
,,,-
|
|
1
by Oliver Grawert
initial checkin |
101 |
EOF
|
102 |
}
|
|
103 |
||
|
116
by Oliver Grawert
add plymouth support to user readable output |
104 |
$MYECHO"Caching vfat content in ${CACHE} ..." >>${LOG} |
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
105 |
cache_vfat >>${LOG} 2>&1 |
106 |
||
|
116
by Oliver Grawert
add plymouth support to user readable output |
107 |
$MYECHO"Resizing root partition ..." >>${LOG} |
|
1
by Oliver Grawert
initial checkin |
108 |
resize_partitions |
|
17
by Oliver Grawert
jasper_growroot: use fake mtab in initramfs to please resize2fs, drop fsck, we need to do that at image build time, change UUID generation code. jasper_setup: use ext3 filesystem in fstab, remount /root rw for write operations |
109 |
|
|
116
by Oliver Grawert
add plymouth support to user readable output |
110 |
$MYECHO"Re-writing vfat partition ..." >>${LOG} |
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
111 |
write_vfat >>${LOG} 2>&1 |
|
17
by Oliver Grawert
jasper_growroot: use fake mtab in initramfs to please resize2fs, drop fsck, we need to do that at image build time, change UUID generation code. jasper_setup: use ext3 filesystem in fstab, remount /root rw for write operations |
112 |
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
113 |
# Give some info to the user TODO: create plymouth output
|
|
116
by Oliver Grawert
add plymouth support to user readable output |
114 |
$MYECHO"Resizing root filesystem. Please wait, this will take a moment ..." |
115 |
$MYECHO"Resizing root filesystem ..." >>${LOG} |
|
|
61
by Oliver Grawert
jasper_growroot: small fixes, jasper_setup: disable swap file creation (temporary), add sysctl.d file to switch kernel to less disk writes, default to noop elevator on kernel cmdline, add more output (temporary) |
116 |
# little workaround for wrong clocks
|
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
117 |
mount ${ROOTDEV}2 /root >>${LOG} 2>&1 |
|
76
by Oliver Grawert
jasper_growroot: re-enable swap file creation during first boot, redirect output of mount calls to logfile, jasper_setup: change text about resizing time, it is a lot faster than 10min nowadays |
118 |
umount /root >>${LOG} 2>&1 |
|
61
by Oliver Grawert
jasper_growroot: small fixes, jasper_setup: disable swap file creation (temporary), add sysctl.d file to switch kernel to less disk writes, default to noop elevator on kernel cmdline, add more output (temporary) |
119 |
|
|
116
by Oliver Grawert
add plymouth support to user readable output |
120 |
$MYECHO"Checking filesystem before resizing..." |
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
121 |
/sbin/e2fsck -fy ${ROOTDEV}2 >>${LOG} 2>&1 || true |
|
61
by Oliver Grawert
jasper_growroot: small fixes, jasper_setup: disable swap file creation (temporary), add sysctl.d file to switch kernel to less disk writes, default to noop elevator on kernel cmdline, add more output (temporary) |
122 |
pass=1 |
123 |
iter=0 |
|
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
124 |
LANG=C /sbin/resize2fs -p ${ROOTDEV}2 2>&1 | while read -n 1 input; do |
|
57
by Oliver Grawert
jasper_growroot: strip parentheses from resize2fs output, add proper percentage output for each single pass of the resize progress, depend on bc for percentage calculation, copy bc in the jasper hook |
125 |
char=$(echo $input|sed 's/[)(]//') |
126 |
if [ "${char}" = "X" ];then |
|
127 |
if [ "${iter}" = "100.0" ];then |
|
128 |
iter=0 |
|
129 |
pass=$(($pass+1)) |
|
130 |
echo >>${LOG} |
|
131 |
fi
|
|
132 |
iter=$(echo $iter+2.5|bc) |
|
|
61
by Oliver Grawert
jasper_growroot: small fixes, jasper_setup: disable swap file creation (temporary), add sysctl.d file to switch kernel to less disk writes, default to noop elevator on kernel cmdline, add more output (temporary) |
133 |
printf "\rResizing, pass: %i [%3.0f/100]" $pass $iter |
|
57
by Oliver Grawert
jasper_growroot: strip parentheses from resize2fs output, add proper percentage output for each single pass of the resize progress, depend on bc for percentage calculation, copy bc in the jasper hook |
134 |
fi
|
135 |
if [ -z "${char}" ]; then |
|
|
55
by Oliver Grawert
jasper_growroot: add progress reporting to resize2fs output |
136 |
echo -n " " >>${LOG} |
137 |
else
|
|
138 |
echo -n "${char}" >>${LOG} |
|
|
57
by Oliver Grawert
jasper_growroot: strip parentheses from resize2fs output, add proper percentage output for each single pass of the resize progress, depend on bc for percentage calculation, copy bc in the jasper hook |
139 |
fi
|
|
55
by Oliver Grawert
jasper_growroot: add progress reporting to resize2fs output |
140 |
done
|
141 |
echo >>${LOG} |
|
|
61
by Oliver Grawert
jasper_growroot: small fixes, jasper_setup: disable swap file creation (temporary), add sysctl.d file to switch kernel to less disk writes, default to noop elevator on kernel cmdline, add more output (temporary) |
142 |
echo 1>/dev/.initramfs/jasper-reboot
|
|
17
by Oliver Grawert
jasper_growroot: use fake mtab in initramfs to please resize2fs, drop fsck, we need to do that at image build time, change UUID generation code. jasper_setup: use ext3 filesystem in fstab, remount /root rw for write operations |
143 |
|
|
33
by Oliver Grawert
add caching and re-formatting of the vfat partition with the new CHS geometry of the SD card so we can be sure we are still able to boot |
144 |
# Set a new UUID to make sure we're unique in the world
|
|
111
by Oliver Grawert
drop some hardcoding of the rootdev function |
145 |
/sbin/tune2fs -U $(uuidgen) ${ROOTDEV}2 >>${LOG} 2>&1 |
|
34
by Oliver Grawert
jasper_growroot: add detection of rootdevice from cmdline, fix vfat handling, use DOS compatibility in sfdisk call to make sure vfat stays bootable, remove cache dir for fat data. jasper_setup: write flash-kernel.conf |
146 |
|
147 |
rm -rf ${CACHE} |