Showing posts with label boot. Show all posts
Showing posts with label boot. Show all posts

Thursday, February 25, 2010

Install Ubuntu from Alternate CD image; booting from USB flash drive

I recently tried a couple of ubuntu versions, installing them on a partition to play a few hours. In the process I re-discovered unetbootin, a wonderful tool for this: I burned the CD ISO images in a USB flash drive, instead of burning CDs (even if you use rewritable, it is slower than a USB key). UNetbootin let's you make a bootable pendrive from any ISO image; you can even download your favorite distro CD from there.

The main comment of this post is, however, not just the unetbootin process, but two tips that solved issues with these images.

First, the simpler one: You have to mark the partition in the USB drive as bootable, or you will not be able to boot... To do this, run fdisk /dev/sdb (or whichever your drive's device is), and add its boot flag.

The second on is subtler. With the Ubuntu 9.10 Desktop CD everything worked perfectly; I was able to boot. But later I tried the Alternate CD, which after booting it could not find the contents of the "CD" it was installing from. Somehow it missed the point it had boot from USB; so there would not be any contents on CD-ROM to read (in fact, that machine does not even have a CD drive). What I had to do was to add a flag to the kernel boot options: When UNetbootin starts, before pressing Enter on the "Default" option, press Tab to edit it. Edit the kernel line, to make it look like this one:
/ubnkern initrd=/ubninit vga=normal cdrom-detect/try-usb=true -- quiet

(Everything should be in a single line). Your line might not be identical; but the important part is to add "cdrom-detect/try-usb=true" before the "--". With this option the installer found the contents and was able to continue the rest of the install process.

Wednesday, February 24, 2010

Resizing a VirtualBox bootable WinXP drive

I have a couple of Windows images running in VirtualBox machines. (Yes I only boot linux, but still have a couple of windows images confined to their VMs). They ran out of diskspace; I created too small disks. I had attempted to solve this by adding increasingly larger secondary disks; but Windows does not like small "C:" partitions; sooner or later problems arise.

I found tips from several places about how to do this so I am going to compile my experience here. Since VDI images cannot be just resized (disk geometry can be altered), one needs to move the data to another VDI disk. The procedure is then: 1) Create a new (bigger) disk, 2) Clone the old disk into the new disk, 3) replace the disk in the virtual machine.

So far, that's more or less simple if the disk is not the primary, bootable disk. But I tried cloning with Acronis TrueImage, GParted and a couple of other tools, and they all resulted in an unbootable disk with "Disk reader error, press Ctrl+Alt+Del" message when trying to boot. I tried using the windows recovery console rebuild the MBR (fixmbr.exe) or the boot sector (fixboot.exe) but none of them worked. The extra tip was touching a parameter in the boot sector of the disk... find the details below.

Before you start, you might want to backup your entire VDI image; just in case (none of these steps will modify it... but there is always the case of selecting the wrong option).

All the steps then look like:
  1. Create the disk

    1. Shut down the virtual Windows machine
    2. From VirtualBox disk manager, create a new disk (bigger!), and attach it as secondary to that machine.

  2. Copy data. Use some cloning tool to copy the entire disk from the old disk to the new one. In my case, I found the simpler way was:

    1. Download a GParted LiveCD,
    2. Add it to the list of VirtualBox ISO images,
    3. Mount it on the virtual machine, and make sure the CDROM is first in boot order sequence.
    4. Boot GParted. Select the old disk/partition, click "Copy". Select the new disk, create on "Create Partition Table" (type "MSDOS"), then click "Paste" to bring the new data. In the resizing dialog, you can extend the partition to the end of the disk. Click "Apply" and it will take a while until the partition is copied. Then go to "Manage Flags" and enable the "Boot" flag.
    5. Shutdown the virtual machine; remove the ISO cd image.

  3. Enable the new disk (You might want to try seeing if the new disk just boots -- If you do not get a "Disk Read Error" message, skip next steps and you are done!).

    1. Start the virtual machine (still with the old disk as primary). You should be able to view the bigger, secondary disk, with the same contents as the old one.
    2. From within Windows, download Roadkil's Boot Builder. Then a) Read the boot sector of the NEW disk, b) change the "Heads" parameters to 255, c) write the sector back to the NEW disk. (Make sure not to screw up disk names! your old disk is still the backup.). See screenshot.
    3. Shutdown Windows. From VirtualBox, remove the old (smaller) disk, and leave only the new (larger) disk. Start up the VM, it will nicely boot up. (Well, Windows will boot up...)

I have no idea why that Heads parameter needs to be changed; but changing it from 128 to the magic 255 value worked for me (enlarging a 3Gb disk to 10Gb one) and others as well.

Happy cloning!

Saturday, July 18, 2009

Speed up ubuntu boot time

My notebook has run linux for a couple of years already, upgrading from kubuntu version to version, and having installed and uninstalled countless packages. This impacts in, for example, boot time.... I feel it takes too long to boot.

Here are a few things I have done last night to improve boot time. Some may or may not apply to you. I am running Kubuntu 9.04 Jaunty. Hopefully, you might even suggest more improvements.

Bootchart

First, to analyze booting time, install bootchart. It is a wonderful service that renders a graph of how startup scripts and services are run. It might add a little overhead to your load time, but it will also tell you exactly where and how time is spent. On Ubuntu: apt-get install bootchart. Mine has been there for months, but if you are just installing then boot your linux once so you get at least one chart: check out /var/log/bootchart -- a PNG image and few reports in a .tgz are created. See the image for an example: my boot took 46 seconds.

