init-install.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/sh -e
  2. #
  3. # Copyright (C) 2008 Intel
  4. #
  5. # install.sh [device_name] [rootfs_name] [video_mode] [vga_mode]
  6. #
  7. # We need 20 Mb for the boot partition
  8. boot_size=20
  9. # 5% for the swap
  10. swap_ratio=5
  11. found="no"
  12. echo "Searching for a hard drive..."
  13. for device in 'hda' 'hdb' 'sda' 'sdb'
  14. do
  15. if [ -e /sys/block/${device}/removable ]; then
  16. if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then
  17. found="yes"
  18. while true; do
  19. echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]"
  20. read answer
  21. if [ "$answer" = "y" ] ; then
  22. break
  23. fi
  24. if [ "$answer" = "n" ] ; then
  25. found=no
  26. break
  27. fi
  28. echo "Please answer by y or n"
  29. done
  30. fi
  31. fi
  32. if [ "$found" = "yes" ]; then
  33. break;
  34. fi
  35. done
  36. if [ "$found" = "no" ]; then
  37. exit 1
  38. fi
  39. echo "Installing image on /dev/${device}"
  40. #
  41. # The udev automounter can cause pain here, kill it
  42. #
  43. rm -f /etc/udev/scripts/mount*
  44. #
  45. # Unmount anything the automounter had mounted
  46. #
  47. umount /dev/${device} 2> /dev/null || /bin/true
  48. umount /dev/${device}1 2> /dev/null || /bin/true
  49. umount /dev/${device}2 2> /dev/null || /bin/true
  50. umount /dev/${device}3 2> /dev/null || /bin/true
  51. umount /dev/${device}4 2> /dev/null || /bin/true
  52. umount /dev/${device}5 2> /dev/null || /bin/true
  53. umount /dev/${device}6 2> /dev/null || /bin/true
  54. if [ ! -b /dev/sda ] ; then
  55. mknod /dev/sda b 8 0
  56. fi
  57. if [ ! -b /dev/sdb ] ; then
  58. mknod /dev/sdb b 8 16
  59. fi
  60. if [ ! -b /dev/loop0 ] ; then
  61. mknod /dev/loop0 b 7 0
  62. fi
  63. mkdir -p /tmp
  64. cat /proc/mounts > /etc/mtab
  65. disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
  66. swap_size=$((disk_size*5/100))
  67. rootfs_size=$((disk_size-boot_size-swap_size))
  68. rootfs_start=$((boot_size + 1))
  69. rootfs_end=$((rootfs_start+rootfs_size))
  70. swap_start=$((rootfs_end+1))
  71. bootfs=/dev/${device}1
  72. rootfs=/dev/${device}2
  73. swap=/dev/${device}3
  74. echo "*****************"
  75. echo "Boot partition size: $boot_size MB (/dev/${device}1)"
  76. echo "Rootfs partition size: $rootfs_size MB (/dev/${device}2)"
  77. echo "Swap partition size: $swap_size MB (/dev/${device}3)"
  78. echo "*****************"
  79. echo "Deleting partition table on /dev/${device} ..."
  80. dd if=/dev/zero of=/dev/${device} bs=512 count=2
  81. echo "Creating new partition table on /dev/${device} ..."
  82. parted /dev/${device} mklabel msdos
  83. echo "Creating boot partition on /dev/${device}1"
  84. parted /dev/${device} mkpartfs primary ext2 0 $boot_size
  85. echo "Creating rootfs partition on /dev/${device}2"
  86. parted /dev/${device} mkpartfs primary ext2 $rootfs_start $rootfs_end
  87. echo "Creating swap partition on /dev/${device}3"
  88. parted /dev/${device} mkpartfs primary linux-swap $swap_start $disk_size
  89. parted /dev/${device} print
  90. echo "Formatting /dev/${device}1 to ext2..."
  91. mkfs.ext3 $bootfs
  92. echo "Formatting /dev/${device}2 to ext3..."
  93. mkfs.ext3 $rootfs
  94. echo "Formatting swap partition...(/dev/${device}3)"
  95. mkswap $swap
  96. mkdir /ssd
  97. mkdir /rootmnt
  98. mount $rootfs /ssd
  99. mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt
  100. echo "Copying rootfs files..."
  101. cp -a /rootmnt/* /ssd
  102. if [ -d /ssd/etc/ ] ; then
  103. echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab
  104. # We dont want udev to mount our root device while we're booting...
  105. if [ -d /ssd/etc/udev/ ] ; then
  106. echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist
  107. fi
  108. fi
  109. umount /ssd
  110. umount /rootmnt
  111. echo "Preparing boot partition..."
  112. mount $bootfs /ssd
  113. grub-install --root-directory=/ssd /dev/${device}
  114. echo "(hd0) /dev/${device}" > /ssd/boot/grub/device.map
  115. echo "default 0" > /ssd/boot/grub/menu.lst
  116. echo "timeout 30" >> /ssd/boot/grub/menu.lst
  117. echo "title Live Boot/Install-Image" >> /ssd/boot/grub/menu.lst
  118. echo "root (hd0,0)" >> /ssd/boot/grub/menu.lst
  119. echo "kernel /boot/vmlinuz root=$rootfs rw $3 $4 quiet" >> /ssd/boot/grub/menu.lst
  120. cp /media/$1/vmlinuz /ssd/boot/
  121. umount /ssd
  122. sync
  123. echo "Remove your installation media, and press ENTER"
  124. read enter
  125. echo "Rebooting..."
  126. reboot -f