Using the MilaX Live CD for failsafe bootingby Bernd Schemmer, June 2009 Homepage: http://www.bnsmb.de/ Table of contents
History
IntroductionPurposeMilaX is a small size Live CD distribution which runs completely off a CD . In addition to various other usages (see links) MilaX can also be used as failsafe image for the Solaris OS. Note: A failsafe image is an image for a ramdisk from which the Solaris OS can boot. This boot method is used, for example, if you do a "boot -s" in newer Solaris versions. This article describes how to create a failsafe image from the MilaX Live CD. In the rest of the article, the failsafe image is simply called "the image." ScopeThis article only describes how to create the image for the Solaris OS for x86 platforms. PrerequisitesA working Solaris installation (either Solaris, Solaris Nevada, or OpenSolaris); the MilaX image for x86 described here was tested with Solaris Express Community Edition Build 111, Solaris 10 10/08 OS, and OpenSolaris 2009.06 111a. The MilaX Live CD; for this article, I used MilaX for x86 version 0.3.3 and version 0.4. ReferencesSolaris and Linux on one USB stick - dual usage Adding a Live CD Distribution to an existing Solaris installation Converting the MilaX Live CD for SPARC to a WANBOOT image Creating a failsafe image with MilaX for the Solaris OS on x86 PlatformsPreparationTo create the image with MilaX, boot from the MilaX Live CD and open a root shell. The first step is to create a file for the image: # Note: /mnt/solaris0 is mounted to the internal hard disk in this example
#
(root@milax) # mkfile -n 500m /mnt/solaris0/milax_img
Next lofi mount the image, create a filesystem on the lofi device, and mount the lofi device: (root@milax) # LOFI_DEV=$( lofiadm -a /mnt/solaris0/milax_img ) && \ newfs ${LOFI_DEV} (root@milax) # mkdir /tmp/milax (root@milax) # mount ${LOFI_DEV} /tmp/milax Then copy the script copy_milax_to_img.sh (see the appendix) to the machine, make it executable using chmod, and execute it, e .g (root@milax) # ./copy_milax_to_img.sh /tmp/milax Starting to copy data from UFS root to /tmp/milax - this may take some time. /tmp/milax/etc/crypto/certs/SUNWObjectCA linked to /tmp/milax/etc/certs/SUNWObjectCA /tmp/milax/etc/rc0.d/K50pppd linked to /tmp/milax/etc/init.d/pppd ... tar: ./svc/volatile/kcfd_door is not a file. Not dumped tar: ./sysevent/devfsadm_event_channel/1 is not a file. Not dumped ################################################################### MilaX now installed on /tmp/milax ################################################################### After the script is done, rename the kernel in the image. (root@milax) # mv /tmp/milax/platform/i86pc/kernel/unix /tmp/milax/platform/i86pc/kernel/milax_unix Then umount the image and delete the lofi device: (root@milax) # umount /tmp/milax (root@milax) # lofiadm -d ${LOFI_DEV} Now copy the image file, /mnt/solaris0/milax_img in this example, to a save place. InstallationTo install the image, execute these steps. Log in as root to the target machine and copy the image to the machine; in this example, we assume the image is called milax_img and it is in the directory /milax. Then lofi mount the image: bash-3.2# mkdir /tmp/milax bash-3.2# mount $( lofiadm -a /milax/milax_img ) /tmp/milax Copy the kernel from the image to the hard disk. bash-3.2# cp /tmp/milax/platform/i86pc/kernel/milax_unix /milax/platform/i86pc/kernel/milax_unix And umount the image and delete the lofi device: bash-3.2 # umount /tmp/milax bash-3.2# lofiadm -d /milax/milax_img And last, add an additional entry for MilaX failsafe to the GRUB boot menu: title MilaX 0.3.3 (32 Bit) (failsafe) findroot (pool_rpool,0,a) kernel$ /platform/i86pc/kernel/milax_unix module$ /milax/milax.img That's it; now you can boot the failsafe image with MilaX for maintenance tasks on your main Solaris installation. Update 15.06.2009:
Customizing the failsafe imageTo customize the Solaris OS in the image boot into the normal Solaris OS and lofi mount the image, do the following (in this example, we assume the image is called milax_img and it is in the directory /milax). Lofi mount the image: bash-3.2# mkdir /tmp/milax bash-3.2# mount $( lofiadm -a /milax/milax_img ) /tmp/milax Now do your customizations. And finally, umount the image again: bash-3.2 # umount /tmp/milax bash-3.2# lofiadm -d /milax/milax_img TroubleshootingMy changes to the failsafe image are not persistent.To change the contents of the image, you must lofi mount the image (see above); changes made while the machine is booted from the image are not persistent. There's no network connection after booting from the failsafe imageThe Solaris OS in the failsafe image needs a DHCP server to automatically configure the network adapter. If there is no DHCP server in your environment, you must either add a static IP configuration to the image (see above) or configure the network manually every time after the image is booted. The X Server starts automatically but not the Window managerThere's a bug in MilaX 0.4 that the Window manager does not start automatically every reboot. If this the case you only see the grey background from the X server and no menus. To get around this bug simply kill the X Server (using CTRL-ALT-BACKSPACE) and restart the X Server using the command startx, e.g. (alex@milx) # startx How to use more than one MilaX failsafe imageTo use more than one MilaX failsafe image use unique
names for the kernel and the image, e.g. Appendixcopy_milax_to_img.sh#!/usr/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Script to install MilaX into a boot image for failsafe booting # written by Bernd Schemmer # based on the sript to install MilaX to ZFS # By Alexander R. Eremin, April 4 2008. # Thanks to Tim Foster for basic zfs-boot script # # # History # v1.10 14.06.2009 /bs # added support for MilaX 0.4 # # Make sure only root can run our script if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" exit 1 fi # check arguments if [ "$#" -lt 1 ] || [ $1 == "-h" ] || [ $1 == "--help" ] then echo "Usage : $0 targetfilesystem" echo "eg. $0 /mnt/milax" exit 1 fi TARGET_FS="$1" # # get MiIaX version # if [ -f /etc/release ] ; then MILAX_VERSION="$( head -1 /etc/release | tr -s " " | cut -f3 -d " " )" RELEASE_FOUND=0 else MILAX_VERSION="$( uname -a | tr -s "_" " " | cut -f5 -d " " )" RELEASE_FOUND=1 fi case ${MILAX_VERSION} in 0.4 ) echo "Using MilaX version ${MILAX_VERSION}" ;; 0.3.3 ) echo "Using MilaX version ${MILAX_VERSION}" ;; * ) if [ ${RELEASE_FOUND} = 0 ] ; then echo "WARNING: Untested MilaX version found: ${MILAX_VERSION} -- assuming this version is compatible to MilaX version 0.4" MILAX_VERSION=0.4 else echo "WARNING: Untested MilaX version found: ${MILAX_VERSION} -- assuming this version is compatible to MilaX version 0.3.3" MILAX_VERSION=0.3.3 fi ;; esac # directory with the additional files # home=/usr/dss/share/hdinstall # added 09.06.2009 22:11 /bs -- start umount /lib/libc.so.1 # added 09.06.2009 22:11 /bs -- end # start copying main data over to it echo "Starting to copy data from UFS root to ${TARGET_FS} - this may take some time." cd / find . -xdev -depth -print | cpio -pvdm ${TARGET_FS} 2>&1 > /dev/null # libc! cp -rP /lib/libc.so* ${TARGET_FS}/lib 2>&1 > /dev/null mkdir -p ${TARGET_FS}/alex cd /alex find . -xdev -depth -print | cpio -pvdm ${TARGET_FS}/alex 2>&1 > /dev/null mkdir -p ${TARGET_FS}/root cd /root find . -xdev -depth -print | cpio -pvdm ${TARGET_FS}/root 2>&1 > /dev/null mkdir -p ${TARGET_FS}/usr cd /usr find . -xdev -depth -print | cpio -pvdm ${TARGET_FS}/usr 2>&1 > /dev/null mkdir -p ${TARGET_FS}/system/object mkdir -p ${TARGET_FS}/system/contract mkdir -p ${TARGET_FS}/tmp mkdir -p ${TARGET_FS}/mnt mkdir -p ${TARGET_FS}/proc mkdir -p ${TARGET_FS}/var/run mkdir -p ${TARGET_FS}/dev/fd touch ${TARGET_FS}/etc/mnttab touch ${TARGET_FS}/etc/dfs/sharetab chmod 555 ${TARGET_FS}/system/object chmod 555 ${TARGET_FS}/system/contract chmod 555 ${TARGET_FS}/proc chmod 777 ${TARGET_FS}/tmp chmod 755 ${TARGET_FS}/etc/svc/volatile chmod 755 ${TARGET_FS}/var/run chmod 555 ${TARGET_FS}/dev/fd chmod 444 ${TARGET_FS}/etc/mnttab chmod 755 ${TARGET_FS}/usr chmod 755 ${TARGET_FS}/alex chmod 755 ${TARGET_FS}/root chmod 755 ${TARGET_FS}/mnt chown -R alex:adm ${TARGET_FS}/alex chown root ${TARGET_FS}/system/object chown root ${TARGET_FS}/system/contract chown root ${TARGET_FS}/proc chown root ${TARGET_FS}/tmp chown root ${TARGET_FS}/etc/svc/volatile chown root ${TARGET_FS}/var/run chown root ${TARGET_FS}/dev/fd chown root ${TARGET_FS}/etc/mnttab chgrp root ${TARGET_FS}/system/object chgrp root ${TARGET_FS}/system/contract chgrp sys ${TARGET_FS}/tmp chgrp root ${TARGET_FS}/proc chgrp sys ${TARGET_FS}/etc/svc/volatile chgrp sys ${TARGET_FS}/var/run chgrp root ${TARGET_FS}/dev/fd chgrp root ${TARGET_FS}/etc/mnttab # now populate the devices and /dev directories in ${TARGET_FS} # do this by lofs mounting / and pulling the files directly mkdir -p /zfs-root-tmp.$$ mount -F lofs -o nosub / /zfs-root-tmp.$$ (cd /zfs-root-tmp.$$; tar cf - devices dev ) | (cd ${TARGET_FS}; tar xfp -) 2>&1 > /dev/null cd / umount /zfs-root-tmp.$$ rm -rf /zfs-root-tmp.$$ # copy last etc cd /etc tar cf - . | (cd ${TARGET_FS}/etc ; tar xfp -) 2>&1 > /dev/null if [ "${MILAX_VERSION}"x = "0.3.3"x ] ; then cp $home/misc/xstart ${TARGET_FS}/usr/dss/sbin/ cp $home/misc/live-fs-root ${TARGET_FS}/lib/svc/method/ cp $home/misc/repository.db ${TARGET_FS}/etc/svc/ elif [ "${MILAX_VERSION}"x = "0.4"x ] ; then rm ${TARGET_FS}/lib/svc/method/live-fs-root cd ${TARGET_FS}/lib/svc/method/ ln -s fs-root live-fs-root cd / fi # copy vfstab cp $home/misc/vfstab ${TARGET_FS}/etc/vfstab echo "/devices/ramdisk:a - / ufs 1 no rw,notime">>${TARGET_FS}/etc/vfstab echo " ###################################################################" echo echo " MilaX now copied to ${TARGET_FS}" echo echo " ###################################################################" |