How to set up a minimalistic Lubuntu in VirtualBox

Set up the virtual machine

  1. Get the latest amd64 Lubuntu installer ISO.
  2. Get the latest amd64 Ubuntu mini-installer ISO.
  3. Create a Linux, Ubuntu (64 bit) virtual machine with no drive.
  4. In the virtual machine’s settings, create and attach a new 20 GB hard drive (main drive) and a new 4 GB hard drive (swap), then set up the hardware as you wish.

Prepare the drives

  1. Attach the Lubuntu installer ISO.
  2. Boot the virtual machine.
  3. Select Try Lubuntu without installing.
  4. Go to the Applications menu (you may have to scroll down), System Tools, GParted.
  5. Device menu, Create Partition Table..., Apply.
  6. Right click on unallocated, New, File system is ext4 (or whatever the latest standard is), Add.
  7. Edit menu, Apply All Operations, Apply.
  8. Right click on /dev/sda1, Manage Flags, check boot, Close.
  9. Switch from /dev/sda to /dev/sdb.
  10. Device menu, Create Partition Table..., Apply.
  11. Right click on unallocated, New, File system is linux-swap, Label is swap, Add.
  12. Edit menu, Apply All Operations, Apply.
  13. Close GParted.
  14. Go to the Applications menu, Accessories, LXTerminal, and run the following commands:
    sudo -i
    apt-get install zerofree
    zerofree -v /dev/sda1
    poweroff
    
  15. Wait 15 seconds and close the running virtual machine (choose Power off the machine).
  16. Open the virtual machine’s settings, detach the 4 GB drive, and click OK.
  17. File, Virtual Media Manager..., right click on the 4 GB drive, Modify..., Immutable, OK, Close.
  18. Open the virtual machine’s settings, reattach the 4 GB drive, and click OK.
  19. Open a terminal, switch to the directory with the virtual drives, and run the following on both drives:
    VBoxManage modifyhd --compact "[name of virtual drive].vdi"
    
  20. You now have two formatted drives. The one used for swap is immutable, which means that the drive will be restored to its current pristine state every time the virtual machine is rebooted.

Install Ubuntu base

  1. Attach the Ubuntu mini-installer ISO and boot the virtual machine.
  2. Choose Command-line install.
  3. Answer the prompts.
  4. When the Partition disks screen comes up:
    1. Choose the Manual partitioning method.
    2. For the 21.5 GB partition, use the following settings and then choose Done setting up the partition:
      Use as: Ext4 journaling file system
      Format the partition: no, keep existing data
      Mount point: /
      Mount options: defaults
      Bootable flag: on
      
    3. Go to Finish partitioning and write changes to disk and press enter.
    4. Choose No to not return to the partitioner.
    5. Choose Yes to write the changes.
  5. Make sure to install GRUB bootloader to the master boot record when it asks later on.
  6. When the installer returns to the original menu (with Command-line install), turn off the virtual machine.
  7. Detach the ISO.
  8. Start the virtual machine.
  9. Log in using the username and password you chose when installing Ubuntu base.
  10. Run the following commands:
    sudo rm -rf /tmp/*; sudo mount -t tmpfs tmpfs /tmp -o size=2G,mode=1777
    sudo -i
    nano /etc/fstab
    
  11. Add the following line to the bottom of the file, double-check that you entered it correctly, then press Ctrl-O, Enter, Ctrl-X:
    tmpfs /tmp tmpfs size=2G,mode=1777 0 0
    
  12. Run the following commands:
    apt-get update
    apt-get install -y virtualbox-guest-utils
    poweroff
    
  13. You now have a minimal install of Ubuntu.

Install Lubuntu

  1. Start the virtual machine (with no attached CDs).
  2. Log in using the username and password you chose when installing Ubuntu base.
  3. Run the following commands:
    sudo -i
    echo -e \\n# VirtualBox has no SMBus\\nblacklist i2c_piix4>> /etc/modprobe.d/blacklist.conf
    apt-get purge -y fuse geoip-database krb5-locales os-prober ppp
    apt-get install -y software-properties-common
    add-apt-repository -y ppa:lubuntu-dev/non-official-apps
    apt-get update
    apt-get install -y --auto-remove --no-install-recommends lubuntu-core
    echo -e \#\!/bin/sh\\n\\nrm -f /tmp/.menu-cached-:0-\${USER}\\n/usr/bin/lxpanel \${1+\"\$@\"}> /usr/local/bin/lxpanel
    chmod a+x /usr/local/bin/lxpanel
    sed -i '/xscreensaver/d' /etc/xdg/lxsession/Lubuntu/autostart
    sed -i '/xfce4-power-manager/d' /etc/xdg/lxsession/Lubuntu/autostart
    apt-get install -y gksu policykit-1-gnome lxtask lxterminal menulibre
    echo Hidden=true>> /usr/share/applications/debian-xterm.desktop
    echo Hidden=true>> /usr/share/applications/debian-uxterm.desktop
    
  4. If your virtual machine won’t have much RAM assigned to it:
    apt-get install -y zram-config
    
  5. If you’d like a lightweight image viewer:
    apt-get install -y viewnior
    
  6. If you’d like a lightweight web browser:
    apt-get install -y xombrero
    
  7. If you’d like very lightweight graphical effects like shadows under windows and see-through titlebars:
    apt-get install -y compton
    echo @compton -bcCGfe 0.8 -I 1 -O 0.06 --sw-opti>> /etc/xdg/lxsession/Lubuntu/autostart
    
  8. If you’d like Oracle’s version of Java (change java7 to another version if you’d like):
    add-apt-repository -y ppa:webupd8team/java
    apt-get update
    apt-get install -y oracle-java7-installer
    find /var/cache/ -name jdk-*.tar.gz -delete
    
  9. If you’d like sudo to work without a password:
    sed -i 's/^%sudo\tALL=(ALL:ALL) ALL$/%sudo\tALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
    
  10. If you’d like the user to have a blank password (replace username with the actual username):
    sed -i 's/^\(username:\)[^:]*/\1U6aMy0wojraho/' /etc/shadow
    
  11. If you’d like to disable guest logins:
    /usr/lib/lightdm/lightdm-set-defaults -l false
    
  12. If you’d like the system to automatically log in as this user (replace username with the actual username):
    /usr/lib/lightdm/lightdm-set-defaults -a username
    
  13. Use apt-get to install any other software you’d like.
  14. Wait for the virtual machine to restart with Lubuntu running.
  15. Choose Lubuntu as the session type.
  16. Log in as the user you created.
  17. Set the system up as you wish.
  18. If you installed Oracle’s version of Java, you may wish to turn off the browser plugin (this can be done for all browsers in the Java control panel).
  19. Go to the Applications menu, Accessories, LXTerminal, and run the following commands:
    sudo -i
    apt-get update
    apt-get -y dist-upgrade
    apt-get autoremove --purge
    apt-get clean
    updatedb
    poweroff
    
  20. You now have a Lubuntu system set up as you wish.

