[1331] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Make USB key to save/restore HW configuration on a ProLiant DL 680 G7
|
---|
| 4 | #
|
---|
| 5 | #set -x
|
---|
| 6 |
|
---|
| 7 | sync
|
---|
| 8 | DRIVE=$1
|
---|
| 9 | [ -z $DRIVE ] && echo "Usage: $0 device." && exit -1
|
---|
| 10 | [ ! -b $DRIVE ] && echo "$1 is not a block device. Exiting." && exit -1
|
---|
| 11 | KPARTX=`which kpartx`
|
---|
| 12 | [ $? -ne 0 ] && echo "kpartx is missing. exiting" && exit -1
|
---|
| 13 | SYSLINUX=`which syslinux`
|
---|
| 14 | [ $? -ne 0 ] && echo "syslinux is missing. exiting" && exit -1
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | [[ $DRIVE == /dev/sda* ]] && echo "For security, the script does not work on /dev/sda* devices" && exit -1
|
---|
| 18 |
|
---|
| 19 | [[ `cat /proc/mounts | grep $DRIVE` != "" ]] && echo "$DRIVE is mounted. Exit now." && exit -1
|
---|
| 20 |
|
---|
| 21 | # Wipe the partition table.
|
---|
| 22 | dd if=/dev/zero of=$DRIVE bs=4096 count=1 2>&1 > /dev/null
|
---|
| 23 | [ $? -ne 0 ] && echo "WARNING: Unable to erase MBR on $DRIVE."
|
---|
| 24 |
|
---|
| 25 | # Create partition
|
---|
| 26 | echo "Creating the partition on $DRIVE"
|
---|
| 27 | sfdisk -q -D $DRIVE << EOF
|
---|
| 28 | 0,,C,*
|
---|
| 29 | EOF
|
---|
| 30 | [ $? -ne 0 ] && echo "Unable to partition the key $DRIVE. Exiting" && exit -1
|
---|
| 31 | sfdisk -q -R $DRIVE
|
---|
| 32 |
|
---|
| 33 | if [[ $DRIVE == /dev/loop* ]]; then
|
---|
| 34 | $KPARTX -av $DRIVE
|
---|
| 35 | PART="/dev/mapper/${DRIVE#/dev/}p1"
|
---|
| 36 | else
|
---|
| 37 | PART=${DRIVE}1
|
---|
| 38 | fi
|
---|
| 39 |
|
---|
| 40 | echo "Creating the master boot record on $DRIVE"
|
---|
| 41 | dd if=./mbr.bin of=$DRIVE > 2>&1 /dev/null
|
---|
| 42 | [ $? -ne 0 ] && echo "Unable to copy MBR on $DRIVE. Please check the key. Exiting" && exit -1
|
---|
| 43 |
|
---|
| 44 | # FAT32 filesystem labeled 'LiveUSB'
|
---|
| 45 | sleep 5
|
---|
| 46 | echo "Creating FAT filesystem on $PART"
|
---|
| 47 | mkfs.vfat -n LiveUSB $PART > /dev/null
|
---|
| 48 | [ $? -ne 0 ] && echo "Unable to format the partition $PART as VFAT. Exiting" && exit -1
|
---|
| 49 |
|
---|
| 50 | # The SQUASHFS containing the EXT3 filesystem with the
|
---|
| 51 | # minimum OS and the SSTK tools
|
---|
| 52 | SQUASHFS=$(mktemp -d squashfs.XXXX)
|
---|
| 53 | mkdir $SQUASHFS/LiveOS
|
---|
| 54 | dd if=ext3fs.img of=$SQUASHFS/LiveOS/ext3fs.img 2>&1 > /dev/null
|
---|
| 55 | [ $? -ne 0 ] && echo "Unable to copy the squashfs FS. Exiting" && exit -1
|
---|
| 56 |
|
---|
| 57 | TMPDIR=`mktemp -d mkusb.XXXX`
|
---|
| 58 | if [ ! -d "$TMPDIR" ]; then
|
---|
| 59 | echo "$TMPDIR is not a directory. Exiting"
|
---|
| 60 | exit -1
|
---|
| 61 | else
|
---|
| 62 | if [[ "$TMPDIR" == "/" ]]; then
|
---|
| 63 | echo "$TMPDIR is /. Exiting"
|
---|
| 64 | exit -1
|
---|
| 65 | fi
|
---|
| 66 | fi
|
---|
| 67 |
|
---|
| 68 | ret=0
|
---|
| 69 | mount $PART $TMPDIR
|
---|
| 70 | if [ $? -ne 0 ] ; then
|
---|
| 71 | echo "Unable to mount $PART under $TMPDIR. Exiting"
|
---|
| 72 | ret=1
|
---|
| 73 | else
|
---|
| 74 | mkdir $TMPDIR/syslinux $TMPDIR/LiveOS $TMPDIR/data_files $TMPDIR/fw_files $TMPDIR/log
|
---|
| 75 | cat > $TMPDIR/fw_files/README << EOF
|
---|
| 76 | ProLIant Linux entry point:
|
---|
| 77 | http://www.hp.com/go/proliantlinux
|
---|
| 78 |
|
---|
| 79 | Firmware update for the DL 380 G7 are available at
|
---|
| 80 | http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareIndex.jsp?lang=en&cc=us&prodNameId=4091432&prodTypeId=15351&prodSeriesId=4091412&swLang=8&taskId=135&swEnvOID=4103
|
---|
| 81 |
|
---|
| 82 | Need to download the various .scexe files and place them in that directory so the server is being updated when choosing the fw option in boot menu.
|
---|
| 83 |
|
---|
| 84 | Latest FW available at time of USB Key built:
|
---|
| 85 | BIOS P67 2011.05.05 (CP015473.scexe)
|
---|
| 86 | iLO3 1.20 2011-04-05 (CP014002.scexe)
|
---|
| 87 | Smart Array 5.06 2011-08-16 (CP015807.scexe)
|
---|
| 88 | Embedded Broadcom NIC 2.3.0 2011-02-24 (CP014348.scexe)
|
---|
| 89 | NC364T NIC - None available
|
---|
| 90 | NC365T NIC - None available
|
---|
| 91 | EOF
|
---|
| 92 | echo "Copying system files..."
|
---|
| 93 | $SYSLINUX -i -d syslinux $PART
|
---|
| 94 | if [ $? -ne 0 ]; then
|
---|
| 95 | echo "Unable to syslinux $PART. Exiting"
|
---|
| 96 | ret=1
|
---|
| 97 | else
|
---|
| 98 | cp vmlinuz initramfs.img syslinux.cfg $TMPDIR/syslinux
|
---|
| 99 | cp fw_files/* $TMPDIR/fw_files
|
---|
| 100 | cp data_files/* $TMPDIR/data_files
|
---|
| 101 | mksquashfs $SQUASHFS $TMPDIR/LiveOS/squashfs.img
|
---|
| 102 | if [ $? -ne 0 ]; then
|
---|
| 103 | echo "Unable to recreate the squash FS $SQUASHFS. Exiting"
|
---|
| 104 | ret=1
|
---|
| 105 | fi
|
---|
| 106 | fi
|
---|
| 107 | fi
|
---|
| 108 | rm -rf $SQUASHFS
|
---|
| 109 | if [ $ret -eq 1 ]; then
|
---|
| 110 | umount $TMPDIR
|
---|
| 111 | exit $ret
|
---|
| 112 | fi
|
---|
| 113 |
|
---|
| 114 | echo "Done"
|
---|
| 115 |
|
---|
| 116 | echo "Unmounting file system. It may take some time to flush the buffers..."
|
---|
| 117 | umount $TMPDIR
|
---|
| 118 |
|
---|
| 119 | [[ $PART == "/dev/mapper/loop*" ]] && $KPARTX -dv $DRIVE
|
---|
| 120 |
|
---|
| 121 | rm -rf $TMPDIR
|
---|