I am going to list a couple of things I did to cut boot time:

Remove services: You can see in the chart there are a LOT of services being started. I use many of them; I stopped using a few of them and others I seldom use. So I could remove some of them from my startup -- with the risk of having a few things stop working. In other cases, I will just know they are stopped, and will start it when I needed (For example: For work, there are weeks were I use a local apache2 daily; but there are periods where I don't use it -- In this case I am going to start it manually when needed). To remove a process from the startup, run (every command listed here is to be run as root): update-rc.d -f remove. If my notes are correct, these are those I have removed:
  • apache2: I don't use it daily
  • mysql (3 services starting with 'mysql'): I don't use it daily, either
  • tomcat5.5: the same
  • bluetoothd: I don't have bluetooth hardware!
  • kdm-kde4: This is a leftover from last year (was it in Gutsy? Hardy?) that I installed a KDE4 pre-release, and had the option to choose between KDE 3.x and 4.x. The service for my desktop manager is "kdm" (it appears in the chart), not "kdm-kde4" which just gives an error while running.
  • winbindd: used for samba if I am correct - I had a samba server, but not anymore
  • firestarted: a software firewall. I am behind a firewalling router already. Sometimes I use firestarter for specific things... let's start it manually when needed.
  • exim4: a mail server? I have never used it.
  • timidity: a daemon for MIDI emulation... I think I installed it and used it once in a year.
  • virtualbox-ose: Another leftover -- I used to run VirtualBox OSE (Open Source Edition), but now I am using the "closed" one. The latter has "vboxdrv" and "vboxnet" services; but virtualbox-ose is some leftover from the older virtualbox.
  • apport: A tool for crash reports. I don't know if I should removed this... but I have never filled a crash report.
  • avahi-daemon: "discovers network resources".... uhm, I don't know what this is about. I removed it, and will re-add it if needed.
  • wclientd: this is for a VPN client I have stopped using some time ago. I have other vpn services (agn*) running, this one is not needed.
I think those are most of the services I have removed. After removing, just booted once... and from the 46s original seconds I am down to about 36s!

View and remove services, graphically: There is a nice tool that lists your startup services, and you can choose to start/stop them for current session or remove them from startup sequence: "BUM", Boot Up Manager. I mostly listed manually my /etc/rc?.d directories and viewed bootchart graphs, but this one is also useful too (and it allows to remove services with a click).

Readahead

Since a few versions ago "readahead" is included by default in ubuntu installs. It is meant to read in advance all or most the files needed to boot, in the best order to maximize disk access speed, and avoid too many random seeks in the hard disk as services are started. In most installes, it uses a prebuilt list of files that are read --in a default ubuntu install--, but if you have upgraded versions, installed packages, or just let your install grow up with time, this list will be likely outdated.

To update the readahead-list, do the following: Boot your machine, and in the GRUB menu press "e" to edit the kernel parameters. Select your kernel, press "e" again and append the word "profile" (separated with a space from the last parameter written there), press Enter to accept this change and press "b" to boot. This boot will take MUCH longer than usual; it will record all disk activity. The good thing is that all the files will be listed to file /etc/readahead/boot, sorted for optimal access. Once linux booted, just reboot (you don't need to change anything in grub, the "profile" thing was a setting for boot only one time).

The original process is shown in the example chart, as taking about 10 seconds. This is actually good: if we don't do this, it would most likely take even more time to read all files needed for services to load. After profiling my boot, this time increased to about 15 seconds. But the overall time was down to 30s! (From the about 36s before readahead). This is because after the length readahead-list operation, all services load much faster.

Note that some people get benefit from readahead, and others do not. You can check if it works for you by disabling it, just emptying the file /var/readahead/boot. Measure the next load to see if readahead is useful for you. For me, it was!

Summary

I just did the two things above: removing services I don't need, and re-profiling to customize my readahead-list. This made my linux boot in 30s, from the 46s that was using -- a big gain! Yet, I am not completely happy - I know it can be done better. So I would love to hear if you have more tips!

Also, once you are done with bootchart you might want to remove it from boot. (I would not uninstall the package, you may want to use it from time to time). Just do "update-rc.d -f bootchart remove" and "update-rc.d -f stop-bootchart remove". To re-add it, you may re-install the package or add it to runlevels 2-3-4-5: update-rc.d stop-bootchart start 99 2 3 4 5

For a couple of alternatives:
  • Some people report that the splash screen (with the progress bar, while linux loads) can be expensive and slow down things. You can remove the "splash" parameter from your kernel boot (try it out in the same way "profile" was added, as described above) and see if it helps. It did not help in my case. If it does for you, then you need to go change your "defoptions" in /boot/grub/menu.lst and reinstall grub to get the 'splash' parameter removed permanently.
  • There is an endless thread (3 years old already) here with information about readahead, and if you read it thoroughly, with a lot of information and other tips.
As conclusion: I spent over 2 hours last night (not including the time to write this post) to gain 15 seconds during bootup. So I will need to boot my notebook 480 times to recover the initial investment! :) But I don't regret, it was funny and I learned a lot in the process, I think. I would love to learn more tips about it -- it would be much nicer to boot in 20s or so...