Last active
December 14, 2015 03:19
-
-
Save mizzy/5020611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
image=/tmp/sl63.img | |
root_dir=/tmp/root | |
truncate -s 5368709120 $image | |
parted --script -- $image "mklabel msdos" | |
parted --script -- $image "mkpart primary ext2 63s 4095" | |
parted --script -- $image "mkpart primary linux-swap(v1) 4096 5119" | |
kpartx -va $image | |
mkfs.ext4 -F -E lazy_itable_init=1 -L root /dev/mapper/loop0p1 | |
mkswap -L swap -f /dev/mapper/loop0p2 | |
mount /dev/mapper/loop0p1 $root_dir | |
cat <<EOF > /tmp/sl.repo | |
[sl] | |
name=Scientific Linux 6 - x86_64 | |
baseurl=http://ftp.scientificlinux.org/linux/scientific/6/x86_64/os/ | |
http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/os/ | |
http://ftp2.scientificlinux.org/linux/scientific/6/x86_64/os/ | |
ftp://ftp.scientificlinux.org/linux/scientific/6/x86_64/os/ | |
enabled=1 | |
gpgcheck=1 | |
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-sl file:///etc/pki/rpm-gpg/RPM-GPG-KEY-dawson | |
EOF | |
yum -c /tmp/sl.repo --disablerepo='*' --enablerepo='sl' --installroot=$root_dir \ | |
-y groupinstall core | |
mkdir -m 0755 $root_dir/dev/pts | |
mkdir -m 1777 $root_dir/dev/shm | |
rm $root_dir/dev/null | |
mknod -m 666 $root_dir/dev/null c 1 3 | |
mknod -m 666 $root_dir/dev/zero c 1 5 | |
mknod -m 620 $root_dir/dev/tty1 c 4 1 | |
mknod -m 620 $root_dir/dev/tty2 c 4 2 | |
mknod -m 620 $root_dir/dev/tty3 c 4 3 | |
mknod -m 620 $root_dir/dev/tty4 c 4 4 | |
mknod -m 600 $root_dir/dev/console c 5 1 | |
mknod -m 666 $root_dir/dev/full c 1 7 | |
mknod -m 666 $root_dir/dev/randam c 1 8 | |
mknod -m 666 $root_dir/dev/urandam c 1 9 | |
mknod -m 666 $root_dir/dev/ptmx c 5 2 | |
chroot $root_dir bash -e -c "echo root:root | chpasswd" | |
cat <<EOF > $root_dir/etc/sysconfig/network | |
NETWORKING=yes | |
HOSTNAME=drpepper.mizzy.org | |
EOF | |
cat <<EOF > $root_dir/etc/sysconfig/network-scripts/ifcfg-eth0 | |
DEVICE=eth0 | |
TYPE=Ethernet | |
BOOTPROTO=dhcp | |
ONBOOT=yes | |
EOF | |
root_uuid=`blkid -sUUID -ovalue /dev/mapper/loop0p1` | |
swap_uuid=`blkid -sUUID -ovalue /dev/mapper/loop0p2` | |
cat <<EOF > $root_dir/etc/fstab | |
UUID=${root_uuid} / ext4 defaults 1 1 | |
UUID=${swap_uuid} swap swap defaults 0 0 | |
tmpfs /dev/shm tmpfs defaults 0 0 | |
devpts /dev/pts devpts gid=5,mode=620 0 0 | |
sysfs /sys sysfs defaults 0 0 | |
proc /proc proc defaults 0 0 | |
EOF | |
sed -i "s/^\(SELINUX=\).*/\1disabled/" $root_dir/etc/sysconfig/selinux | |
yum -c /tmp/sl.repo --disablerepo='*' --enablerepo='sl' --installroot=$root_dir \ | |
-y install kernel | |
yum -c /tmp/sl.repo --disablerepo='*' --enablerepo='sl' --installroot=$root_dir \ | |
-y install grub | |
cat <<EOF > /tmp/device.map | |
(hd0) $image | |
EOF | |
cp $root_dir/usr/share/grub/x86_64-redhat/stage1 $root_dir/boot/grub | |
cp $root_dir/usr/share/grub/x86_64-redhat/stage2 $root_dir/boot/grub | |
cat <<EOF | grub --batch --device-map=/tmp/device.map | |
root (hd0,0) | |
setup (hd0) | |
quit | |
EOF | |
cat <<EOF > $root_dir/boot/grub/grub.conf | |
default=0 | |
timeout=5 | |
splashimage=(hd0,0)/boot/grub/splash.xpm.gz | |
hiddenmenu | |
title sl-6.3_x86_64 (2.6.32-279.el6.x86_64) | |
root (hd0,0) | |
kernel /boot/vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=${root_uuid} rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM selinux=0 | |
initrd /boot/initramfs-2.6.32-279.el6.x86_64.img | |
EOF | |
cd $root_dir/boot/grub | |
ln -fs grub.conf menu.lst | |
cd - >/dev/null | |
chroot $root_dir bash -e -c "ln -fs /boot/grub/grub.conf /etc/grub.conf" | |
umount $root_dir | |
kpartx -dv $image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment