/usr/share/tcos/scripts/tcos-premount/20swapon is in initramfs-tools-tcos 0.89.86.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #!/bin/sh
#
if [ "$1" = "prereqs" ]; then
exit 0
fi
quiet=n
. /scripts/functions
# if break=swapon STOP here
maybe_break swapon
. /conf/tcos.conf
. /conf/tcos-run-functions
# DOCUMENTME noswap | disable swap file creation (swap partition is used always, if found)
noswap=$(read_cmdline_var "noswap" "0")
if [ ${noswap} = 1 ]; then
_log "SWAPON swap disabled from cmdline"
exit 0
fi
############ VARS ###############
# need 64 mb of free space (in kb)
need_free_space=65536
mem_max=$(grep MemTotal /proc/meminfo | awk '{print $2}')
mem_max_dd=901120
if [ ${need_free_space} -ge ${mem_max} ] ; then
# mem_max - 10 Mb
need_free_space=$(($mem_max-10240))
fi
if [ ${need_free_space} -ge ${mem_max_dd} ];then
need_free_space=${mem_max_dd}
fi
#################################
swap_parts_num=$(grep ^/dev /etc/fstab|grep -c swap)
swap_parts_devs=$(grep ^/dev /etc/fstab|grep swap | awk '{print $1}')
ext3_parts_num=$(grep ^/dev /etc/fstab|grep -c ext3)
ext3_parts_devs=$(grep ^/dev /etc/fstab|grep ext3 | awk '{print $1}')
fat32_parts_num=$(grep ^/dev /etc/fstab|grep -c vfat)
fat32_parts_devs=$(grep ^/dev /etc/fstab|grep vfat | awk '{print $1}')
######### FUNCTIONS ##########
check_if_swaps() {
# exit if swap is mounted
if [ $(grep -c -v ^Filename /proc/swaps ) != 0 ]; then
_log "SWAPON have swap !!!"
log_end_msg 0
exit 0
fi
}
mount_exits_swap() {
for dev in $1 ; do
swapon ${dev}
done
}
swap_mnt_file=/mnt/tmp/swap.file
# check if /mnt/tmp is mounted and create swap file into /mnt/tmp
create_swap () {
if [ $(grep -c /mnt/tmp /proc/mounts) -gt 0 ]; then
# have /mnt/tmp !!!!
# check if file exists
if [ -f ${swap_mnt_file} ]; then
# file exists, mount
swapon ${swap_mnt_file} >> /tmp/initramfs.debug 2>&1
else
# file not exists, create it
dd if=/dev/zero of=${swap_mnt_file} bs=${need_free_space}k count=1 >> /tmp/initramfs.debug 2>&1
mkswap ${swap_mnt_file} >> /tmp/initramfs.debug 2>&1
swapon ${swap_mnt_file} >> /tmp/initramfs.debug 2>&1
fi
fi
}
############# begin code ############
log_begin_msg "Active swap partitions"
# first we search for a swap mounted and exit
_log "SWAPON checking swap mounted partitions"
check_if_swaps
# no swap partition, create swap file in /mnt/tmp (if mounted)
create_swap
# if here we have no swap
_log "SWAP no swap avalaible"
log_end_msg 1
exit 0
|