Debian Codegraph @

sbin/drbl-sl

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 #
5 # Note: This code is modified from http://cdprojekte.mattiasschlenker.de/Public/DSL-frominitrd/2.2b-0.0/script/pxedsl.sh
6 # Ref:
7 # http://news.mattiasschlenker.de/2006/02/22/pxe-booting-damnsmalllinux/#more-10
8 #
9 # SL: Small Linux (Damn Small Linux, Puppy Linux, Clonezilla live, GParted live..)
10 #
11 # Load DRBL setting and functions
12 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
13
14 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
15 . /etc/drbl/drbl-ocs.conf
16 . $DRBL_SCRIPT_PATH/sbin/ocs-functions
17
18 # Settings
19 SL_ISO_URL_EXAMPLE="http://downloads.sourceforge.net/clonezilla/clonezilla-live-3.0.2-21-amd64.iso"
20 # The method for netboot's root file system. "fetch" means the client will download the filesystem.squashfs from tftpd server, "nfsroot" means client will mount the nfs server. By default we use fetch. "nfsroot" only works for Debian-live based system (e.g. Clonezilla live, GParted live...)
21 rootfs_location="fetch"
22 # Force to update the PXELinux config file
23 force_to_update_pxecfg="yes"
24
25 # List all supported SL_NAME
26 # // On 2009/05/25, we remove the support for PLD, INSERT, PUD, since those projects are not developed any more. As for GeeXbox, since we do not have time, it's removed, too.
27 # // 2013/03/13, DSL and PuppyLinux were removed. Not so useful to provide this.
28 #supported_SL_dists="DSL PuppyLinux INSERT PLD Debian-live GeeXbox PUD-Linux"
29 supported_SL_dists="Clonezilla-live GParted-live"
30
31 # The buffer ratio for iso to container
32 buffer_ratio_for_iso_to_container="1.25"
33
34 # The default estimation ratio for client's ram to use this small linux,
35 # we estimate it as 3 times of the initrd. For some distribution we might overwrite this value if necessary.
36 client_ram_to_initrd_ratio="3"
37
38 #
39 batch_mode="off"
40 # Prompt messages after installation.
41 booting_messages="on"
42
43 # By default when Clonezilla live is used, not to add ocs_server
44 add_ocs_server="no"
45 # By default when in fetch mode, the squashfs file will be copied, not link
46 use_link_in_fetch_mode="no"
47
48 # Functions
49 USAGE() {
50 echo "Load small GNU/Linux ($supported_SL_dists) Linux to DRBL environment."
51 echo "Usage: $0 [OPTION] [SL-ISO|SL-INDEX]"
52 echo "OPTION:"
53 language_help_prompt_by_idx_no
54 echo "-b, --batch-mode Run clone in batch mode."
55 echo "-e, --fetch-link Use symbolic link when the mode is fetch for root file system."
56 echo "-i, --install ISO: Load Small Linux ISO into DRBL environment, you must put the iso file in the current working dir. This conflicts with \"-p\" option."
57 echo "-d, --distribution DIST: Assign the small GNU/Linux distribution as DIST. Available names are: $supported_SL_dists."
58 echo "-f, --use-nfsroot By default the boot parameter to load the root file system (e.g. filesystem.squashfs) is fetch. With this option, nfsroot is used. //NOTE// This function only works for live-initramfs based system. E.g. Clonezilla live or GParted live."
59 echo "-k, --keep-pxecfg Keep the pxelinux config file without updating the boot parameters."
60 echo "-n, --no-prompt-boot-message Skip the prompt messages about booting via PXE or etherboot in the end of execution."
61 echo "-o, --add-ocs-server Add ocs_server in the boot parameters for Clonezilla live."
62 echo "-p, --live-path PATH: Assign the mounted or unzipped live system as PATH. This conflicts with \"-i\" option."
63 echo "-s, --server-ip IP_ADDR: Assign the tftp or NFS server's IP address to be used in Clonezilla/GParted live."
64 echo "-u, --uninstall DIST: Uninstall Small Linux DIST."
65 echo "-V, --dist-version VER: Assign the version of small GNU/Linux version number as VER."
66 echo "-v, --verbose: Verbose mode."
67 echo "SL-ISO is one of $supported_SL_dists ISO file, used with installation."
68 echo "S-L-INDEX is one of $supported_SL_dists, used with uninstallation."
69 echo "Ex: To load Clonezilla live, run '$0 -i clonezilla-live-3.0.2-21-amd64.iso'"
70 echo " To load GParted live, run '$0 -i gparted-live-1.4.0-6-amd64.iso'"
71 for isl in $supported_SL_dists; do
72 echo " To remove $isl, run '$0 -u $isl'"
73 done
74 echo " To remove all Small Linux, run '$0 -u all'"
75 }
76 #
77 get_rootfs_location_opt() {
78 rootfs_location_opt=""
79 case "$rootfs_location" in
80 "fetch")
81 if is_drbl_clonezilla_live_env; then
82 # Check if file exists in the http URL. If the return code is 200 then it exists.
83 url_path="$server_IP/$squashfs_file"
84 if [ "$(curl -s -L -o /dev/null -w "%{http_code}" -I "http://$url_path")" -eq 200 ]; then
85 rootfs_location_opt="fetch=http://$url_path"
86 else
87 rootfs_location_opt="fetch=tftp://$url_path"
88 fi
89 fi
90 ;;
91 "nfsroot")
92 rootfs_location_opt="netboot=nfs nfsroot=$server_IP:$drbl_common_root/clonezilla-live/" ;;
93 esac
94 } # end of get_rootfs_location_opt
95 # get rootfile
96 get_SL_rootfile(){
97 # this function must be used after iso is mounted, we need to find version inside it for some distribution (such as PLD).
98 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
99 dsl|DamnSmallLinux)
100 rootfile="$rootfile_path/KNOPPIX"
101 # DSL does not have any extra file, the only one is KNOPPIX
102 extra_sys_file=""
103 ;;
104 puppy|PuppyLinux)
105 rootfile="$rootfile_path/pup_${SL_VER}.sfs"
106 # Puppy 2.12, there is a /zdrv_212.sfs <-- deprecated.
107 [ -f "$isomnt/$rootfile_path/zdrv_${SL_VER}.sfs" ] && extra_sys_file="$rootfile_path/zdrv_${SL_VER}.sfs"
108 ;;
109 clonezilla-live|gparted-live)
110 rootfile="$rootfile_path/filesystem.squashfs"
111 extra_sys_file=""
112 ;;
113 esac
114 } # end of get_SL_rootfile
115 #
116 prepare_param_in_pxe_grub_cfg(){
117 # This function must be used after ramdisk_size is calculated.
118 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
119 dsl|DamnSmallLinux)
120 append_param_in_grub_cfg="ramdisk_size=$ramdisk_size init=/etc/init lang=us apm=power-off vga=791 nomce noapic quiet BOOT_IMAGE=knoppix frominitrd"
121 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
122 ;;
123 puppy|PuppyLinux)
124 # from version 216, init is ready when released, and no bootparam_trigger is necessary. Now drbl-SL only supports puppy from version 4.2.1
125 bootparam_trigger=""
126 use_modified_init="no"
127 append_param_in_grub_cfg=""
128 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
129 ;;
130 clonezilla-live)
131 if [ -z "$server_IP" ]; then
132 # Find the IP address of this server. Here we choose the first one in the list of those connected to DRBL clients.
133 server_IP="$(LC_ALL=C get-all-nic-ip -b | awk -F" " '{print $1}')"
134 fi
135 if [ "$add_ocs_server" = "yes" ]; then
136 ocs_serer_opt="ocs_server=\"$server_IP\""
137 fi
138 get_rootfs_location_opt
139 if [ -z "$cl_gp_boot_param" ]; then
140 append_param_in_grub_cfg="boot=live union=overlay noswap noeject nolocales vga=788 $rootfs_location_opt $ocs_serer_opt"
141 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
142 else
143 append_param_in_grub_cfg="$cl_gp_boot_param noeject $rootfs_location_opt $ocs_serer_opt"
144 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
145 if is_drbl_live_env; then
146 # We will reuse the filesystem.squashfs from DRBL live, however, it's not like that of Clonezilla live, therefore more option are needed here.
147 clonezilla_se_live_opts="hostname=ocs-client \
148 username=$assgned_username systemd.unit=multi-user.target drbl_live_noconfx \
149 stick-to-pxe-srv dhcp-vendor-id=DRBLClient \
150 drbl_prerun1=\"mkdir -p /var/lib/live/clonezilla/ocs-live.d\" \
151 drbl_prerun2=\"grep -qsE ^sudo -i ocs-live-run-menu /home/$assgned_username/.bash_profile || echo sudo -i ocs-live-run-menu >> /home/$assgned_username/.bash_profile\""
152 append_param_in_grub_cfg="$append_param_in_grub_cfg $clonezilla_se_live_opts"
153 append_param_in_pxe_cfg="$append_param_in_pxe_cfg $clonezilla_se_live_opts"
154 fi
155 fi
156 ;;
157 gparted-live)
158 if [ -z "$server_IP" ]; then
159 # Find the IP address of this server. Here we choose the first one in the list, since it's just an example.
160 server_IP="$(LC_ALL=C get-all-nic-ip -i | awk -F" " '{print $1}')"
161 fi
162 get_rootfs_location_opt
163 if [ -z "$cl_gp_boot_param" ]; then
164 assgned_username="user" # The live system uses the default username as "user"
165 gparted_se_live_opts="username=$assgned_username"
166 append_param_in_grub_cfg="boot=live union=overlay noswap noeject nolocales vga=788 $rootfs_location_opt "
167 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
168 else
169 append_param_in_grub_cfg="$cl_gp_boot_param noeject $rootfs_location_opt"
170 append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg"
171 fi
172 ;;
173 esac
174 } # end of prepare_param_in_pxe_grub_cfg
175 #
176 create_linuxrc_pxe_initrd_with_rootfs_inserted(){
177 case "$initrd_type" in
178 ext2)
179 # prepare the size for initrd.
180 iso_size="$(stat -c "%s" $SL_ISO)" # unit: bytes
181 container_need_in_KB="$(echo "scale=0; $iso_size * $buffer_ratio_for_iso_to_container / 1024.0" | bc -l)" # unit: KB
182 client_RAM_required="$(echo "scale=0; $container_need_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)"
183 # ramdisk_size is for client booting use (kernel parameter).
184 ramdisk_size="$container_need_in_KB"
185 echo "New NBI initrd size (uncompressed): $container_need_in_KB KB. Use ramdisk_size=$ramdisk_size in bootparam."
186 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
187 echo "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB."
188 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
189 echo "Creating the modified ramdisk will take a while, please be patient."
190
191 # Unpack initrd
192 echo 'Creating container...'
193 dd if=/dev/zero of=$wd/initrd.img bs=1024 count=$container_need_in_KB
194 echo 'Formatting container...'
195 mkfs.ext2 -q -F -L "${SL_NAME}-initrd" $wd/initrd.img
196 echo 'Unpacking old initrd...'
197 $uncompress_to_stdout "$oldinitrd" > $wd/oldinitrd.img
198 mkdir $wd/initrd.tmp
199 mkdir $wd/oldinitrd.tmp
200 # Mount initrd
201 mount -o loop $wd/initrd.img $wd/initrd.tmp
202 mount -o loop $wd/oldinitrd.img $wd/oldinitrd.tmp
203 #
204 if [ -z "$SL_VER" ]; then
205 if [ -e $wd/oldinitrd.tmp/PUPPYVERSION ]; then
206 SL_VER="$(cat $wd/oldinitrd.tmp/PUPPYVERSION)"
207 elif [ -e $isomnt/GEEXBOX/etc/version ]; then
208 # only if the modified version exists, otherwise we ust default one.
209 SL_VER_TMP="$(cat $isomnt/GEEXBOX/etc/version)"
210 if [ -e "$DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER_TMP/linuxrc.$SL_NAME-$SL_VER_TMP.drbl" ]; then
211 SL_VER="$SL_VER_TMP"
212 else
213 SL_VER="default"
214 fi
215 else
216 SL_VER="default"
217 fi
218 fi
219
220 #
221 get_SL_rootfile
222 prepare_param_in_pxe_grub_cfg
223
224 echo 'Copying content of the old initrd...'
225 ( cp -a $wd/oldinitrd.tmp/* $wd/initrd.tmp )
226 mkdir -p $wd/initrd.tmp/$rootfile_path_in_initrd
227 echo 'Copying root image...'
228 cp -af $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/
229 if [ -n "$extra_sys_file" ]; then
230 cp -af $isomnt/$extra_sys_file $wd/initrd.tmp/$rootfile_path_in_initrd/
231 fi
232 if [ "$use_modified_init" = "yes" ]; then
233 if [ -e $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl ]; then
234 echo "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..."
235 cp -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/linuxrc
236 else
237 echo "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/default/..."
238 cp -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/default/linuxrc.$SL_NAME-default.drbl $wd/initrd.tmp/linuxrc
239 fi
240 else
241 echo "The linuxrc from $SL_FULL_NAME is ready for PXE boot."
242 fi
243
244 # Umount initrd
245 umount $wd/initrd.tmp
246 umount $wd/oldinitrd.tmp
247
248 # Pack the initrd again:
249 echo 'Packing initrd...'
250 $compress_to_stdout $wd/initrd.img > $pxecfg_pd/$nbi_initrd
251
252 # Remove the initrd
253 echo 'Removing temporary copy of initrd...'
254 rm $wd/initrd.img
255 # Remove the old original initrd
256 echo 'Removing temporary copy of original initrd...'
257 rm $wd/oldinitrd.img
258
259 # Copy the linux kernel
260 cp -f "$kernel" $pxecfg_pd/$nbi_kernel
261 ;;
262
263 cpio)
264 mkdir -p $wd/initrd.tmp
265 mkdir -p $wd/oldinitrd.tmp
266 (cd $wd/oldinitrd.tmp/; $uncompress_to_stdout "$oldinitrd" | cpio -idm)
267 #
268 if [ -z "$SL_VER" ]; then
269 if [ -e $wd/oldinitrd.tmp/PUPPYVERSION ]; then
270 SL_VER="$(cat $wd/oldinitrd.tmp/PUPPYVERSION)"
271 else
272 SL_VER="default"
273 fi
274 fi
275
276 #
277 get_SL_rootfile
278 prepare_param_in_pxe_grub_cfg
279
280 echo 'Copying content of the old initrd...'
281 ( cp -a $wd/oldinitrd.tmp/* $wd/initrd.tmp/ )
282 mkdir -p $wd/initrd.tmp/$rootfile_path_in_initrd
283 echo 'Copying root image...'
284 cp -a $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/
285 if [ -n "$extra_sys_file" ]; then
286 cp -af $isomnt/$extra_sys_file $wd/initrd.tmp/$rootfile_path_in_initrd/
287 fi
288 if [ "$use_modified_init" = "yes" ]; then
289 echo "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..."
290 cp -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/linuxrc
291 else
292 echo "The linuxrc from $SL_FULL_NAME is ready for PXE boot."
293 fi
294
295 # Pack the initrd again:
296 echo "Packing the new initrd... $msg_this_might_take_several_minutes..."
297 (cd $wd/initrd.tmp/; find . | cpio -o -H newc | gzip -9 > $pxecfg_pd/$nbi_initrd)
298
299 # Remove the working dir
300 echo 'Removing temporary working dir...'
301 [ -d "$wd" -a -n "$(echo $wd | grep "drbl_sl_wd")" ] && rm -rf $wd
302
303 # Copy the linux kernel
304 cp -f "$kernel" $pxecfg_pd/$nbi_kernel
305 ;;
306 esac
307 } # end of create_linuxrc_pxe_initrd_with_rootfs_inserted
308
309 #
310 put_pxe_initrd_without_rootfs_inserted(){
311 #///NOTE/// This function is deprecated! We keep it just in case we need in the future.
312 cp -f $oldinitrd $pxecfg_pd/$nbi_initrd
313 initrd_size="$(stat -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes
314 initrd_size_in_KB=$(echo "scale=0; $initrd_size / 1024.0" | bc -l)
315 client_RAM_required="$(echo "scale=0; $initrd_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)"
316 # ramdisk_size is for client booting use (kernel parameter).
317 ramdisk_size="$initrd_size_in_KB"
318 echo "New NBI initrd size (uncompressed): $initrd_size_in_KB KB. Use ramdisk_size=$ramdisk_size in bootparam."
319 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
320 echo "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB."
321 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
322 get_SL_rootfile
323 prepare_param_in_pxe_grub_cfg
324 # Copy the linux kernel
325 cp -f $kernel $pxecfg_pd/$nbi_kernel
326 chmod 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd
327 } # end of put_pxe_initrd_without_rootfs_inserted
328 #
329 create_casper_pxe_initrd_with_rootfs_inserted(){
330 #///NOTE/// This function is deprecated! We keep it just in case we need in the future.
331 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
332 debian-live-etch|Debian-live)
333 [ -z "$SL_VER" ] && SL_VER="etch"
334 get_SL_rootfile
335 # it's initramfs, so no more loop mount, just use cpio
336 mkdir $wd/initrd.tmp
337 (cd $wd/initrd.tmp; $uncompress_to_stdout "$oldinitrd" | cpio -idm)
338 mkdir -p $wd/initrd.tmp/$rootfile_path_in_initrd
339 echo "Copying root image. $msg_this_might_take_several_minutes"
340 cp -f $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/
341 if [ "$use_modified_init" = "yes" ]; then
342 echo "Copying modified casper from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..."
343 cp -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/casper.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/scripts/casper
344 fi
345 # create initramfs
346 echo "Creating initramfs $pxecfg_pd/$nbi_initrd, $msg_this_might_take_several_minutes"
347 ( cd $wd/initrd.tmp
348 find . | cpio --quiet -o -H newc | gzip -9 > $pxecfg_pd/$nbi_initrd
349 )
350 initramfs_size="$(stat -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes
351 initramfs_size_in_KB=$(echo "scale=0; $initramfs_size / 1024.0" | bc -l)
352 client_RAM_required="$(echo "scale=0; $initramfs_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)"
353 # initramfs, we do not have to assign ramdisk_size in bootparam.
354 echo "The new initrd size is: $initramfs_size_in_KB KB."
355 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
356 echo "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB."
357 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
358 prepare_param_in_pxe_grub_cfg
359 cp -f $kernel $pxecfg_pd/$nbi_kernel
360 chmod 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd
361 ;;
362 PUD|pud)
363 if [ -z "$SL_VER" ]; then
364 # iso file name is like PUD-0.4.6.10.iso, try to guess.
365 SL_VER="$(basename $SL_ISO | sed -e "s/^PUD-//g" -e "s/.iso$//g")"
366 fi
367 get_SL_rootfile
368 # it's initramfs, so no more loop mount, just use cpio
369 mkdir $wd/initrd.tmp
370 (cd $wd/initrd.tmp; $uncompress_to_stdout "$oldinitrd" | cpio -idm)
371 mkdir -p $wd/initrd.tmp/$rootfile_path_in_initrd
372 echo "Copying root image. $msg_this_might_take_several_minutes"
373 cp -f $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/
374 if [ "$use_modified_init" = "yes" ]; then
375 echo "Copying modified casper from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..."
376 cp -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/casper.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/scripts/casper
377 else
378 echo "The linuxrc from $SL_FULL_NAME is ready for PXE boot."
379 fi
380 # create initramfs
381 echo "Creating initramfs $pxecfg_pd/$nbi_initrd, $msg_this_might_take_several_minutes"
382 ( cd $wd/initrd.tmp
383 find . | cpio --quiet -o -H newc | gzip -9 > $pxecfg_pd/$nbi_initrd
384 )
385 initramfs_size="$(stat -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes
386 initramfs_size_in_KB=$(echo "scale=0; $initramfs_size / 1024.0" | bc -l)
387 client_RAM_required="$(echo "scale=0; $initramfs_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)"
388 # initramfs, we do not have to assign ramdisk_size in bootparam.
389 echo "The new initrd size is: $initramfs_size_in_KB KB."
390 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
391 echo "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB."
392 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
393 prepare_param_in_pxe_grub_cfg
394 cp -f $kernel $pxecfg_pd/$nbi_kernel
395 chmod 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd
396 ;;
397 esac
398 } # end of create_casper_pxe_initrd_with_rootfs_inserted
399 #
400 put_kernel_initrd_root_fs_on_pxe_server() {
401 # Copy the linux kernel
402 echo "Copying kernel $kernel as $pxecfg_pd/$nbi_kernel..."
403 cp -af $kernel $pxecfg_pd/$nbi_kernel
404 echo "Copying initrd $oldinitrd as $pxecfg_pd/$nbi_initrd..."
405 cp -af $oldinitrd $pxecfg_pd/$nbi_initrd
406 get_SL_rootfile
407 case "$rootfs_location" in
408 "fetch")
409 echo "Copying root image $isomnt/$rootfile to $pxecfg_pd... $msg_this_might_take_several_minutes"
410 case "$use_link_in_fetch_mode" in
411 yes) ln -fsv $isomnt/$rootfile $pxecfg_pd/$squashfs_file ;;
412 no) rsync -aP $isomnt/$rootfile $pxecfg_pd/$squashfs_file ;;
413 esac
414 ;;
415 "nfsroot")
416 echo "Copying root image $isomnt/$rootfile to $drbl_common_root/clonezilla-live/... $msg_this_might_take_several_minutes"
417 mkdir -p $drbl_common_root/clonezilla-live/live/
418 # In DRBL live server when unfs3 is used, we can use mount --bind to make this
419 if is_drbl_live_env; then
420 if mountpoint $drbl_common_root/clonezilla-live/live/ &>/dev/null ; then
421 umount $drbl_common_root/clonezilla-live/live/
422 fi
423 mount --bind $isomnt/$rootfile_path $drbl_common_root/clonezilla-live/live/
424 else
425 rsync -aP $isomnt/$rootfile $drbl_common_root/clonezilla-live/live/
426 fi
427 ;;
428 esac
429 prepare_param_in_pxe_grub_cfg
430 chmod 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd
431 } # end of put_kernel_initrd_root_fs_on_pxe_server
432 #
433 umount_and_clean_tmp_working_dirs(){
434 if [ "$iso_mnt_flag" = "true" ]; then
435 # It's mounted by this program.
436 if mountpoint $isomnt &>/dev/null; then
437 umount $isomnt
438 fi
439 fi
440 [ -d "$isomnt" -a -n "$(echo $isomnt | grep "drblsl_tmp")" ] && rm -rf $isomnt
441 [ -d "$wd" -a -n "$(echo $wd | grep "drbl_sl_wd")" ] && rm -rf $wd
442 } # end of umount_and_clean_tmp_working_dirs
443 #
444 get_SL_OS_NAME(){
445 if [ "$(echo $SL_ISO | grep -i "clonezilla-live")" ]; then
446 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
447 echo "This ISO file $SL_ISO is for Clonezilla live."
448 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
449 SL_OS="clonezilla-live"
450 elif [ "$(echo $SL_ISO | grep -i "gparted-live")" ]; then
451 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
452 echo "This ISO file $SL_ISO is for GParted live."
453 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
454 SL_OS="gparted-live"
455 else
456 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
457 echo "Unknown Small Linux distribution! This script only works with $supported_SL_dists! Program terminated!!!"
458 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
459 exit 1
460 fi
461 } # end of get_SL_OS_NAME
462
463 #
464 install_SL(){
465 # 2 cases, (1) live iso/zip (2) path where iso is mounted or zip is uncompressed.
466 # Case (1)
467 local grub_cfg_f lines begin_line end_line search_cmd
468 if [ "$source_mode" = "iso-zip" ]; then
469 if [ -z "$SL_ISO" ]; then
470 USAGE
471 exit 1
472 fi
473
474 if [ ! -f "$SL_ISO" ]; then
475 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
476 echo "$SL_ISO is NOT found!"
477 echo "You have to prepare the iso file. For example, if you want to use Clonezilla live, you can get it via this command:"
478 echo "wget $SL_ISO_URL_EXAMPLE"
479 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
480 exit 1
481 fi
482
483 # Program file might give different results:
484 # ISO 9660 CD-ROM filesystem data # file vesion 5.03
485 # x86 boot sector # file version 4.10
486 # For file version 5.17 in Jessie:
487 # debian-7.4.0-i386-netinst.iso: DOS/MBR boot sector; partition 1 : ID=0x17, active, start-CHS (0x0,2,1), end-CHS (0x114,63,32), startsector 64, 567232 sectors
488 case "$SL_ISO" in
489 *.iso)
490 if [ -z "$(LC_ALL=C file -Lsk $SL_ISO | grep -i "ISO 9660 CD-ROM filesystem data")" ] &&\
491 [ -z "$(LC_ALL=C file -Lsk $SL_ISO | grep -i "x86 boot sector")" ] &&\
492 [ -z "$(LC_ALL=C file -Lsk $SL_ISO | grep -i "DOS/MBR boot sector")" ]
493 then
494 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
495 echo "$SL_ISO is not an ISO 9660 CD-ROM filesystem data file!"
496 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
497 echo "Program terminated!"
498 exit 1
499 fi
500 ;;
501 *.zip)
502 if [ -z "$(LC_ALL=C file -Lsk $SL_ISO | grep -i "Zip archive data")" ]
503 then
504 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
505 echo "$SL_ISO is not a zip file!"
506 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
507 echo "Program terminated!"
508 exit 1
509 fi
510 ;;
511 esac
512 elif [ "$source_mode" = "live-path" ]; then
513 # Case (2): live-path. From the 1st line in file
514 # /lib/live/mount/medium/{Clonezilla-Live-Version,DRBL-Live-Version,GParted-Live-Version}
515 # we can get the file name. Its content is like:
516 # ==================================
517 # clonezilla-live-2.4.2-49-i686-pae
518 # This Clonezilla live iso file was created by this command:
519 # ocs-iso -s --extra-boot-param quiet -y 6.03 -i 2.4.2-49-i686-pae
520 # ==================================
521 # Jun/15/2016 In order to work with toram=live mechanism, we also put those *-Live-Version
522 # in /lib/live/mount/medium/live/, therefore we have check these files, too
523 # /lib/live/mount/medium/live/{Clonezilla-Live-Version,DRBL-Live-Version,GParted-Live-Version}
524 # //NOTE// For backward compatibility both of these two types of files have to be checked.
525 # User might use newer DRBL environment to deploy old version of clonezilla/drbl/gparted live.
526 if [ -e "$LIVE_PATH/Clonezilla-Live-Version" ]; then
527 SL_ISO="$(head -n 1 $LIVE_PATH/Clonezilla-Live-Version)"
528 elif [ -e "$LIVE_PATH/live/Clonezilla-Live-Version" ]; then
529 SL_ISO="$(head -n 1 $LIVE_PATH/live/Clonezilla-Live-Version)"
530 elif [ -e "$LIVE_PATH/DRBL-Live-Version" -o \
531 -e "$LIVE_PATH/live/DRBL-Live-Version" ]; then
532 # To avoid confusion, we switch drbl-live to Clonezilla live since this small linux won't be really DRBL, we just need it work as Clonezilla live.
533 #SL_ISO="$(head -n 1 $LIVE_PATH/DRBL-Live-Version)"
534 SL_ISO="clonezilla-live-0.0.0-0"
535 elif [ -e "$LIVE_PATH/GParted-Live-Version" ]; then
536 SL_ISO="$(head -n 1 $LIVE_PATH/GParted-Live-Version)"
537 elif [ -e "$LIVE_PATH/live/GParted-Live-Version" ]; then
538 SL_ISO="$(head -n 1 $LIVE_PATH/live/GParted-Live-Version)"
539 else
540 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
541 echo "File $LIVE_PATH/Clonezilla-Live-Version, $LIVE_PATH/DRBL-Live-Version, $LIVE_PATH/GParted-Live-Version, or"
542 echo "$LIVE_PATH/live/Clonezilla-Live-Version, $LIVE_PATH/live/DRBL-Live-Version or $LIVE_PATH/live/GParted-Live-Version not found!"
543 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
544 echo "$msg_program_stop."
545 echo -n "$msg_press_enter_to_continue..."
546 read
547 exit 1
548 fi
549 fi
550 # get SL_OS name from iso file name
551 # Ugly, since it's not easy to know which one is which one, here we just judge them by file name.
552 [ -z "$SL_OS" ] && get_SL_OS_NAME
553
554 # Assign different usernames for the clonezilla/drbl/gparted live (RAM) clients.
555 # E.g.
556 # clonezilla-live -> clonezilla
557 # drbl-live -> drbl
558 assgned_username="$(echo $SL_OS | tr "[A-Z]" "[a-z]" | awk -F"-" '{print $1}')"
559
560 # Some settings for SL
561 # insert_rootfs=yes => we have to put the root/main filesystem from SL in initrd
562 # init_type: linuxrc or casper
563 # use_modified_init: yes or no.
564 # 2 types of init: linuxrc or casper. Some are not ready for PXE, we have to mofify, some are ready.
565 # Basically there are 6 types of SL:
566 # (1) linuxrc is ready for PXE, initrd is ready for PXE (insert_rootfs=no, use_modified_init=no). Actually if insert_rootfs=no, use_modified_init must be no. Ex: PLD
567 # (2) linuxrc is ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=no). Ex: Insert 1.39a or later
568 # (3) linuxrc is NOT ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yesyes, use_modified_init=yes). Ex:DSL, PuppyLinux, GeeXbox
569 # (4) casper is ready for PXE, initrd is ready for PXE (insert_rootfs=no, use_modified_init=yes). Actually no such SL now (2007/02/19), maybe in the future when they accept our patch.
570 # (5) casper is NOT ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=yes). Ex: Debian Live, PUD.
571 # (6) casper is ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=yes). Actually no such SL now (2007/02/19), maybe in the future when they accept our patch.
572
573 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
574 dsl|DamnSmallLinux)
575 # SL_NAME: in one word
576 SL_NAME="DSL"
577 SL_FULL_NAME="Damn Small Linux"
578 # e.g. dsl-4.4.10.iso -> 4.4.10
579 SL_VER="$(basename $SL_ISO | sed -e "s/^dsl-//g" -e "s/.iso$//g")"
580 # In DSL, boot kernel files are linux24 and minirt24.gz in /boot/isolinux/
581 bootfiles_path="/boot/isolinux"
582 # in DSL, it's cloop file /cdrom/KNOPPIX/KNOPPIX
583 rootfile_path="/KNOPPIX"
584 rootfile_path_in_initrd="/cdrom/KNOPPIX"
585 insert_rootfs="yes"
586 init_type="linuxrc"
587 use_modified_init="yes"
588 initrd_type="ext2"
589 squashfs="no"
590 ;;
591 puppy|PuppyLinux)
592 # SL_NAME: in one word
593 SL_NAME="PuppyLinux"
594 SL_FULL_NAME="Puppy Linux"
595 # In PuppyLinux, boot kernel files are vmlinuz and initrd.gz in /
596 bootfiles_path="/"
597 # in PuppyLinux, it's squashfs, name is like pup_211.sfs in /
598 rootfile_path="/"
599 rootfile_path_in_initrd="/"
600 insert_rootfs="yes"
601 init_type="linuxrc"
602 use_modified_init="yes"
603 initrd_type="cpio"
604 squashfs="no"
605 ;;
606 clonezilla-live|gparted-live)
607 # SL_NAME: in one word
608 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
609 clonezilla-live)
610 SL_NAME="Clonezilla-live"
611 SL_FULL_NAME="Clonezilla Live"
612 # e.g. clonezilla-live-1.2.2-14.iso -> 1.2.2-14
613 SL_VER="$(basename $SL_ISO | sed -e "s/^clonezilla-live-//g" -e "s/.iso$//g" -e "s/.zip$//g")"
614 ;;
615 gparted-live)
616 SL_NAME="GParted-live"
617 SL_FULL_NAME="GParted Live"
618 # e.g. gparted-live-0.4.5-2.iso -> 0.4.5-2
619 SL_VER="$(basename $SL_ISO | sed -e "s/^gparted-live-//g" -e "s/.iso$//g" -e "s/.zip$//g")"
620 ;;
621 esac
622 # In Clonezilla/GParted live, boot kernel file is vmlinuz1 in /isolinux/
623 bootfiles_path="/live"
624 # in Clonezilla/GParted live, name is like /live/filesystem.squashfs
625 rootfile_path="/live"
626 rootfile_path_in_initrd="" # useless
627 insert_rootfs="no"
628 init_type="live"
629 use_modified_init="no"
630 initrd_type="" # useless
631 squashfs="yes"
632 ;;
633 esac
634
635 #
636 if [ "$batch_mode" != "on" ]; then
637 echo "$msg_delimiter_star_line"
638 echo "$msg_this_script_will_create_SL_diskless: $SL_FULL_NAME"
639 echo -n "$msg_are_u_sure_u_want_to_continue [Y/n] "
640 read confirm_ans
641 case "$confirm_ans" in
642 n|N|[nN][oO])
643 echo "$msg_program_stop"
644 exit 1
645 ;;
646 *)
647 echo "$msg_ok_let_do_it"
648 ;;
649 esac
650 fi
651
652 #
653 if [ "$source_mode" = "iso-zip" ]; then
654 iso_mnt_flag=""
655 isomnt="$(mktemp -d /tmp/drblsl_tmp.XXXXXX)"
656 wd="$(mktemp -d drbl_sl_wd.XXXXXX)"
657 if [ -n "$(echo $SL_ISO | grep -iE "\.iso")" ]; then
658 echo "Mounting the iso file $SL_ISO at mounting point $isomnt"
659 mount -o loop $SL_ISO $isomnt
660 iso_mnt_flag="true"
661 elif [ -n "$(echo $SL_ISO | grep -iE "\.zip")" ]; then
662 unzip $SL_ISO -d $isomnt
663 else
664 echo "$SL_ISO: Unknown file format! Program terminated!"
665 fi
666 elif [ "$source_mode" = "live-path" ]; then
667 isomnt="$LIVE_PATH"
668 fi
669
670 # Find kernel
671 echo "Finding the kernel and initrd from iso..."
672 for i in $isomnt/$bootfiles_path/*; do
673 # sometimes it's "Linux kernel x86", sometimes it's "Linux x86 kernel"
674 # In Ubuntu Sarge (file 4.17-2ubuntu1):
675 # For DSL: linux24: Linux x86 kernel root=0x301-ro vga=normal, bzImage, version 2.4.26 (root@Knoppix) #1 SMP Sa
676 # For Puppy: vmlinuz: Linux kernel x86 boot executable RO-rootFS, root_dev 0x341, swap_dev 0x1, Normal VGA
677 # For INSERT: vmlinuz: Linux kernel x86 boot executable RO-rootFS, root_dev 0x806, swap_dev 0x1, Normal VGA
678 # The problem is that, for some distribution, like INSERT, there is another file "memtest86": memtest86: Linux x86 kernel
679 # For Clonezilla live iso, there is another one: eb.zli (etherboot)
680 # For old file, like Debian Sarge (file 4.12-1) or RH9 (file-3.39-9):
681 # In Debian Sarge: vmlinuz-2.6.8-2-686: x86 boot sector
682 # In RH9: vmlinuz-2.4.20-28.9smp: x86 boot sector
683 # In OpenSuSE 11.3: "file -Ls vmlinuz" gives:
684 # vmlinuz: Linux/x86 Kernel, Setup Version 0x20a, bzImage, Version 3.2.0, Version 3.2.0-24, RO-rootFS, swap_dev 0x4, Normal VGA
685 if [ -n "$(LC_ALL=C file -Lsk $i | grep -iE "(Linux x86 kernel|Linux kernel x86 boot executable|Linux\/x86 Kernel|x86 boot sector)")" ]; then
686 # Ugly
687 # we skip memtest, etherboot, ipxe, freedos...
688 if [ -z "$(LC_ALL=C echo $i | grep -iE "(memtest|mt86|eb.zli|memdisk|gpxe.lkn|ipxe.lkn|ipxe.efi|freedos|fdos)")" ]; then
689 kernel="$i"
690 break
691 fi
692 fi
693 done
694 if [ -n "$kernel" ]; then
695 echo "Found the kernel: $kernel"
696 else
697 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
698 echo "The kernel does NOT exist! Program terminated!"
699 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
700 umount_and_clean_tmp_working_dirs
701 exit 1
702 fi
703
704 # Find initrd
705 # UGLY! Here we assume only one gzip/cpio file exists, and it's initrd.
706 for i in $isomnt/$bootfiles_path/* $isomnt/$rootfile_path/*; do
707 if [ -n "$(LC_ALL=C file -Lsk $i | grep -iE "gzip compressed data")" ]; then
708 oldinitrd="$i"
709 uncompress_to_stdout="gunzip -c"
710 compress_to_stdout="gzip -c"
711 break
712 elif [ -n "$(LC_ALL=C file -Lsk $i | grep -iE "XZ compressed data")" ]; then
713 oldinitrd="$i"
714 uncompress_to_stdout="xzcat"
715 compress_to_stdout="xz -c"
716 break
717 elif [ -e "$(dirname $i)/../Clonezilla-Live-Version" -a -n "$(echo $i | grep -iE "initrd.img")" ]; then
718 # This is a workaround for CentOS 5, since its "file" command won't tell XZ format. For Clonezilla live 2.x, we have used XZ format for initrd.
719 oldinitrd="$i"
720 uncompress_to_stdout="xzcat"
721 compress_to_stdout="xz -c"
722 break
723 elif [ -n "$(LC_ALL=C echo $i | grep -iE "\/miniroot.lz$")" ]; then
724 # For INSERT, the initrd is miniroot.lz, which is lzma format. Most of the program file does not have the magic for that.
725 oldinitrd="$i"
726
727 # There are two types of lzma, although they all said they are 4.32/4.33
728 # (1) MDV2007, Ubuntu Etch
729 # LZMA 4.32 Copyright (c) 1999-2005 Igor Pavlov 2005-12-09
730 # Usage: LZMA <e|d> inputFile outputFile [<switches>...]
731 # e: encode file
732 # d: decode file
733 # -si: read data from stdin
734 # -so: write data to stdout
735 # (2) Debian Etch
736 # lzma 4.32.0beta3 Copyright (C) 2006 Ville Koskinen
737 # Based on LZMA SDK 4.43 Copyright (C) 1999-2006 Igor Pavlov
738 # -c --stdout output to standard output
739 # -d --decompress force decompression
740 # -z --compress force compression
741 if [ -n "$(LC_ALL=C lzma --h 2>&1 | grep -iEw "\-so:")" ]; then
742 uncompress_to_stdout="lzma d -so"
743 compress_to_stdout="lzma e -so"
744 else
745 uncompress_to_stdout="lzma -d -c -S .lz"
746 compress_to_stdout="lzma -z -c"
747 fi
748 break
749 elif [ -n "$(LC_ALL=C file -Lsk $i | grep -i "ASCII cpio archive")" ]; then
750 oldinitrd="$i"
751 break
752 fi
753 done
754 if [ -n "$oldinitrd" ]; then
755 echo "Found the initrd: $oldinitrd"
756 else
757 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
758 echo "The initrd does NOT exist! Program terminated!"
759 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
760 umount_and_clean_tmp_working_dirs
761 exit 1
762 fi
763 # we rename the NBI kernel and img, like dsl-linux24 and dsl-minirt24.gz
764 nbi_kernel="${SL_NAME}-${kernel##*/}"
765 nbi_initrd="${SL_NAME}-${oldinitrd##*/}"
766 if [ "$squashfs" = "yes" ]; then
767 get_SL_rootfile
768 squashfs_file="${SL_NAME}-${rootfile##*/}"
769 fi
770 # For Clonezilla/GParted live, we should try to find the boot parameters now
771 case "$(echo $SL_OS | tr "[A-Z]" "[a-z]")" in
772 clonezilla-live|gparted-live)
773 initrd_filename="$(basename $oldinitrd)"
774 # The append line e.g.:
775 # append initrd=/live/initrd1.img boot=live union=aufs ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=791 nolocales
776 # We have to remove ip=frommedia because the /etc/resolv.conf got in live-boot (actually this program scripts/live-bottom/23networking) won't be copied to /etc/resolv.conf if ip=frommedia exists in boot parameters.
777 # 2012/Nov/1 The patched live-boot 2.0.15-1.drbl15 has fixed this issue, and live-boot 3.x has no such issue. Therefore no more removing ip=frommedia.
778 # 2014/Jan/19 The syslinux and isolinux dirs have been unified in one dir "syslinux"
779 if [ -e $isomnt/boot/grub/grub.cfg ]; then
780 grub_cfg_f="$isomnt/boot/grub/grub.cfg"
781 else
782 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
783 echo "File grub.cfg was _NOT_ found in live system!"
784 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
785 echo "$msg_program_stop"
786 exit 1
787 fi
788 # Assign and filter out the ocs_prerun* in case it's preseed by users.
789 # (1) ocs_prerun*
790 # (2) "drbl_live_noconfx" which we will add later
791 # (3) "username", we will add it later
792 # (4) more... Check function filter_cl_gp_boot_param.
793 # get the description from grub config. It's more precise than isolinux.cfg we used before.
794 # because we can locate default menu by "--id live-default".
795 lines="$(get_grub_efi_image_block live-default $grub_cfg_f)"
796 begin_line="$(echo $lines | awk -F" " '{print $1}')"
797 end_line="$(echo $lines | awk -F" " '{print $2}')"
798 search_cmd="if ($begin_line..$end_line) {print}"
799 cl_gp_boot_param="$(LC_ALL=C perl -n -e "$search_cmd" $grub_cfg_f | \
800 grep -iw "\$linux_cmd" | filter_cl_gp_boot_param)"
801 ;;
802 esac
803
804 #
805 case "$insert_rootfs" in
806 yes)
807 case "$init_type" in
808 "linuxrc") create_linuxrc_pxe_initrd_with_rootfs_inserted ;;
809 "casper") create_casper_pxe_initrd_with_rootfs_inserted ;;
810 esac
811 ;;
812 no)
813 case "$squashfs" in
814 "yes") put_kernel_initrd_root_fs_on_pxe_server ;;
815 *) put_pxe_initrd_without_rootfs_inserted ;;
816 esac
817 ;;
818 esac
819 #
820 umount_and_clean_tmp_working_dirs
821
822 # append the config file in pxelinux dir.
823 if [ -z "$(grep -E "^[[:space:]]*label[[:space:]]+$SL_NAME[[:space:]]*$" $PXELINUX_DIR/default)" ] || [ "$force_to_update_pxecfg" = "yes" ]; then
824 if [ -n "$(grep -E "^[[:space:]]*label[[:space:]]+$SL_NAME[[:space:]]*$" $PXELINUX_DIR/default)" ]; then
825 echo "First removing $SL_NAME setting in $PXELINUX_DIR/default..."
826 delete_label_block_pxe_img $SL_NAME $PXELINUX_DIR/default
827 fi
828 echo "Append the $SL_FULL_NAME config in $PXELINUX_DIR/default..."
829 cat <<-SL_PXE >> $PXELINUX_DIR/default
830 label $SL_NAME
831 # MENU DEFAULT
832 # MENU HIDE
833 MENU LABEL $SL_FULL_NAME $SL_VER (Ramdisk)
834 # MENU PASSWD
835 KERNEL $nbi_kernel
836 APPEND $append_param_in_pxe_cfg
837
838 TEXT HELP
839 $SL_FULL_NAME $SL_VER runs on RAM
840 ENDTEXT
841
842 SL_PXE
843 fi
844
845 # append the config file in grub efi dir.
846 if [ -z "$(grep -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ] || [ "$force_to_update_pxecfg" = "yes" ]; then
847 if [ -n "$(grep -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ]; then
848 echo "First removing $SL_NAME setting in $GRUB_EFINB_DIR/grub.cfg..."
849 delete_menuentry_block_grub_img clonezilla-live-client $GRUB_EFINB_DIR/grub.cfg
850 fi
851 echo "Append the $SL_FULL_NAME config in $GRUB_EFINB_DIR/grub.cfg..."
852 cat <<-SL_PXE >> $GRUB_EFINB_DIR/grub.cfg
853 menuentry "$SL_NAME $SL_VER (Ramdisk)" --id clonezilla-live-client {
854 # This is Clonezilla live especially to be run for Clonezilla SE.
855 # Do _NOT_ edit unless you know what you are doing!
856 echo "Enter $SL_FULL_NAME $SL_VER (Ramdisk)..."
857 echo 'Loading $nbi_kernel...'
858 \$linux_cmd $nbi_kernel $append_param_in_pxe_cfg
859 echo 'Loading initial ramdisk $nbi_initrd...'
860 \$initrd_cmd $nbi_initrd
861 }
862
863 SL_PXE
864 fi
865 # Put the version number
866 cat <<-SL_INFO_PXE > $pxecfg_pd/${SL_NAME}-info.txt
867 $SL_FULL_NAME version: $SL_VER
868 Files were extracted from "$(basename $SL_ISO)"
869 SL_INFO_PXE
870 # Put the prompt messages
871 echo "$msg_delimiter_star_line"
872 if [ "$booting_messages" = "on" ]; then
873 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
874 echo "$msg_all_set_you_can_turn_on_clients"
875 #echo "$msg_note! $msg_etherboot_5_4_is_required"
876 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
877 fi
878 } # end of install_SL
879
880 #
881 uninstall_SL(){
882 # convert
883 case "$SL_TO_BE_REMOVED" in
884 [aA][lL][lL])
885 SL_TO_BE_REMOVED="$supported_SL_dists"
886 ;;
887 esac
888 echo "Uninstalling installed Small Linux..."
889 for id in $SL_TO_BE_REMOVED; do
890 if [ -z "$(echo "$supported_SL_dists" | grep -Ew "$id")" ]; then
891 echo "$SL_TO_BE_REMOVED is an unknown Small Linux! Program terminated!"
892 exit 1
893 fi
894 # remove the block in pxelinux
895 if [ -n "$(grep -E "^[[:space:]]*label[[:space:]]+$id[[:space:]]*$" $PXELINUX_DIR/default)" ]; then
896 echo "Removing $id setting in $PXELINUX_DIR/default..."
897 delete_label_block_pxe_img $id $PXELINUX_DIR/default
898 fi
899 if [ -n "$(grep -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ]; then
900 echo "First removing $SL_NAME setting in $GRUB_EFINB_DIR/grub.cfg..."
901 delete_menuentry_block_grub_img clonezilla-live-client $GRUB_EFINB_DIR/grub.cfg
902 fi
903 # remove vmlinuz and initrd
904 if [ -n "$(ls $pxecfg_pd/${id}-* 2>/dev/null)" ]; then
905 echo "Removing installed $id if it exists..."
906 rm -fv $pxecfg_pd/${id}-*
907 fi
908 if ! is_drbl_live_env; then
909 # When it's not in drbl live env, the files are copied to $drbl_common_root/clonezilla-live/, therefore we remove them. Otherwise it's a mount point.
910 if [ -d "$drbl_common_root/clonezilla-live/" ]; then
911 rm -rfv $drbl_common_root/clonezilla-live/*
912 fi
913 fi
914 done
915 } # end of uninstall_SL
916
917 #############
918 ### MAIN ###
919 #############
920 #
921 check_if_root
922
923 # Parse command-line options
924 while [ $# -gt 0 ]; do
925 case "$1" in
926 -b|--batch-mode) shift; batch_mode="on" ;;
927 -e|--fetch-link) shift; use_link_in_fetch_mode="yes" ;;
928 -l|--language)
929 shift
930 if [ -z "$(echo $1 |grep ^-.)" ]; then
931 # skip the -xx option, in case
932 specified_lang="$1"
933 [ -z "$specified_lang" ] && USAGE && exit 1
934 shift
935 fi
936 ;;
937 -i|--install)
938 shift; mode="install"
939 if [ -z "$(echo $1 |grep ^-.)" ]; then
940 # skip the -xx option, in case
941 SL_ISO="$1"
942 [ -z "$SL_ISO" ] && USAGE && exit 1
943 shift
944 fi
945 ;;
946 -p|--live-path)
947 shift; mode="install"
948 if [ -z "$(echo $1 |grep ^-.)" ]; then
949 # skip the -xx option, in case
950 LIVE_PATH="$1"
951 [ -z "$LIVE_PATH" ] && USAGE && exit 1
952 shift
953 fi
954 ;;
955 -d|--distribution)
956 shift;
957 if [ -z "$(echo $1 |grep ^-.)" ]; then
958 # skip the -xx option, in case
959 SL_OS="$1"
960 [ -z "$SL_OS" ] && USAGE && exit 1
961 shift
962 fi
963 ;;
964 -f|--use-nfsroot) shift; rootfs_location="nfsroot" ;;
965 -k|--keep-pxecfg) shift; force_to_update_pxecfg="no" ;;
966 -n|--no-prompt-boot-message) shift; booting_messages="off";;
967 -o|--add-ocs-server) shift; add_ocs_server="yes" ;;
968 -s|--server-ip)
969 shift;
970 if [ -z "$(echo $1 |grep ^-.)" ]; then
971 # skip the -xx option, in case
972 server_IP="$1"
973 [ -z "$server_IP" ] && USAGE && exit 1
974 shift
975 fi
976 ;;
977 -u|--uninstall)
978 shift; mode="uninstall"
979 if [ -z "$(echo $1 |grep ^-.)" ]; then
980 # skip the -xx option, in case
981 SL_TO_BE_REMOVED="$1"
982 [ -z "$SL_TO_BE_REMOVED" ] && USAGE && exit 1
983 shift
984 fi
985 ;;
986 -V|--dist-version)
987 shift;
988 if [ -z "$(echo $1 |grep ^-.)" ]; then
989 # skip the -xx option, in case
990 SL_VER="$1"
991 [ -z "$SL_VER" ] && USAGE && exit 1
992 shift
993 fi
994 ;;
995 -v|--verbose)
996 verbose="on"
997 verbose_opt="-v"
998 shift ;;
999 *) USAGE && exit 1 ;;
1000 esac
1001 done
1002 # mode is essential
1003 [ -z "$mode" ] && USAGE && exit 1
1004
1005 # Load the language file
1006 ask_and_load_lang_set $specified_lang
1007
1008 #
1009 if [ -n "$SL_ISO" ]; then
1010 source_mode="iso-zip"
1011 elif [ -n "$LIVE_PATH" ]; then
1012 source_mode="live-path"
1013 fi
1014
1015 # run it
1016 case "$mode" in
1017 install) install_SL;;
1018 uninstall) uninstall_SL;;
1019 esac