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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
#!/bin/sh
PACKAGES="lvm2 gdisk e2fsprogs dosfstools kmod udev"
eval "$chrooted_functions"
probe_target_optional_functions
start_failsafe_mode
# in the chroot commands should use /tmp for temporary files
export TMPDIR=/tmp
if [ "$1" = "--debug" ]
then
debug=1
shift
else
debug=0
fi
loop_device=$1
root_password_request=$2
shift 2
# eval <var>=<value> parameters
while [ ! -z "$1" ]
do
eval "$1"
shift
done
failsafe mount -t proc none /proc >/dev/null
failsafe_mount_sys_and_dev >/dev/null
export DEBIAN_FRONTEND=noninteractive LANG=C
optional_target_prepare_rootfs draft inside
# We will need internet connectivity for package management.
# Ensure we have a valid DNS setup.
resolv_conf_orig_status=$(ensure_valid_resolv_conf)
if [ "$resolv_conf_orig_status" != "ok" ]
then
echo "I: draft image - generated /etc/resolv.conf (it was missing or incomplete)"
fi
if $target_custom_packages_exists
then
PACKAGES="$PACKAGES $(target_custom_packages)"
fi
# install missing packages
echo -n "I: draft image - updating package manager database... "
apt-get update -qq
echo done
# fdisk & sfdisk are part of util-linux, but on newer OS they are
# in a dedicated package. Ensure it is installed.
if package_exists fdisk
then
PACKAGES="$PACKAGES fdisk"
fi
# if needed (a FAT partition or volume will have to grow) install
# fatresize (package is in section 'universe' on Ubuntu).
if [ $need_fatresize -eq 1 ]
then
PACKAGES="$PACKAGES fatresize"
if ! package_exists fatresize
then
echo "I: draft image - package fatresize not found."
echo -n "I: draft image - trying to add section universe in apt sources (for fatresize)... "
apt_sources_add_section universe
echo done
echo -n "I: draft image - updating package manager database again... "
apt-get update -qq
echo done
fi
fi
if [ -z "$kernel_package" ]
then
# kernel package not specified, install a default one
kernel_search_regexp="^$(target_kernel_default_package)$"
error_if_missing="$(
echo "E: no linux kernel package found."
echo "E: Run 'debootstick --help-os-support' for more info."
)"
else
kernel_search_regexp="^${kernel_package}$"
error_if_missing="E: no such package '$kernel_package'"
fi
kernel_package_found=$(
list_available_packages "$kernel_search_regexp")
if [ -z "$kernel_package_found" ]
then
echo "$error_if_missing"
exit 1
fi
to_be_installed=""
for package in $kernel_package_found $PACKAGES
do
if [ $(package_is_installed $package) -eq 0 ]
then
to_be_installed="$to_be_installed $package"
fi
done
[ -f /sbin/init ] || to_be_installed="$to_be_installed init"
if [ "$to_be_installed" != "" ]
then
echo -n "I: draft image - installing packages:${to_be_installed}... "
install_packages $to_be_installed
echo done
fi
# keep it small
apt-get -qq clean
rm -rf /var/lib/apt/lists/*
# tune LVM config
tune_lvm
# for text console in kvm
if [ "$debug" = "1" ]
then
# if OS init is upstart, create a service
# in order to start a shell when the system is ready
if [ -f '/sbin/upstart' ]
then
cat > ./etc/init/ttyS0.conf << EOF
start on stopped rc or RUNLEVEL=[12345]
stop on runlevel [!12345]
respawn
exec /sbin/getty -L 115200 ttyS0 xterm
EOF
fi
fi
# set the root password if requested
case "$root_password_request" in
"NO_REQUEST")
true # nothing to do
;;
"NO_PASSWORD")
passwd -dq root # remove root password
;;
*) # change root password
echo "$root_password_request" | chpasswd
;;
esac
echo -n "I: draft image - setting up bootloader... "
target_configure_bootloader
# installing grub on this temporary work-image
# may not seem useful (it will be repeated on the final
# stick anyway), but actually it is:
# the files created there should be accounted when
# estimating the final stick minimal size).
target_install_bootloader
echo done
# check if target-specific code specified
# 'applied_kernel_cmdline' variable
if [ ! -z ${applied_kernel_cmdline+x} ]
then
bootargs="$applied_kernel_cmdline"
if [ -z "$bootargs" ]
then
bootargs="<none>"
fi
echo "I: draft image - kernel bootargs: $bootargs"
fi
if [ "$config_hostname" != "" ]
then
echo -n "I: draft image - setting hostname... "
echo "$config_hostname" > /etc/hostname
echo done
fi
echo -n "I: draft image - performing sanity checks... "
should_update_hosts_file=$(missing_or_empty /etc/hosts)
should_update_locale_file=$(missing_or_empty /etc/default/locale)
echo done
if [ $should_update_hosts_file -eq 1 ]
then
echo -n "I: draft image - generating /etc/hosts (it was empty or missing)... "
generate_hosts_file
echo done
fi
if [ $should_update_locale_file -eq 1 ]
then
echo -n "I: draft image - adding missing locale definition... "
mkdir -p /etc/default
echo "LC_ALL=C" > /etc/default/locale
echo done
fi
possibly_restore_resolv_conf
optional_target_cleanup_rootfs draft inside
# umount all
undo_all
|