Saturday, November 05, 2011

Remove accent marks from filename in Vietnamese

(Gỡ bỏ dấu tiếng Việt trong tên tập tin)

This is a java code from http://khoinguonit.com/f80/[java]-doi-ten-file-tieng-viet-co-dau-thanh-khong-dau-1578/

  • It reads files from the input folder and then moves them to output. To make changes to files in the current directory, use . (dot) instead.
  • Online complier at http://www.innovation.ch/java/java_compile.html.
  • From console, run it by java Rename, or make a run.bat:
    @echo off
    java Rename

    pause
  • This code also changes upper cases into lower cases.

Saturday, October 22, 2011

Shrink VirtualBox disk images

In Linux (Debian) guest:
  • apt-get install zerofree
    zerofree is a small program which uses the ext2fs library to get a list of all the blocks, checks if the current block is free but non-zero (i.e. has been used at some point) and fills it with zeroes again. The utility also works on ext3 or ext4 filesystems. This allows the VBoxManage tool to compact the VDI.
  • init 1
    to go to single mode.
  • mount -n -o remount,ro -t ext2 /dev/XXX /MOUNTPOINT"
    to remount all partitions read only (chec the available filesystem with df).
    • -n : not try to update "/etc/mtab" (which might be on the now read only disk)
    • -t ext2 : not need journaling.
  • fsck.ext2 -f /dev/XXX
    to check the filesystem (if necessary).
  • zerofree /dev/XXX
  • fsck.ext2 -f /dev/XXX
    again to check the filesystem (if necessary).
  • mount -t ext4 -o remount,rw /dev/XXX /MOUNTPOINT
    to remount the partitions back to normal.
  • Shutdown the virtual machine.
In Windows guest:
  • Perform hard disk defragmentation.
  • Download sdelete from http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
  • sdelete -c DRIVE:
  • Shutdown the virtual machine
In host:
  • VboxManage modifyhd /path/to/the/vmdiskimage.vdi --compact
Ref:
- http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi
- http://intgat.tigress.co.uk/rmy/uml/sparsify.html
- http://forums.virtualbox.org/viewtopic.php?t=1198
- http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06

Thursday, October 13, 2011

Access linux filesystems in Windows

There are some drivers available to access a linux filesystem from Windows, such as Ext2Fsd (read and write, for ext2, partly ext3/ext4), explore2fs (read-only, for ext2/ext3), Ext2read (read only, for ext2/ext3/ext4), DiskInternals Linux Reader (freeware, read-only, for ext2/ext3/ext4, HFS and ReiserFS), Ext2 Installable File System for Windows (freeware, read and write, for ext2), RFSTOOL (read-only, for ReiserFS), ReiserDriver (read-only, for ReiserFS), LTOOLS (read and write, for ext2/ext3 and ReiserFS). Some of them have stopped development for quite a long time.

An more "native" approach is to make use of a virtual machine to read and write the linux filesystems on internal and external hard disk drives. It seems to be the only choice for btrfs until now.

  • Install VirtualBox (with USB support enabled).
  • Create a Debian virtual machine. Get a Debian netinst image and install a base system (without any suggested groups of packages). It takes around 900 MB plus swap space at the time of this writing. Network of the virtual machine is set to bridged.
  • To access a linux partition on intrenal hard disk drive: create an image representing it and add it to VirtualBox
    • Run cmd.exe as administrator.
    • Change into the VirtualBox directory:
      cd "c:\Program Files\Oracle\VirtualBox"
    • List the partitions of the hard disk:
      VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDriveX
      with X is the hard disk drive number (the first one in Windows is numbered 0). Linux filesystem is 0x83. Note the number(s) of the needed partition(s).
    • Create the image of the partition(s):
      VBoxManage.exe internalcommands createrawvmdk -filename "\path\to\file.vmdk -rawdisk \\.\PhysicalDriveX -partitions Y,Z
      The image file name has to be a .vmdk. Y, Z are the partitions numbers found by the previous command.
    • Run VirtualBox as administrator. Go to Storage tab of the Settings of the machine. Add the image in SATA Controller.
  • To access a linux partition on usb hard disk drive, select it from the menu Devices -> USB Devices from the machine window.
  • Install samba package. Its current version on Debian testing is 3.5.11.
    • Check available samba users with pdbedit -L -a. Create a new samba user (if necessary) with smbpasswd -a username (the username should be added in Linux system by useradd before that).
    • The default smb.conf should work out of the box, or can be edited to meet appropriate share needs. By default, the home directory of the user will be shared and read-only is set. To enable writing, set read only = no in [homes] definition. File and directory creation mask can also be re-set. Run /etc/init.d/samba reload to reload smb.conf.
  • Mount the partitions on internal and/or usb hard disks to directories which can be accessed by samba.
  • In Windows 7, type the IP address of the virtual machine in search/run box (menu Start), like \\192.168.56.38 (found by running ifconfig in the virtual machine). Windows 7 uses DOMAIN/username to login, which fails to log into samba server. This can be bypassed by adding a \ before the username.

