Saturday, June 13, 2009

Part II: Success - Restoring my EeePC from USB to a Minimal System

(cont'd from Part I: My 1st Trial)

After struggling for two weeks with failures after failures, I have finally worked it out. It turned out that simply by moving the files from sda1 to sda2 and back is enough to defragment the filesystem. But depending on the packages you removed and where the files are originally located, the resulted disk fragmentation may vary and it need some trial and error to determine the end block of sda1.

For the brave ones who would like to join my adventure, you can download my script package restore-minimal-701-4G.tgz and extract the files to your EeePC System Recovery USB disk. [NB. Do not use winzip to extract the files] Then reboot and run it like what I have described in Restore EeePC from Recovery DVD without unionfs or Boot Xandros from USB for Dummies.

Scenario I have Tested

This is only preliminary success - different scenarios are not yet thoroughly tested. So far only tested successful with the following setup:
Hardware: EeePC 4G
Recovery EeePC Linux disk image: 701 4G iso
Set of Uninstalled Programs: Minimal system (as per remove*.list files I have enclosed in my script package)
Allow extra disk space while shrinking filesystem = 5% (achieving final available disk space of 92% vs. original of 96%)
[NB. If you shrink the filesystem too much with resize2fs, it is not possible to redo it. You will have to start all over again. So it is up to you to experiment if you want to maximize use of disk space in the read only partition.]

If you have another version of EeePC Linux other than the EeePC Linux version 1.0 (for 701 4G) I have tested, you will need to check and change the package names in the remove*.list files according to your version. Run "dpkg -l" to list packages installed in your system and compare with my remove list.
[Remember: Do not edit the files with Windows Notepad. Use
Notepad2 instead if you want to do it in Windows. The files should be saved with UNIX style "End of Line" instead of MSDOS text file.]

Before and After

Here are the "df" and "fdisk -l" outputs before and after the process. These show the free disk space and the partition layout before and after the process:

1) Original 5% free disk space in sda1, 2147308k used out of 2371820k total filesystem size
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/sda1 2371820 2147308 104028 95% /mnt
2) Now 8% free disk space in sda1, Used = 1367640k, i.e. freed up 780 MB. Also filesystem size reduced to 1534320k, i.e. 35% smaller
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/sda1 1534320 1367640 119932 92% /mnt
3) Original disk partition layout: sda1 occupies 300 cylinders and sda2 occupies 184 cylinders
Disk /dev/sda: 4001 MB, 4001292288 bytes
255 heads, 63 sectors/track, 486 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 300 2409718+ 83 Linux
/dev/sda2 301 484 1477980 83 Linux
/dev/sda3 485 485 8032+ c W95 FAT32 (LBA)
/dev/sda4 486 486 8032+ ef EFI (FAT-12/16/32)
4) After resizing: sda1 only occupies 193 cylinders and sda2 enlarged to 291 cylinders
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1 1 193 1550241 83 Linux
/dev/sda2 194 484 2337457+ 83 Linux
Please note that I have tested it a few times and the numbers given here and below are extracted during different trials. So they may not correlate.

The Restore Process

It took me 17 mins to run this restore process once, break down as follows:
1) 5 mins - Boot up and restore Linux system image from USB (depending on the speed of your USB device, it may take longer)
2) 2 mins - Uninstalling packages
3) 8 mins - Defragment filesystem [NB. the more files in sda1, i.e. less packages you remove, the longer it will take]
4) 2 mins - Resize filesystem and partition

During the process, you will be prompted by apt-get to confirm removal of programs [Y/n]? for each remove*.list file it processes.
Processing remove_settings.list ...

Reading package lists... Done
Building dependency tree... Done
Note, selecting libclamav-client-perl for regex 'libclamav*'
Note, selecting libclamav-dev for regex 'libclamav*'
Note, selecting libclamav2 for regex 'libclamav*'
Note, selecting libclamav-client-perl for regex 'clamav*'
Note, selecting php5-clamavlib for regex 'clamav*'
Note, selecting clamav for regex 'clamav*'
Note, selecting clamav-freshclam for regex 'clamav*'
Note, selecting clamav-dbg for regex 'clamav*'
Note, selecting libclamav-dev for regex 'clamav*'
Note, selecting clamav-base for regex 'clamav*'
Note, selecting libclamav2 for regex 'clamav*'
Note, selecting sylpheed-claws-clamav for regex 'clamav*'
Note, selecting sylpheed-claws-gtk2-clamav for regex 'clamav*'
Note, selecting clamav-testfiles for regex 'clamav*'
Note, selecting clamav-data for regex 'clamav*'
Note, selecting clamav-getfiles for regex 'clamav*'
Note, selecting python2.4-clamav for regex 'clamav*'
Note, selecting python-clamav instead of python2.4-clamav
Note, selecting clamav-daemon for regex 'clamav*'
Note, selecting clamav-docs for regex 'clamav*'
Note, selecting python-clamav for regex 'clamav*'
Note, selecting clamav-milter for regex 'clamav*'
Note, selecting php4-clamavlib for regex 'clamav*'
The following packages will be REMOVED:
clamav clamav-base clamav-freshclam libclamav2 xandros-antivirus
0 upgraded, 0 newly installed, 5 to remove and 85 not upgraded.
Need to get 0B of archives.
After unpacking 14.3MB disk space will be freed.
Do you want to continue [Y/n]?
[Y/n] means default is "Yes"(Y), you have to press "n" (no) and then [Enter] to cancel. If you simply press [Enter], this means "Yes"(Y).

