Edit: you may want to check out my updated post in this topic.
In one of my projects I needed to quickly install and/or reproduce virtual Ubuntu servers using QEMU+KVM. It’s nothing difficult but I decided to record the required steps here so I don’t have to remember it all the time. The overall process is the following:
- download an installation image, mount it and make a writable copy
- modify/replace isolinux.cfg and preseed files
- recreate ISO and test by booting from it
Get an Ubuntu installation image
I’m using the latest 64-bit LTS server ISO which is marked 12.04.2 at the moment of writing this. I also recommend downloading it via torrent then keep it seeding.
Mount ISO and copy files
Mount the downloaded image then copy the contents to a directory where you can edit the files since the mounted filesystem will be read-only.
mount -o loop /path/to/image /mount/here rsync -av /mount/here/ /copy/here chmod -R u+w /copy/here/isolinux chmod -R u+w /copy/here/preseed
Modify files
Adjust isolinux.cfg and preseed files to your needs. The options needed before the installer mounts the installation media should go into isolinux.cfg as part of the append statement. Every other preconfiguration for the installer could be set in the preseed file (list of preseed options). All path info in the below examples should be seen as if the root directory was the ISO image’s root.
isolinux.cfg
As I intend to use the new image for unattended installation I replaced the original file with the following:
prompt 0 default install label install menu label ^Install Ubuntu kernel /install/vmlinuz append file=/cdrom/preseed/ubuntu-server-minimalvm.seed locale=en_GB.UTF-8 console-setup/ask_detect=false keyboard-configuration/layoutcode=hu vga=788 initrd=/install/initrd.gz quiet --
- prompt 0: this can spare time on boot by not waiting for any user input
- append options:
- file: which preseed file should be used during the installation
- language, country and locale can be set separately but usually it’s enough to set the locale (
language=en country=GB locale=en_GB.UTF-8
is equivalent tolocale=en_GB.UTF-8
howeverlanguage=en country=HU locale=en_GB.UTF-8
combination won’t work for some reason..) - console-setup/ask_detect=false: don’t try to autodetect keyboard settings
- keyboard-configuration/layoutcode=hu: set the keyboard layout to Hungarian
- everything else (vga, initrd, quiet) is kept from the default file
The installer mounts the installation media at this point so it could load the specified preseed file and use that from here on.
Preseed file
In order to don’t stop to wait for any user input I needed to specify the following minimal set of preconfiguration options: hostname, initial user’s full name, username and MD5 hashed password, home directory encryption, timezone, partition setup, mirror config, update policy, additional packages to be insalled, GRUB installation, and how to finish the installation.
I just prepended these lines to the existing ubuntu-server-minimalvm.seed file:
# Set hostname d-i netcfg/get_hostname string ubuntu # Create new user d-i passwd/user-fullname string Ubuntu User d-i passwd/username string ubuntu d-i passwd/user-password-crypted password $1$1AniiGAw$ZsUcBK840ZrkmoVIvTneP1 # Don't encrypt the home directory d-i user-setup/encrypt-home boolean false # Set timezone d-i time/zone string Europe/Budapest # Partitioning d-i partman-auto/disk string /dev/vda d-i partman-auto/method string lvm d-i partman-lvm/device_remove_lvm boolean true d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm_nooverwrite boolean true d-i partman-auto-lvm/guided_size string max d-i partman-partitioning/confirm_write_new_label boolean true d-i partman/choose_partition select finish d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true # Mirror d-i mirror/http/proxy string # Unattended security upgrades d-i pkgsel/update-policy select unattended-upgrades # Install OpenSSH server tasksel tasksel/first multiselect openssh-server # Install acpid d-i pkgsel/include string acpid # Install GRUB2 d-i grub-installer/only_debian boolean true # Avoid that last message about the install being complete d-i finish-install/reboot_in_progress note d-i debian-installer/exit/poweroff boolean true
Edit: install acpid by default as it is needed for proper VM shutdown. The initial username/password is ubuntu/ubuntu in this example.
recreate ISO
mkisofs -r -V "auto-ubuntu-minimalvm" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /path/to/new/iso /copy/here
boot
- createqemu image
qemu-img create -f qcow2 ubuntu-server-12.04.2-amd64-minimalvm.img 2G
- boot from modified iso
qemu-kvm -cpu host -drive file=ubuntu-server-12.04.2-amd64-minimalvm.img,if=virtio -net nic -net user,hostname=ubuntu -m 256M -boot d -cdrom /path/to/new/iso
Pingback: Simple unattended Ubuntu install in a VM | Agile sysadmin
Hello,
I am very delighted with the way the unattended installation worked completely for me but it seems that newer iso images of ubuntu for example 13.10 saucy salamander version doesnt workout with that method is there a way to let it work?
Hi Tanios, I’m glad you found it useful!:) Nowadays I only use a simpler method described here. Maybe you would like to check that out until I figure out the ISO-way for more recent versions and update the post.
I was able to successfully create a QEMU image from latest ubuntu-13.10-server-amd64.iso by copy-pasting the steps in the post. If you still have a problem, feel free to post some more details (though if it’s long, you may want to use pastebin, gist or a similar service and just share the URL).
Hello again,
I am currently working on ubuntu 12.04.4 (amd64) fully automated installation but I am having a problem with my preseed file when trying to download additional packages. You may want to take a look at my preseed file and thanks for your help.
http://pastebin.com/tKfkmBYk
Hi,
I tried to modify ubuntu-12.04.4-server-amd64.iso using your preseed file. For me the installation stops during ‘Configuring tasksel’ on the ‘How do you want to manage upgrades on this system?’. It is because the answer for this question (pkgsel/update-policy) is missing from the preseed file. There’s a link in the post which points to the list of the preseed options for 12.04 (I just fixed the link from lts to 12.04). It’s usually worth checking that page first when the installer asks something new ;)
It also helps if you can find or choose an ‘almost good’ preseed and then just add your custom d-i options to it. The install CD customization article, or searching for debian-installer docs in general could also be helpful sometimes.
I hope this helps, happy installing! :)
Hello,
I modified my preseed file and it worked quite frankly thanks for the help. I am trying now to do the installation using NFS by creating two virtual machines on oracle virtual box between client and server. I just wanted to know if you have tried or post something related to this kind of installation because I searched for it I didn’t find any useful links
I’m glad it worked in the end! :) About NFS+VirtualBox: I’m afraid it isn’t totally clear what exactly you’re trying to achieve, but for quick provisioning of VirtualBox machines you might want to take a look at Vagrant and/or Rex/Boxes.
I am trying to apply the automated installation on the network by creating two virtual machines server and client and try to run the automated installation of Ubuntu so that the client gets and boots the iso image from the server using NFS by this way the installation will be centralized and proceed on all clients without the use of a CD. I think a modification in the preseed file is required. Do you have any suggestions or something that you have posted that may be useful ?
Thanks again.
I think you need to check out PXE, TFTP and DHCP topics in general in order to do that. You might also be interested in the cobbler and FAI (Fully Automatic Installation) projects. I don’t have direct experience with them, but Canonical/Ubuntu also has MAAS/Juju for bare-metal provisioning and orchestration. There’s also Rex.IO if you like to get your hands dirty and play with pre-alpha stuff :)
Ok gd I am gonna check them out I really appreciate the help :)