Prepare a backup/distribution archive

  1. File, Virtual Media Manager..., right click on the 20 GB drive, Copy..., Next >, VDI (VirtualBox Disk Image), Next >, Dynamically allocated, Next >, Copy, Close.
  2. Attach the copy you just made.
  3. Attach the Lubuntu installer ISO.
  4. Boot the virtual machine.
  5. Select Try Lubuntu without installing.
  6. Go to the Applications menu (you may have to scroll down), Accessories, LXTerminal, and run the following commands:
    sudo -i
    mkdir /mnt/old
    mount -o rw /dev/sdc1 /mnt/old
    cd /mnt/old
    rm -rf tmp/* tmp/.* var/log/* var/log/.*
    for i in .aptitude .bash_history .mysql_history .dbus .gconf '.xsession-errors*'; do find -name "$i" -exec rm -rf {} +; done
    find -print0 | sort -z | tar vvcf contents.tar --no-recursion --null -T -
    mkfs.ext4 -U `blkid -o value -s UUID /dev/sda1` /dev/sda1
    mkdir /mnt/new
    mount -o rw /dev/sda1 /mnt/new
    cd /mnt/new
    tar vvxf /mnt/old/contents.tar
    cd /
    umount /dev/sda1
    apt-get install zerofree
    zerofree -v /dev/sda1
    poweroff
    
  7. Wait 15 seconds and close the running virtual machine (choose Power off the machine).
  8. File, Virtual Media Manager..., do the following:
    1. Right click on the copy of the 20 GB drive, Release, Release, right click on the copy of the 20 GB drive, Remove, Remove, Delete.
    2. Click the triangle next to the 4 GB drive to expand it, right click on the strangely-named drive that shows up below it, Release, Release, right click on the strangely-named drive, Remove, Remove, Delete.
    3. Switch to Optical disks tab, and do the following with each optical disk: right click on the disk, Remove, Remove.
    4. Click Close.
  9. Reattach the 4 GB drive.
  10. Open a terminal, switch to the directory with the virtual drives, and run the following (filling in the name of the 20 GB drive and virtual machine):
    VBoxManage modifyhd --compact "[name of 20 GB virtual drive].vdi"
    rm -rf Logs/*
    rm -f *.vbox-prev
    cd ..
    find "[name of virtual machine]" -print0 | sort -z | tar vvcf machine.tar --owner=0 --group=0 --no-recursion --null -T -
    xz -vvz --lzma2=dict=255MiB,lc=3,lp=1,pb=2,mode=normal,nice=273,mf=bt4,depth=2000 --check=sha256 machine.tar
    
  11. Now you have a VirtualBox image (machine.tar.xz) with customized minimalistic Lubuntu that you can distribute to others or use to get back to a pristine state.
Advertisements
This entry was posted in Ubuntu. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s