Last active
July 31, 2024 12:47
-
-
Save AugustoCiuffoletti/e0af693878e8fa9ab5b6e8d761eb9eec to your computer and use it in GitHub Desktop.
Revisions
-
AugustoCiuffoletti revised this gist
Oct 25, 2020 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,8 +26,7 @@ NC='\033[0m' # No Color echo -e "${LGREEN}*** Now running on $HOSTNAME${NC}" echo -e "${LGREEN}*** Fixing /etc/hosts${NC}" if ! grep $VMhostname -q /etc/hosts then sed -i".bak" "/127\.0\.0\.1/ s/$/ ${VMhostname}/" /etc/hosts fi echo -e "${LGREEN}*** Configuring localization for "$HOSTNAME"....${NC}" @@ -45,6 +44,11 @@ apt -y upgrade echo -e "${LGREEN}*** Installing extra packages...${NC}" apt -y install linux-modules-extra-$(uname -r) tasksel echo -e "${LGREEN}*** Installing VirtualBox guest additions...${NC}" sudo apt -y install virtualbox-guest-additions-iso sudo mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /media/ sudo /media/VBoxLinuxAdditions.run echo -e "${LGREEN}*** Bundle package selection (with tasksel)...${NC}" tasksel @@ -60,8 +64,7 @@ echo $imgFile # get the image if [ ! -e $imgFile ] then wget $VMimage fi VBoxManage import $imgFile --vsys 0 --vmname $VMname -
AugustoCiuffoletti revised this gist
Oct 25, 2020 . No changes.There are no files selected for viewing
-
AugustoCiuffoletti revised this gist
Oct 24, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -53,15 +53,15 @@ echo -e "${LGREEN}*** Consider rebooting the VM before using${NC}" EOF # prepare the tools sudo apt-get install cloud-image-utils imgFile=`basename $VMimage` echo $imgFile # get the image if [ ! -e $imgFile ] then wget $VMimage fi VBoxManage import $imgFile --vsys 0 --vmname $VMname -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,12 +25,9 @@ NC='\033[0m' # No Color echo -e "${LGREEN}*** Now running on $HOSTNAME${NC}" echo -e "${LGREEN}*** Fixing /etc/hosts${NC}" if ! grep $VMhostname -q /etc/hosts then sed -i".bak" "/127\.0\.0\.1/ s/$/ ${VMhostname}/" /etc/hosts fi echo -e "${LGREEN}*** Configuring localization for "$HOSTNAME"....${NC}" -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -28,28 +28,30 @@ Next the Virtual Machine is created: download the .ova, create the VM, configure The following step creates the [cloud-init](https://cloudinit.readthedocs.io) configuration files (`user-data` and `meta-data`): they will be used by the cloud-init support inside the VM (remember, it is created from a cloud image) to configure it from the inside. In the two files you find the name of the host, the name of the (unique) user, and its RSA public key for authentication. The files are packaged in a .iso file (a virtual DVD) that is attached to the VM, and threfore available to cloud-init. At this point the script launches the VM, and waits for your prompt to start the successive steps. This is extremely in-elegant: any suggestion is welcome. When the VM is up and running you hit return and the installation proceeds uploading the configuration script prepared in the very first step, and lauching it execution. It perform a fix in the `/etc/hosts` file, asks for the password of the unique user (see the `$VMusername` variable), performs the localization, and updates the software packages, installing a bundle of packages excluded from cloud images and the tasksel tool, which is immediately launched ## How to use the script Preconditions: you have a Linux box with VirtualBox installed and at least an RSA public key available in `$HOME/.ssh` (if not, then it is time to generate it!). Launch VirtualBox, next create a directory and download the script. Check if the variables fit your case, next launch it with $ ./UbuntuMini.sh After less than one minute (30" on my Lenovo Legion Laptop) a Virtual Terminal appears showing the boot sequence on the VM. Stay on the terminal from which you launched the script, and press `return` only when the Virtual Terminal shows the login screen. You will be asked to confirm the connection to the VM (type `yes`) and, after a few seconds, to set the password for the user (twice). After a few minutes (four on my laptop) of unattended operation you are presented with the tasksel dialog. Here you can select (up/down arrows and the `space` key to select) the bundles you want to install. Highlight the `<ok>` using the `TAB` key when finished. The installation will proceed, unattended. When finished, the control returns to the host computer. It is advisable to restart the VM before using it. You can connect with the VM also using `ssh` password-less from a host terminal: $ ssh -p 2222 user@localhost replacing `user` with the username you indicated in the configuration step. I have tried a few desktop installations, that are a valuable test since they need that the display manager and the rest are correctly installed, and they work fine. As a lightweight customizable desktop installation I suggest the Xubuntu minimal desktop, available from `tasksel`. Enjoy :-) -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ The first part of the script creates a `vm-config.sh` file that will be later up Next the Virtual Machine is created: download the .ova, create the VM, configure networking, and prepare the drives. The following step creates the [cloud-init](https://cloudinit.readthedocs.io) configuration files (`user-data` and `meta-data`): they will be used by the cloud-init support inside the VM (remember, it is created from a cloud image) to configure it from the inside. In the two files you find the name of the host, the name of the (unique) user, and its RSA public key for authentication. The files are packaged in a .iso file (a virtual DVD) that is attached to the VM, and threfore available to cloud-init. At this point the script launches the VM, and waits for your prompt to start the successive steps. This is extremely in-elegant: any suggeston is welcome. -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,9 @@ Customization is carried out by editing the bash variables on top of the script. * **`VMname`** the name of your VM (as in the VirtualBox dashboard) * **`VMhostname`** the hostname * **`VMusername`** the name of the initial user * **`VMtimezone`** the timezone (if you do not touch this line it will be the same as your host machine) * **`VMlocale`** the localization (if you do not touch this line it will be the same as your host machine) * **`VMkeyboard`** the console keyboard (if you do not touch this line it will be the same as your host machine) If you do not touch at all you obtain a customizable running VM. -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ The *mini.iso* for the Ubuntu distribution is **legacy** since version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machines for development, teaching, testing, etc. A distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here](http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso), but there is no guarantee that its availability will continue after Focal Fossa. An *askubuntu* post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). So I decided to find a way to do without the mini.iso, and I wrote this script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository](https://cloud-images.ubuntu.com/). You have many options here about the image format to use: I refer to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a `tasksel` dialog to proceed with you customization. Surprise, it is faster than the procedure based on the *mini.iso*. ## Customizing the script -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ The *mini.iso* for the Ubuntu distribution is **legacy** since version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machines for development, teaching, testing, etc. A distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here](http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso), but there is no guarantee that its availability will continue after Focal Fossa. An *askubuntu* post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). So I decided to find a way to do without the mini.iso, and I wrote this script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository](https://cloud-images.ubuntu.com/). You have many options here about the image format to use: I refer to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a `tasksel` dialog to proceed with you costomization. Surprise, it is faster than the procedure based on the *mini.iso*. ## Customizing the script -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Living without the Ubuntu mini.iso (in VirtualBox) The *mini.iso* for the Ubuntu distribution is **legacy** since version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machines for development, teaching, testing, etc. A distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here](http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso), but there is no guarantee that its availability will continue after Focal Fossa. An *askubuntu* post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). So I decided to find a way to do without the mini.iso, and I wrote this script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository](https://cloud-images.ubuntu.com/). You have many options here about the image format to use: I refer to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a tasksel dialog to proceed with you costomization. Surprise, it is faster than the procedure based on the *mini.iso*. -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Living without the Ubuntu mini.iso (in VirtualBox) The *mini.iso* for the Ubuntu distribution is **legacy** since version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machines for development, teaching, testing, etc. A distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here](http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso), but there is no guarantee that its availabolity will continue after Focal Fossa. An *askubuntu* post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). So I decided to find a way to do without the mini.iso, and I wrote this script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository](https://cloud-images.ubuntu.com/). You have many options here about the image format to use: I refer to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a tasksel dialog to proceed with you costomization. Surprise, it is faster than the procedure based on the *mini.iso*. -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 32 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,45 +1,55 @@ # Living without the Ubuntu mini.iso (in VirtualBox) The *mini.iso* for the Ubuntu distributio is **legacy** since version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machines for development, teaching, testing, etc. A distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here](http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso), but there is no guarantee that its availabolity will continue after Focal Fossa. An *askubuntu* post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). So I decided to find a way to do without the mini.iso, and I wrote this script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository](https://cloud-images.ubuntu.com/). You have many options here about the image format to use: I refer to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a tasksel dialog to proceed with you costomization. Surprise, it is faster than the procedure based on the *mini.iso*. ## Customizing the script Customization is carried out by editing the bash variables on top of the script. Namely: * **`VMimage`** the location of the OVA image * **`VMname`** the name of your VM (as in the VirtualBox dashboard) * **`VMhostname`** the hostname * **`VMusername`** the name of the initial user * **`VMtimezone`** the timezone (if you do not touch this line it will be same of your host machine) * **`VMlocale`** the localization (if you do not touch this line it will be same of your host machine) * **`VMkeyboard`** the console keyboard (if you do not touch this line it will be same of your host machine) If you do not touch at all you obtain a customizable running VM. ## How it works Jump to the next section if in hurry. This one is mainly written for those that want to adapt it. The first part of the script creates a `vm-config.sh` file that will be later uploaded to the running VM and, there, executed to configure it. We will describe its function later. Next the Virtual Machine is created: download the .ova, create the VM, configure networking, and prepare the drives. The following step creates the [cloud-init](https://cloudinit.readthedocs.io) configuration files (`user-data` and `meta-data`): they will be used by the cloud-init support inside the VM (remember, it is created from a cloud image) to configure it from the inside. In the two files you find the name of the host, the name of the (unique) user, and its RSA public key for authentication. The files are packaged in a .iso file (a virtual DVD) that is attached to the VM, and threfore available to the cloud-init. At this point the script launches the VM, and waits for your prompt to start the successive steps. This is extremely in-elegant: any suggeston is welcome. When the VM is up and running you hit return and the installation proceeds uploading the configuration script prepared in the very first step, and lauching it execution. It perform a fix in the /etc/hosts file, asks for the password of the unique user (see the $VNusername variable), performs the localization, and updates the software packages, installing a bundle of packages excluded from cloud images and the tasksel tool, which is immediately launched ## How to use the script Preconditions: you have a Linux box with VirtualBox installed and at least an RSA public key available in $HOME/.ssh (if not, then it is time to generate it!). Launch VirtualBox, next create a directory and download the script. Check if the variables fit your case, next launch it with $ ./UbuntuMini.sh After less than one minute (30" on my Lenovo Legion Laptop) a Virtual Terminal appears showing the boot sequence on the VM. Stay on the terminal from which you launched the script, and press `return` only when the Virtual Terminal shows the login screen. You will be asked to confirm the connection to the VM (type `yes`) and, after a few seconds, the password for the user (twice). After a few minutes (four on my laptop) of unattended operation you are presented with the tasksel dialog. Here you can select (up/down arrows and the `space` key to select) the bundles you want to install. Highlight the `<ok>` using the `TAB` key when finished. The installation will proceed, unattended. When finished, the control returns to the host computer. It is advisable to restart the VM before using it. You can connect with the machine using the virtual terminal, typing the username/password credentials, or, more comfortably, using `ssh` from a host terminal: $ ssh -p 2222 user@localhost replacing `user` with the username you indicated in the configuration step. I have tried a few desktop installations, that are a valuable test since they need that the disply manager and the rest are correctly installed, and they work fine. -
AugustoCiuffoletti renamed this gist
Oct 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
AugustoCiuffoletti renamed this gist
Oct 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
AugustoCiuffoletti renamed this gist
Oct 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 113 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ #!/bin/bash VMimage="https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.ova" VMname="test" VMhostname="vb-mini" VMusername="user" VMtimezone=`cat /etc/timezone` VMlocale=`localectl | grep LANG | cut -f2 -d:` VMkeyboard=`localectl | grep "X11 Layout" | cut -f2 -d:` VMdir=$HOME"/VirtualBox VMs" ### DO NOT TOUCH AFTER THIS LINE (unless you know what you are doing) #Prepare vm-config.sh script to be run on the new VM echo "Prepare vm-config.sh script" echo "#!/bin/bash" > vm-config.sh echo "VMhostname=\"$VMhostname\"" >> vm-config.sh echo "VMusername=\"$VMusername\"" >> vm-config.sh echo "VMtimezone=\""`cat /etc/timezone`"\"" >> vm-config.sh echo "VMlocale=\""`localectl | grep LANG | cut -f2 -d:`"\"" >> vm-config.sh echo "VMkeyboard=\""`localectl | grep "X11 Layout" | cut -f2 -d:`"\"" >> vm-config.sh cat >> vm-config.sh <<"EOF" # Define colors LGREEN='\033[1;32m' NC='\033[0m' # No Color echo -e "${LGREEN}*** Now running on $HOSTNAME${NC}" echo -e "${LGREEN}*** Fixing /etc/hosts${NC}" if ! grep $HOSTNAME -q /etc/hosts then f=`mktemp` awk '{if (/^127\.0\.0\.1 /) {$0=$0 $HOSTNAME}; print}' /etc/hosts > $f sudo cp $f /etc/hosts rm $f fi echo -e "${LGREEN}*** Configuring localization for "$HOSTNAME"....${NC}" timedatectl set-timezone $VMtimezone localectl set-locale $VMlocale localectl set-keymap $VMkeyboard echo -e "${LGREEN}*** Set password for $VMusername on "$HOSTNAME"....${NC}" passwd $VMusername echo -e "${LGREEN}*** Updating packages...${NC}" apt update apt -y upgrade echo -e "${LGREEN}*** Installing extra packages...${NC}" apt -y install linux-modules-extra-$(uname -r) tasksel echo -e "${LGREEN}*** Bundle package selection (with tasksel)...${NC}" tasksel echo -e "${LGREEN}*** Consider rebooting the VM before using${NC}" EOF # prepare the tools apt-get install cloud-image-utils imgFile=`basename $VMimage` echo $imgFile # get the image if [ ! -e $imgFile ] then wget $theImage fi VBoxManage import $imgFile --vsys 0 --vmname $VMname VBoxManage modifyvm $VMname --nic1 nat # Set networking as NAT VBoxManage modifyvm $VMname --natpf1 ,tcp,,2222,,22 # Enable port forwarding for ssh VBoxManage storagectl $VMname --name Floppy --remove # Remove floppy driver # Create the configuration DVD cat > meta-data <<EOF instance-id: ubuntu local-hostname: $VMhostname EOF cat > user-data <<EOF #cloud-config users: - name: $VMusername sudo: ['ALL=(ALL) NOPASSWD:ALL'] shell: /bin/bash EOF echo " ssh_authorized_keys: " >> user-data for f in ~/.ssh/*.pub do echo -n " - " >> user-data cat $f >> user-data done # Password initialization not working... why? #echo -n " passwd: " >> user-data #cat >> user-data <<"EOF" #...input from mkpasswd here #EOF cloud-localds ciconf.iso user-data meta-data rm user-data meta-data # Mount the configuration disk VBoxManage storageattach $VMname --storagectl IDE --port 0 --device 0 --type dvddrive --medium ciconf.iso VBoxManage startvm $VMname echo "Type 'return' on *this* terminal when the login prompt appears on the VM terminal..." read ssh-keygen -f "/home/augusto/.ssh/known_hosts" -R "[localhost]:2222" echo "Transfer the vmconfig.sh script" scp -P 2222 vm-config.sh user@localhost:/tmp/ echo "Running the script on the VM" ssh -tt -p 2222 $VMusername@localhost "sudo bash /tmp/vm-config.sh" -
AugustoCiuffoletti revised this gist
Oct 22, 2020 . 1 changed file with 26 additions and 126 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,145 +1,45 @@ # Living without the Ubuntu mini.iso (in VirtualBox) The producton of the "mini.iso" distribution for Ubuntu is legacy from Ubuntu version 20.04LTS (Focal Fossa). This is a bad news for those (like me) that formerly used this distribution to produce lightweight virtual machine for development, teaching, testing, etc. A legacy distribution of the mini.iso for Ubuntu 20.04 is indeed still available [here] (http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/mini.iso). An askubuntu post on the topic (there are several) is [here](https://askubuntu.com/questions/1233746/download-ubuntu-minimal-iso-20-04lts). It is therefore better to find a way to do without the mini.iso now. Here you find a script that takes to the ''tasksel'' step starting from a cloud image in the ubuntu [repository][https://cloud-images.ubuntu.com/]. You have many options here: I refere to the .ova file that you find in focal/current. Using a mix of VBOxMangage commands and the cloud-init tools you obtain a tasksel dialog to proceed with you costomization. ## Customizing the script Customization is carried out by editing the bash variables on top of the script. Namely: * VMimage the location of the OVA image * VMname the name of your VM (as in the VirtualBox dashboard) * VMhostname the hostname * VMusername the name of the initial user * VMtimezone the timezone (if you do not touch this line it will be same of your host machine) * VMlocale the localization (if you do not touch this line it will be same of your host machine) * VMkeyboard the console keyboard (if you do not touch this line it will be same of your host machine) If you do not touch at all you obtain a vanilla result that you can customize ## How it works Jump this section if in rush. The first part of the script creates a file vm-config.sh that will be later uploaded to the running VM and there executed to configure the ubuntu. We will describe its function later on. Next the Virtual Machine is created: download the .ova, create the VM, configure the networking, prepare the drives. The following step prepares the configuration files for cloud-init (user-data and meta-data): they will be used by the cloud-init support inside the Vm (remember, it is created from a cloud image) to configure it from the inside. In the two files you find the name of the host, the name of the (unique) user, and its RSA public key for authentication. The files are packaged in a .iso file (a virtual DVD) that is attached to the VM, and threfore available to the cloud-init. At this point the script launches the VM, and wait for your prompt to start the successive steps. When the VM is up and running you hit return and the installation proceeds uploading the configuration script prepared in the very first step. Next the script is launched. It perform a fix in the /etc/hosts file, asks for the password of the unique user (see the $VNusername variable), performs the localization, and updates the software packages, installing a bundle of packages excluded from cloud images and the tasksel tool, which is immediately launched The first part of the script runs on the host computer where you have VirtualBox already installed. ## How to use the script Preconditions: you have VirtualBox installed and at least an RSA public key available in $HOME/.ssh (if not generate it!). Launch VirtualBox, nect create a directory and download the script. Check if the variables fit your case, next launch it with $ ./script.sh After a while it will ask you -
AugustoCiuffoletti revised this gist
Oct 21, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Living without the mini.iso (in VirtualBox) My problem is the creation of a custom Ubuntu VirtualBox VM starting from a minimal one. The result should consist of a VM running in a local VirtualBox installation (not in the cloud). -
AugustoCiuffoletti revised this gist
Oct 21, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Living wothout the mini.iso (in VirtualBox) My problem is the creation of a custom Ubuntu VirtualBox VM starting from a minimal one. The result should consist of a VM running in a local VirtualBox installation (not in the cloud). -
AugustoCiuffoletti revised this gist
Oct 20, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ # Create a custom Ubuntu 20.04 VirtualBox VM without the mini.iso My problem is the creation of a custom Ubuntu VirtualBox VM starting from a minimal one. The result should consist of a VM running in a local VirtualBox installation (not in the cloud). This task was formerly carried out using the minimal install mini.iso. But this disk image is now legacy, although still unofficially available. I wanted a well-documented, long-term solution, possibly based on official releases. Browsing the Internet I found various suggestions, but not a complete solution. Below is a step-by-step guide that is based on such suggestions. The solution may explain why the "mini.iso" based one is going to be dismissed. In fact starting the cloud image is faster and returns a VM that is probably better configured for the use in a VirtualBox environment. In addition, the process might be completely automated (see [this](https://gist.github.com/atoato88/5840807) or [this](https://gist.github.com/smoser/6066204)), while the legacy one requires a manual installation taking a long time. The solution starts from a cloud image, as suggested in one of the posts on the subject ([How to do a minimal install of 20-04](https://askubuntu.com/questions/1264128/how-to-do-a-minimal-install-of-20-04)). -
AugustoCiuffoletti revised this gist
Oct 20, 2020 . 1 changed file with 145 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1,145 @@ # A solution using cloud images My problem is the creation of a custom Ubuntu VirtualBox VM starting from a minimal one. The result should consist of a VM running in a local VirtualBox installation (not in the cloud). This task was formerly carried out using the minimal install mini.iso. But this disk image is now legacy, although still unofficially available. I wanted a well-documented, long-term solution, possibly based on official releases. Browsing the Internet I found various suggestions, but not a complete solution. Below is a step-by-step guide that is based on such suggestions. The solution may explain why the "mini.iso" based one is going to be dismissed. In fact the new one is faster to execute and returns a VM that is probably better configured for the use in a VirtualBox environment. In addition, the process might be completely automated (see [this](https://gist.github.com/atoato88/5840807) or [this](https://gist.github.com/smoser/6066204)), while the legacy one requires a manual installation taking a long time. The solution starts from a cloud image, as suggested in one of the posts on the subject ([How to do a minimal install of 20-04](https://askubuntu.com/questions/1264128/how-to-do-a-minimal-install-of-20-04)). I divided the process, which is designed for a Linux box, into steps: * install the cloud image * configure the VM * configure the cloud image * define user credentials * prepare for customization I also give some untested suggestions for its use in a Windows environment. ## Install the cloud image Cloud images are available from several sources. This guide applies to those on the official Ubuntu site, which offers various flavors. I have selected the 20.04 in OVA format, which is easy to use in VirtualBox ([link](https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.ova)). Editing the URL you find other formats and the repo. Download the image, and create the VM using File -> Import virtual application in the VirtualBox GUI, without launching it. It may be convenient to change the name in the description (double click on the description line) with a simpler one, like ''minimal-focal''. ## Configure the VM ### Networking In the network configuration of the Virtual Machine, configure the network adapter as "NAT", and (in the "Advanced" box) redirect host port 2222 (or whichever you like) to 22. In this way, your VM will be connected to the Internet and accessible through ssh. ### Storage In the Storage configuration of the VM: * Remove the useless floppy driver * Create a new DVD drive and leave it empty ## Configure the cloud image Create a .iso image containing the files that cloud-init will use when the VM is booted. In a convenient place, create the following two YAML files: * meta-data: instance-id: desktop local-hostname: vb-desktop * user-data: #cloud-config users: - name: user sudo: ['ALL=(ALL) NOPASSWD:ALL'] shell: /bin/bash Here you have the option to configure two details in the VM: the hostname (here the ''vb-desktop'' value for the ''local-hostname'' field in the meta-data file) and the username (here the ''user'' value for the ''name'' field in the user-data file). Check the [manual](https://cloudinit.readthedocs.io/en/latest/topics/format.html) for more details. Next, create the .iso file (e.g. ciconf.iso) with the command $ cloud-localds ciconf.iso user-data meta-data The ''cloud-localds'' command is in the "cloud-image-utils" package, that (in Debian/Ubuntu) you install with $ sudo apt install cloud-image-utils The same functions should be available also for Windows users. In the Storage section of the VirtualBox GUI install the .iso file you just created in the IDE drive you created in the previous step. Launch the VM and wait for the terminal login, then "shutdown ACPI". You cannot log in since you do not have credentials. ## Define user credentials Move to the directory of the VM virtual disk (might be ~/VirtualBox VMs/minimal-focal), and mount the disk image. The qemu package is needed, which is installed with $ sudo apt install qemu To install the disk image proceed as follows: $ sudo modprobe nbd max_part=8 $ sudo qemu-nbd -c /dev/nbd0 ubuntu-focal-20.04-cloudimg.vdi $ sudo mount /dev/nbd0p1 /mnt The ''ubuntu-focal-20.04-cloudimg.vdi'' refers to the image file, replace with your own. In the end, the VM filesystem is available in the /mnt directory. To create the user credential ''chroot'' to the VM filesystem, change the user credentials (the ''passwd'' command will prompt you for a new password), and exit the ''chroot'' environment: $ sudo chroot /mnt $ passwd user $ sync $ exit Replace ''user'' with the username configured in the previous step. There are limited chances to mess-up your system using the chroot command, so be careful with it. If you do not know about it, please check the man page. Only when you have safely left the ''chroot'' environment (double check), copy your public key (I assume you have one), inside the VM filesystem: $ mkdir /mnt/home/user/.ssh $ cat ~/.ssh/id_rsa.pub >> /mnt/home/user/.ssh/authorized_keys The above step is optional but extremely convenient. In case you do not have a public key there are thousands of tutorials for this (''ssh-keygen''). When done, unmount the VM disk image: $ sync $ sudo umount /dev/nbd0p1 $ sudo qemu-nbd -d /dev/nbd0 $ sudo rmmod nbd If you forget to unmount, the VM disk is damaged and you need to restart the whole thing. Double-check before proceeding. ## Prepare for customization Start the machine from the VirtualBox GUI interface and log in using the ''user'' username and the defined password. The VM is accessible also from the command-line in your PC with $ ssh user@localhost -p 2222 (''user'' replaced with your username, 2222 is the port number configured in the first step). Then use the way you like (I suggest ''ssh'') to finish the work. Log in the VM and, using a line editor, fix a missing detail in the ''/etc/hosts file'' in the VM: add at the end of the ''localhost'' line the name of the new machine, in the example ''minimal-focal''. Next give the following commands: $ sudo dpkg-reconfigure keyboard-configuration $ sudo apt update $ sudo apt upgrade $ sudo apt install linux-modules-extra-$(uname -r) tasksel The first command adapts the VM keyboard to the one you use, while the rest updates the configuration, installs a bundle package containing modules that are missing in a cloud image and the tasksel utility that is useful for customization. ## Final check and conclusions Using the ''tasksel'' command you can install various kinds of bundles, e.g. a LAMP server. But you may decide to install your favorite collection of packages, just like with the mini.iso. The process described above is conceptually more difficult than that carried out with the mini.iso, but it is faster, taking around 10' to have the machine ready for customization. In contrast, you need to download a VDI which is larger than the mini.iso. Finally, the cloud technology is here to stay, so I hope that this modality will be available for several Ubuntu releases after the mini.iso is finally abandoned. The final check may consist of installing a desktop distribution, like Xubuntu, using tasksel. The test is significant to check if a display manager can operate correctly. To run the check, clone the VM and call ''tasksel'' from the VM terminal. Next select (with ''space'') the "Minimal Xubuntu desktop". Wait until the installation completes and reboot. Windows users should be able to use the same strategy, but the steps that require mounting the VM filesystem and the chroot command are carried out using specific fields in the user-data file. -
AugustoCiuffoletti created this gist
Oct 20, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ # This is my secret gist