Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- . /common.sh
- DISK1_PART1=/dev/sda1
- disk=/dev/sda
- MD0=/dev/md0
- MD0VG=md0_vg
- BFDLV=BFDlv
- BFDDEV=/dev/md0_vg/BFDlv
- workarea="/usb_drive/emctools/hmnhd_images/temp"
- stage1File=$workarea/stage1.wrapped
- ubootFile=$workarea/u-boot.wrapped
- kernelFile=$workarea/zImage
- initrdFile=$workarea/initrd
- reinstallFile="/usb_drive/emctools/hmnhd_images/reinstall"
- USB_MNT_DIR=usb_drive
- mount_vol()
- {
- mkdir -p /sysroot/boot
- vgchange -ay
- mount $BFDDEV sysroot/boot -o noatime
- return $?
- }
- create_partitions()
- {
- local disk=$1
- echo "---Creating partitions"
- dd if=/dev/zero of=$1 bs=1M count=32
- parted $disk mklabel gpt
- parted $disk mkpart primary 65536s 42008576s
- parted $disk set 1 raid on
- wait
- }
- start_sys_raid()
- {
- local disk=$1
- mdadm --create $MD0 --force --auto=md --raid-devices=1 --level=linear --run "${disk}1"
- }
- create_volumes()
- {
- # create lvm volumes for BFD and System
- pvcreate -ff -y $MD0
- vgcreate $MD0VG $MD0
- lvcreate -L 4G -n $BFDLV $MD0VG
- }
- format_sys_partitions()
- {
- mke2fs $BFDDEV
- }
- write_bootrom_directions()
- {
- local disk=$1
- echo "---Writing bootrom directions"
- #
- # Boot ROM loading directions:
- #
- # Secondary checksum (location + length)
- # Secondary location in sectors
- # Secondary length in sectors (minus half a sector due to boot ROM bug)
- #
- # Primary checksum (location + length)
- # Primary location in sectors
- # Primary length in sectors (minus half a sector due to boot ROM bug)
- #
- #perl <<EOF > $USB_MNT_DIR/bootrom.txt
- # print "\x00" x 0x1a4;
- # print "\x00\x5f\x01\x00";
- # print "\x00\xdf\x00\x00";
- # print "\x00\x80\x00\x00";
- # print "\x00" x (0x1b0 -0x1a4 -12 );
- # print "\x22\x80\x00\x00";
- # print "\x22\x00\x00\x00";
- # print "\x00\x80\x00\x00";
- #EOF
- dd if=$USB_MNT_DIR/bootrom.txt of="$disk" bs=512
- }
- hex_byte () {
- dd if=/dev/urandom bs=1 count=1 2>/dev/null \
- | od -x | head -1 | cut -d' ' -f2- \
- | tr -d ' ' | cut -c 3-4 | tr '[a-f]' '[A-F]'
- }
- write_hidden_sectors()
- {
- local disk=$1
- echo "---Writing hidden sectors"
- dd if=$stage1File of="$disk" bs=512 seek=34
- dd if=$ubootFile of="$disk" bs=512 seek=154
- dd if=$kernelFile of="$disk" bs=512 seek=1290
- dd if=$initrdFile of="$disk" bs=512 seek=16674
- # Secondary copies of critical blocks
- # TODO- configure U-Boot to use these if initial ones are bad
- dd if=$stage1File of="$disk" bs=512 seek=57088
- dd if=$ubootFile of="$disk" bs=512 seek=57208
- dd if=$kernelFile of="$disk" bs=512 seek=58344
- # write U-Boot environment, with new random MAC address
- #oui="0x00,0xD0,0xB8"
- #newmac=${oui},0x`hex_byte`,0x`hex_byte`,0x`hex_byte`
- #echo "Setting MAC address to ${newmac}"
- #cat $USB_MNT_DIR/ix1-env.txt \
- #| sed -e "s/\(mac_adr=\)\S* /\1${newmac} /" \
- #| /$USB_MNT_DIR/saveenv \
- #> $USB_MNT_DIR/ix1-env_new.bin || true
- dd if=/$USB_MNT_DIR/ix1-env_old.bin of="$disk" bs=512 seek=558 count=16
- rm /$USB_MNT_DIR/ix1-env_old.bin
- }
- readenv()
- {
- # keep the env value same as from the install script
- local disk=$1
- echo "Reading the old environment values"
- dd if="$disk" of=/$USB_MNT_DIR/ix1-env_old.bin bs=512 skip=558 count=16
- }
- stop_volumes()
- {
- lvchange -a n $MD0VG
- }
- stop_raid()
- {
- mdadm --stop --scan
- }
- destroy_raid()
- {
- mdadm --zero-superblock $1"1"
- }
- # EMC Imager Script
- if [ "$1" == "usb_imaging" ]
- then
- echo "Started USB Imaging..."
- mknod /dev/zero c 1 5
- # if there is no system partition then create it here
- a=`cat /sys/block/sda/sda1/size`
- UUID_1=`mdadm -E --brief $DISK1_PART1 | awk -F "=" '{print $4}'`
- mount_vol
- ret=$?
- if [ "$ret" != "0" ] || [ "$a" == "" ] || [ "UUID_1" == "" ] || [ -f "$reinstallFile" ]
- then
- echo "Going to do a full install"
- rm $reinstallFile
- readenv $disk
- umount /sysroot/boot
- stop_volumes
- stop_raid
- destroy_raid $disk
- create_partitions $disk
- sleep 2
- write_bootrom_directions $disk
- write_hidden_sectors $disk
- start_sys_raid $disk
- create_volumes
- format_sys_partitions
- mount_vol
- fi
- APPS_UPGRADE_IMAGE=/usb_drive/emctools/hmnhd_images/temp/apps
- CONFIG_UPGRADE_IMAGE=/usb_drive/emctools/hmnhd_images/temp/config
- OEM_UPGRADE_IMAGE=/usb_drive/emctools/hmnhd_images/temp/oem
- NoExtractionFile=/usb_drive/emctools/hmnhd_images/noextraction
- copy_image
- umount sysroot/boot
- if [ "hmnhd" == "hmnhd" ]
- then
- kernelFile=/usb_drive/emctools/hmnhd_images/temp/zImage
- initrdFile=/usb_drive/emctools/hmnhd_images/temp/initrd
- # update flash images
- dd if=$kernelFile of="$disk" bs=512 seek=1290
- dd if=$initrdFile of="$disk" bs=512 seek=16674
- fi
- if [ -f $NoExtractionFile ]
- then
- echo "No need to remove the temp folder."
- else
- echo "Remove the temp folder."
- rm -fr /usb_drive/emctools/hmnhd_images/temp/
- fi
- else
- echo "Invalid argument"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement