Skip to content

Instantly share code, notes, and snippets.

@lucafavatella
Forked from abythell/ubuntu-domU.sh
Last active August 29, 2015 14:12
Show Gist options
  • Save lucafavatella/61a9c08cc2ee5a2e81f9 to your computer and use it in GitHub Desktop.
Save lucafavatella/61a9c08cc2ee5a2e81f9 to your computer and use it in GitHub Desktop.

Revisions

  1. Ziptrek Administrator revised this gist Apr 9, 2013. 1 changed file with 16 additions and 5 deletions.
    21 changes: 16 additions & 5 deletions ubuntu-domU.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,12 @@ VG=/dev/domU # existing volume group in which to create a logical volume
    LV=$NAME # name of the new logical volume to create
    LV_SIZE=5G # size of the new logical volume
    MEM_SIZE=512 # memory to allocate to this VM
    RELEASE=precise # "precise" (12.04LTS) or "quantal" (12.10)

    # Ubuntu distro settings. Change mirror or version as required.
    IMAGEDIR=/var/lib/xen/images/ubuntu-netboot
    MIRROR=http://ubuntu.arcticnetwork.ca/
    DISTRO=/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen
    DISTRO=/ubuntu/dists/$RELEASE/main/installer-amd64/current/images/netboot/xen

    #Create Disk
    lvcreate -L $LV_SIZE -n $LV $VG
    @@ -26,12 +27,16 @@ if [ ! -d "$IMAGEDIR" ]; then
    wget $MIRROR/$DISTRO/vmlinuz
    fi

    #Create Xen Config
    #Create pre-install Xen Config
    CONFIG=/etc/xen/$NAME.cfg
    if [ -f "$CONFIG" ];
    then
    mv $CONFIG $CONFIG.old
    fi

    # on_reboot="destroy" is used in the initial config because we need to modify
    # the Xen config file before restarting when the install is complete.

    cat >> $CONFIG << EOL
    name="$NAME"
    memory=$MEM_SIZE
    @@ -40,13 +45,19 @@ vif=['bridge=xenbr0']
    vfb=['vnc=1']
    kernel="$IMAGEDIR/vmlinuz"
    ramdisk="$IMAGEDIR/initrd.gz"
    on_reboot="destroy"
    extra="console=hvc0"
    EOL

    #Launch the VM and connect to console to complete Ubuntu installation
    #Launch the VM and connect to console to complete Ubuntu installation.
    xm create /etc/xen/$NAME.cfg -c

    #Modify Xen Config to use the kernel configured during the installation
    #Modify the post-install Xen Config
    sed -i '/kernel/d' $CONFIG
    sed -i '/ramdisk/d' $CONFIG
    sed -i '/extra/d' $CONFIG
    sed -i '/on_reboot/d' $CONFIG
    echo "bootloader=\"pygrub\"" >> $CONFIG

    #Launch the new VM
    xm create /etc/xen/$NAME.cfg -c

  2. @abythell abythell revised this gist Mar 28, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ubuntu-domU.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    #!/bin/bash
    # Script to download, configure, and install Ubuntu as a Xen domU
    # Uses existing LVM Volume Group. Must be run as root/sudo.
    # Based on instructions at https://help.ubuntu.com/community/Xen

    # User Configurable Settings
    NAME=ubuntu # name of Domain to create
  3. @abythell abythell revised this gist Mar 28, 2013. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions ubuntu-domU.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Uses existing LVM Volume Group. Must be run as root/sudo.

    # User Configurable Settings
    NAME=amanda # name of Domain to create
    NAME=ubuntu # name of Domain to create
    VG=/dev/domU # existing volume group in which to create a logical volume
    LV=$NAME # name of the new logical volume to create
    LV_SIZE=5G # size of the new logical volume
    @@ -41,9 +41,8 @@ kernel="$IMAGEDIR/vmlinuz"
    ramdisk="$IMAGEDIR/initrd.gz"
    EOL

    #Launch the VM and connect to console
    #Launch the VM and connect to console to complete Ubuntu installation
    xm create /etc/xen/$NAME.cfg -c
    exit 0

    #Modify Xen Config to use the kernel configured during the installation
    sed -i '/kernel/d' $CONFIG
  4. @abythell abythell created this gist Mar 28, 2013.
    52 changes: 52 additions & 0 deletions ubuntu-domU.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/bin/bash
    # Script to download, configure, and install Ubuntu as a Xen domU
    # Uses existing LVM Volume Group. Must be run as root/sudo.

    # User Configurable Settings
    NAME=amanda # name of Domain to create
    VG=/dev/domU # existing volume group in which to create a logical volume
    LV=$NAME # name of the new logical volume to create
    LV_SIZE=5G # size of the new logical volume
    MEM_SIZE=512 # memory to allocate to this VM

    # Ubuntu distro settings. Change mirror or version as required.
    IMAGEDIR=/var/lib/xen/images/ubuntu-netboot
    MIRROR=http://ubuntu.arcticnetwork.ca/
    DISTRO=/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen

    #Create Disk
    lvcreate -L $LV_SIZE -n $LV $VG

    #Get Ubuntu Netboot kernel and ramdisk
    if [ ! -d "$IMAGEDIR" ]; then
    mkdir -p $IMAGEDIR
    cd $IMAGEDIR
    wget $MIRROR/$DISTRO/initrd.gz
    wget $MIRROR/$DISTRO/vmlinuz
    fi

    #Create Xen Config
    CONFIG=/etc/xen/$NAME.cfg
    if [ -f "$CONFIG" ];
    then
    mv $CONFIG $CONFIG.old
    fi
    cat >> $CONFIG << EOL
    name="$NAME"
    memory=$MEM_SIZE
    disk=['phy:$VG/$LV,xvda,w']
    vif=['bridge=xenbr0']
    vfb=['vnc=1']
    kernel="$IMAGEDIR/vmlinuz"
    ramdisk="$IMAGEDIR/initrd.gz"
    EOL

    #Launch the VM and connect to console
    xm create /etc/xen/$NAME.cfg -c
    exit 0

    #Modify Xen Config to use the kernel configured during the installation
    sed -i '/kernel/d' $CONFIG
    sed -i '/ramdisk/d' $CONFIG
    sed -i '/extra/d' $CONFIG
    echo "bootloader=\"pygrub\"" >> $CONFIG