Notes:

  • There are reports that with old versions of Samba and Windows 7, it is necessary to modify the Local Security Policy to set the LAN Manager Authentication Level to “Send LM & NTLM responses”. In Windows 7 Professional, this can be done in Control Panel -> Administrative Tools or secpol.msc from the command line. Windows 7 Home versions don’t have this tool but the same thing can be done by edit the registry by hand: open registry with regedit, go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa and add a DWORD value named "LMCompatibilityLevel" and set the value to "1".
  • To enable USB 2.0 (EHCI) controller, VirtualBox extension package must be installed separately.
  • Be careful with USB devices that are currently in use on the host! For example, if you allow your guest to connect to your USB hard disk that is currently mounted on the host, when the guest is activated, it will be disconnected from the host without a proper shutdown. This may cause data loss.
  • There are suggestions to use coLinux. But it does not support 64-bit system at the current time.

Links:

  • Ext2Fsd: http://www.ext2fsd.com
  • Explore2fs: http://www.chrysocome.net/explore2fs
  • ext2read: http://sourceforge.net/projects/ext2read/
  • DiskInternals Linux Reader: http://www.diskinternals.com/linux-reader
  • Ext2 Installable File System For Windows: http://www.fs-driver.org/index.html
  • RFSTOOL: http://freshmeat.net/projects/rfstool
  • ReiserDriver: http://rfsd.sourceforge.net
  • LTOOLS: http://www2.hs-esslingen.de/~zimmerma/software/ltools.html
  • VirtualBox: https://www.virtualbox.org
  • coLinux: http://www.colinux.org
Ref:
- http://www.virtualbox.org/manual/ch09.html#rawdisk
- http://www.ubuntugeek.com/howto-access-ext3-partition-from-windows.html

Saturday, April 16, 2011

Using tor button

1. # apt-get install iceweasel-torbutton
will install other related packages as well.

2. Configure polipo:
- backup /etc/tor/config
- use this file https://gitweb.torproject.org/torbrowser.git/blob_plain/HEAD:/build-scripts/config/polipo.conf as the above config file

3. Configure tor
- Uncomment these lines in /etc/tor/torrc
SocksPort 9050 # what port to open for local application connections
SocksListenAddress 127.0.0.1 # accept connections only from localhost
RunAsDaemon 1
ControlPort 9051

4. Restart polipo and tor
# /etc/init.d/polipo restart
# /etc/init.d/tor restart

Ref:
- https://www.torproject.org/docs/tor-doc-unix.html.en
- http://forums.opensuse.org/get-help-here/network-internet/429127-tor-not-starting.html#post2091241

Blank screen during boot

# lspci
1:00.0 VGA compatible controller: ATI Technologies Inc NI Seymour [AMD Radeon HD 6470M]

A blank screen appears after messages about udev. Cannot move to other consoles by Alt-Fx. However, can "blind" log-in, run startx and X works.

Solution: append radeon.modeset=0 (or nomodeset, if this does not work) to the kernel options line in the bootloader configuration file (/boot/grub/menu.lst or /boot/grub/grub.cfg [but this file is subject to change when upgrading GRUB] for GRUB users) to disable KMS.

Ref: https://wiki.archlinux.org/index.php/Ati

Tuesday, April 05, 2011

Installing Debian via the Internet from Windows (amd64)

1. Download linux (the kernel) and initrd.gz from
http://d-i.debian.org/daily-images/amd64/daily/netboot/debian-installer/amd64/

2. Install and boot GRUB4DOS.
kernel /linux
intrd /initrd.gz

3. The installation begins.

Using GRUB4DOS from Windows 7

A. GRUB4DOS
Copy grldr.mbr, grldr and menu.lst to C:\.

B. BCDEdit
1. Backup the current config:
bcdedit.exe /export c:\filename

2. Create new entry
bcdedit.exe /create /d "GRUB4DOS" /application bootsector

This returns a guid of 32-character string like
{5ed99144-5f57-11e0-818a-78843ccde686}
.
3. Set entry option value: device
bcdedit.exe /set {5ed99144-5f57-11e0-818a-78843ccde686} device boot

However, when booting, it may get the following error:
File: \grldr.mbr
Status: 0xc000000f
Info: The selected entry could not be loaded because the application is missing or corrupt.

This is because becouse Windows 7 creates a hidden extra partition for the BCD. Then, this command should be issued:
bcdedit /set {5ed99144-5f57-11e0-818a-78843ccde686} device partition=C:

4. Set entry option value: path
bcdedit.exe /set {5ed99144-5f57-11e0-818a-78843ccde686} path \grldr.mbr

5. Set entry display order
bcdedit.exe /displayorder {5ed99144-5f57-11e0-818a-78843ccde686} /addlast

6. Set timeout (for example, 2 sec)
bcdedit /timeout 2