Later during the process, you will be asked to confirm shrinking the system partition [yes/NO]:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1 2371820 1363532 887804 63% /mnt

There is now 887804K available disk space in /dev/sda1
Please note that this free space cannot be used by the union filesystem
because /dev/sda1 is always mounted read only.

Do you want to shrink /dev/sda1 to 1558216K? [yes/NO]:
This time, "NO" is in capital letter, meaning default is "NO". If you enter anything other than "yes" or "YES", the script will abort resizing.

So if you answer NO to each prompt, you will end up with the original factory default EeePC Linux, as it has come with your EeePC.

Additional Notes

There are a few points to note during the process:

1) There will be some lines of errors while moving files between sda1 and sda2:
Moving /usr/lib/[b-l] ...
mv: unable to rename '/mnt/usr/lib/libevent.so.1': No such file or directory
mv: unable to rename '/mnt/usr/lib/libgcj_bc.so.1': No such file or directory
mv: unable to rename '/mnt/usr/lib/liblber.so.2': No such file or directory
mv: unable to rename '/mnt/usr/lib/libldap.so.2': No such file or directory
mv: unable to rename '/mnt/usr/lib/libldap_r.so.2': No such file or directory
mv: unable to rename '/mnt/usr/lib/libvolume_id.so': No such file or directory
But I have double-checked that these files (actually symbolic links) mentioned are intact after resizing. So don't worry.

2) With the minimal system, I have found a hissing sound from the speaker as reported many times by other EeeUser forum members (both Linux and winxp). This will not affect music playing, and will go off if you mute the speakers. Since this occur to both Linux and winxp, I am inclined to think it is hardware related (perhaps BIOS?). I have not looked into this yet.

3) The display will blank after 10 minutes of no activity from the keyboard. So it will blank while resizing the partition. Don't panic! Just press any key and display will come back.

4) To defragment the system partition, what I am doing is to copy files from sda1 to sda2 and back again. I break the files into groups of less than 400MB each. This is supposed to be the free disk space in a 2G Surf, so I guess this should be the mininum size of sda2 for different EeePC models.

5) The script will run an "extra.sh" script (in the folder "extra" of the System Recovery USB Disk). It will install "rescue mode" to your grub boot menu, and install your custom initramfs image (if any) and firstrunwizard.conf (to /usr/share/apps/firstrunwizard/) in case you have an recovery iso of a different language version than that you are using.

You will need to edit the "extra.sh" script and give the name of your custom initramfs image and put it in the folder "extra".

6) Theoretically, this restore script should also support restoring to the 2nd SSD (/dev/sdb), but this has not been tested since I don't have a 2nd SSD in my 4G.

7) Likewise, the original restore script will check and detect if the 2nd SSD is non-removable (i.e. not an USB disk) and format it as the HOME partition to be mounted in /home. But there is something missing here: the original script will not set the volume label of sdb1 to HOME if the partition already exist. So many people have reported losing the 16GB partition after USB restore if they have previously installed another Linux in sdb1. I have modified the script to cater for this. But again, since I don't have a 2nd SSD in my 4G, this is untested.

8) The script will save some log files to the folder "log" in the System Recovery USB Disk. This is mainly for debugging and to compare free disk space and fdisk output of partition structure before and after.

The most useful log file will be "removed.log". This log file contains a list of names and version no. of packages removed during this process. If you want to re-install the packages afterwards, this would help giving you the exact package names and version no. [See Part III: Re-installing Removed Packages to my minimal EeePC Linux 701 4G]

Conclusion

In the end, I got my EeePC Linux version 1.0 back again in my EeePC 4G, still with union filesystem, but most programs can now be upgraded without wasting excessive disk space as now they reside in the USER partition.

For the purpose of testing, I have re-installed all programs I have removed and come back to about the same free disk space as before. It is actually slightly less because of the upgrades.

If it is for real production use, I would probably skip some packages, for example, I won't need the Simplified Chinese locales, and probably also not the games and kids programs. Also, I never use Skype and pidgin ...

If you are more aggressive, there will probably be more packages you can remove provided that you are familiar with Linux system administration. The remove list I have included are all applications that has nothing to do with the base system, that I know has update available, and that their removal will not impair system operation. You can experiment with whatever you like, just make sure the system can still boot up, connect to network, automount USB device, and re-install packages. [Note: Although I have removed firefox, you can still connect to the Internet with the default File Manager. Just type the URL in the address bar as with any browser.]

What's Next?

In the coming few days, I will proceed to test this for different scenarios:
- with different remove lists
- find out the minimum extra disk space %
- test with other iso I have on hand including: 900, 1000H and 1.6 French iso

Hopefully, this script can run for all EeePC Linux versions and for all EeePC models, and be bug free. But for the remove files list, you will have to customize it for yourself. No two users will have the same likings for applications of his or her choice. So it is up to you to decide which packages you want to remove or retain for your EeePC.

Continue:
Part I: My 1st Trial
Part II: Success - Restoring my EeePC from USB to a Minimal System
Part III: Re-installing Removed Packages to my minimal EeePC Linux 701 4G
Part IV: 2nd Test restoring to minimal with a 1.6.1 701 en iso
Part V: Yet another test with 1.6 French iso
Conclusion: Restore from USB to minimal system

No comments:

Post a Comment