Linkshare rotating banner
Showing posts with label administration. Show all posts
Showing posts with label administration. Show all posts

Friday, October 5, 2012

Setting the Locale on Linux

A locale is a system setting that allows users to configure the operating system for their own language, date, currency, etc. on Linux. There are slightly different ways to set up locales on different Linux distributions. Here I write how I would normally set up locales on Linux.



To set the system-wide default locale, I would append the LANG= variable to the Linux kernel. The kernel will happily accept the LANG= variable and pass it to the operating system. With syslinux, I would have an entry in syslinux.cfg as follows.



LABEL debian
KERNEL vmlinuz-3.6.0
INITRD /boot/initramfs.lzma
APPEND LANG=en_US.UTF-8 TERM=vt100 root=/dev/sda9


On Debian, Ubuntu, Mint and MEPIS, the system-wide locale may be specified in /etc/environment or /etc/default/locale.



LANG=C.UTF-8


To set your own locale different from the system-wide locale, just add a line to your .bashrc or .xsession:



export LANG=zh_CN.UTF-8


Generating locale-archive Again



The number of locales available on the system may be incomplete in order to save disk space. To see which locales are available, run the following command:



locale -a


If you want to add or remove locales, edit /etc/locale.gen. The following is a sample locale.gen.



ar_SA.UTF-8 UTF-8
bn_IN UTF-8
de_DE.UTF-8 UTF-8
en_US ISO-8859-1
en_US.UTF-8 UTF-8
es_MX.UTF-8 UTF-8
fa_IR UTF-8
fr_FR.UTF-8 UTF-8
gu_IN UTF-8
hi_IN UTF-8
id_ID.UTF-8 UTF-8
it_IT.UTF-8 UTF-8
ja_JP.UTF-8 UTF-8
kn_IN UTF-8
ko_KR.UTF-8 UTF-8
ml_IN UTF-8
mr_IN UTF-8
or_IN UTF-8
pa_PK UTF-8
pt_BR.UTF-8 UTF-8
ru_RU.UTF-8 UTF-8
ta_IN UTF-8
te_IN UTF-8
th_TH.UTF-8 UTF-8
tr_TR.UTF-8 UTF-8
vi_VN UTF-8
zh_CN.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8


After changing the file locale.gen, you need to run locale-gen to regenerate the file /usr/lib/locale/locale-archive.



locale-gen


Enabling All Possible Locales


If you have plenty disk space, then you can enable all locales supported by the current glibc implementation. The list of supported locales is at /usr/share/i18n/SUPPORTED. Just copy it to /etc/locale.gen and rebuild the locales. It will regenerate the file /usr/lib/locale/locale-archive to about 100MB.



cp /usr/share/i18n/SUPPORTED /etc/locale.gen
locale-gen


Running Applications In Different Locales



Use the env command to run an application in a different locale. For example, to run pidgin in Chinese on an English desktop, I would issue:



env LANG=zh_CN.UTF-8 pidgin

Thursday, October 4, 2012

Disk Cloning / Imaging over Network with SSH, Netcat, DD and XZ

Today we have affordable, ample storage and faster bandwidth to facilitate partition imaging and disk cloning over network. Nowadays, it's common and feasible to take the image of a whole partition for various reasons. Compared to file-based backups using tar, disk imaging provides the following advantages.




  • The boot sector is preserved so that it's easy to make it bootable after the restore.
  • Information such as UUID and LABEL is presered, which helps identify the partition in booting and mounting.
  • Information such as ACL and XATTR is preserved, which helps restrict file access and secure the system.
  • Every bit in the unused sectors is preserved, which may assist in digital forensics to uncover deleted or hidden information.


There are commercial programs for disk imaging and backup (Norton Ghost, Acronis True Image). However, Linux users can use readily available tools to get things done. For disk cloning/imaging, we can use ssh, netcat, dd and xz. Note that dd will fail on physically damaged disks. For such disks, use ddrescue instead.



For security and compression, we are going to use ssh and xz in this tutorial. If you don't like xz, feel free to substitute xz with gzip, bzip2 or lzop. Also, netcat is used to stream the dd output over the network. On Debian and Ubuntu derivatives, you need the following packages.




  • bzip2, gzip, lzop, lzma OR xz-utils
  • dd
  • netcat
  • ssh


We are making these assumptions in the following scenarios.




  • Sending computer S

    This computer has IP address 192.168.1.1 and needs to back up partition /dev/sda1.
  • Sending Port

    We'll send using port 5525.
  • Receiving computer T

    This computer has IP address 192.168.1.2 and needs to restore partition /dev/sda2.
  • Receiving Port

    We'll receive at port 7749.


Disk Cloning using dd, xz, netcat and ssh


In this scenario, we will clone a disk partition, simultaneously sending an image of the source partition /dev/sda1 from computer S (192.168.1.1) and restoring it at /dev/sda2 on computer T (192.168.1.2). Make sure that the source partition is not mounted or is mounted read-only. Also, make sure that the target partition size is greater than or equal to the source partition size.




  1. At the sending computer, compress the source partition /dev/sda1 with xz and set up netcat to send it at port 5525:

    dd if=/dev/sda1 bs=16M | xz | nc -l 5525

  2. At the receiving computer, set up a SSH tunnel to the sending computer (192.168.1.1):

    ssh -f -N -L 7749:127.0.0.1:5525 username@192.168.1.1

  3. At the receiving computer, type the following command to receive the partition image and restore it at /dev/sda2:

    nc 127.0.0.1 7749 | xz -d | dd of=/dev/sda2 bs=16M



Alternatively, we could take the following steps to achieve the same thing. However, we start at the receiving computer.




  1. At the receiving computer with the target partition /dev/sda2, type the following command to receive the partition image:

    nc -l 7749 | xz -d | dd of=/dev/sda2 bs=16M

  2. At the sending computer with the source partition /dev/sda1, set up a SSH tunnel to the receiving computer (192.168.1.2):

    ssh -f -N -L 5525:127.0.0.1:7749 username@192.168.1.2

  3. At the sending computer, type the following command to compress the source partition /dev/sda1 and transmit it over the SSH tunnel:

    dd if=/dev/sda1 bs=16M | xz | nc 127.0.0.1 5525

    Note that the transfer may take many hours for a large partition.




Disk Imaging using dd, xz, netcat and ssh


In this scenario, we will just send an image of the source partition /dev/sda1 to the receiving computer T (192.168.1.2) without restoring it. Make sure that the source partition is not mounted or is mounted read-only. A question remains whether to compress the image at the sending or receiving computer. The answer depends on which computer is more powerful. For this example, we'll compress at the sending computer (for network bandwidth reason).




  1. At the sending computer, compress the source partition /dev/sda1 with xz and stream it using netcat:

    dd if=/dev/sda1 bs=16M | xz | nc -l 5525

  2. At the receiving computer, set up a SSH tunnel to the sending computer (192.168.1.1):

    ssh -f -N -L 7749:127.0.0.1:5525 username@192.168.1.1

  3. At the receiving computer, type the following command to receive the file:

    nc 127.0.0.1 7749 > partimg.xz



Alternatively, we could take the following steps to achieve the same thing.




  1. At the receiving computer, set up netcat to listen at port 7749 and save the incoming data to a file partimg.xz.

    nc -l 7749 | dd of=partimg.xz bs=16M

  2. At the sending computer, establish a SSH tunnel to the receiving computer (192.168.1.2) first:

    ssh -f -N -L 5525:192.168.1.2:7749 username@192.168.1.2

  3. At the sending computer, type the following command to compress the source partition /dev/sda1 and transmit it over the SSH tunnel:

    dd if=/dev/sda1 bs=16M | xz | nc 127.0.0.1 5525

    Note that the transfer may take many hours for a large partiiton.




Alternative Simple Commands for Disk Cloning / Imaging


I don't like these methods for some reason, but here I show the simpler methods where netcat is not needed. For disk cloning, type something like this:



dd if=/dev/sda1 bs=16M | xz | ssh username@192.168.1.2 "xz -d | dd of=/dev/sda2 bs=16M"


Just to send an image file, run a command as follows:



dd if=/dev/sda1 bs=16M | xz | ssh username@192.168.1.2 "dd of=partimg.xz bs=16M"


Also Read:


Wednesday, July 28, 2010

Checking Integrity of A Debian/Ubuntu System

Sometimes, a Linux filesystem becomes corrupted, system files are damaged, or some crucial files get lost. This often happens, regardless of which filesystem (ext2, ext3, ext4, jfs, reiserfs, reiser4, or xfs) is used. There are many possible reasons, such as:



  • Unstable hardware, for example, memory or hard drive problem
  • Overheat, power surge, quake or another environmental disaster
  • Buggy software, such as a bug in the kernel or the filesystem driver
  • Compromised security, for example, network intrusion or attack
  • Worm or virus infection


Files in Linux systems can be categorized into the following three:




  1. Verifiable System Files

    In Linux systems that are managed by packages (such as Debian and Ubuntu), these files are installed by packages and make up the bulk of the filesystem. These files reside in such directories as /bin, /lib, /sbin and /usr. They are usually static, which means they don't normally change except when the system is updated, or locally compiled binaries are installed.
  2. Changeable System Files

    These files are auxiliary system files for system configuration, initialization or customization, and system data (such as logs and cache). They reside in /boot, /etc, /opt, /srv and /var.
  3. User Data

    These files are created and used by superuser (a.k.a root) and normal users, or software-generated during casual user activities. Typically, they are in /home, /media, /mnt and /root.


This post focuses on verifiable system files (installed by packages). When the filesystem becomes corrupted (but not completely unreadable), it is possible to verify and restore the system integrity by using package checksums. Before you continue, make sure to fsck the filesystem.



e2fsck -r -v /dev/sda7


In this example, /dev/sda7 points to an ext2 partition we're going to check. Be aware that you cannot fsck a mounted filesystem. Therefore, boot with a Debian Live CD (or a Ubuntu CD) and run fsck. After you've performed fsck, there may be some files created in the /lost+found directory. We'll deal with them later. First, mount the filesystem.



mount -t ext2 /dev/sda7 /mnt


Go to /var/lib/dpkg/info. Then, concatenate all the md5sums files. Most, if not all, Debian and Ubuntu packages come with a md5sum file that we can use to check the integrity of the package and the files installed by the package.



cd /var/lib/dpkg/info
cat *.md5sums | sort > /dev/shm/all.md5


all.md5 has md5 checksums of all the files installed on the system. Now, check the files on the Debian/Ubuntu system against the concatenated md5sums file.



cd /
md5sum -c /dev/shm/all.md5 > /dev/shm/check.txt 2>&1


/dev/shm/check.txt now contains the results of the integrity check. It looks like this:



bin/bash: OK
bin/bunzip2: OK
bin/bzcat: FAILED


In this example, /bin/bzcat is damaged. To find all the missing or damaged files, use a command like this one:



grep -v ': OK$' /dev/shm/check.txt


Let's reinstall this file. First, find out which package this file belongs to.



dpkg -S /bin/bzcat


We'll see the following result.



bzip2: /bin/bzcat


Now we know that we need to reinstall bzip2. Let's download the package.



dpkg -p bzip2 | grep 'Filename: '


This command will let us know the name of the package to download. Use wget to download it.



wget ftp://ftp.us.debian.org/debian/pool/main/b/bzip2/bzip2_1.0.5-4_i386.deb


You can just reinstall the package.



dpkg -i bzip2_1.0.5-4_i386.deb


Or, you can just extract one file:



dpkg --fsys-tarfile bzip2_1.0.5-4_i386.deb | tar xf - ./bin/bzcat


Alternatively,



dpkg --fsys-tarfile bzip2_1.0.5-4_i386.deb | tar xOf - ./bin/bzcat > /mnt/bin/bzcat


To restore a file from the /lost+found directory, you can also use the MD5SUMS file. First, run md5sum on files in /lost+found.



cd /lost+found
md5sum *


You may get an output like this.



9aaa2176d20c1b1203e3abbac55a2513  #124531


To find out what #124531 file is originally, find its md5 checksum from the all.md5 file above.



grep 9aaa /dev/shm/all.md5


You'll get a result like this.



9aaa2176d20c1b1203e3abbac55a2513  bin/bzip2


Now you can just move it to its place.



mv \#124531 /mnt/bin/bzip2


After you restore all damaged files and restore files from /lost+found, you can find missing files in the system. Go to /var/lib/dpkg/info again and concatenate all the list files.



cd /var/lib/dpkg/info
cat *.list | sort | uniq > /dev/shm/all.txt


The .list files in the /var/lib/dpkg/info directore show the list of files installed by packages. Let's find what's missing from the system.



cd /
for f in $(cat /dev/shm/all.txt ); do test -e "$f" || echo "$f" >> /dev/shm/nonexist.txt ; done


The file /dev/shm/nonexist.txt will show which files are missing from the system. You can then replace the missing files as done previously.

Monday, July 26, 2010

Linux: Using dd To Back Up Hard Drive Partitions

I am going to use the omnipresent and omnipotent tool called dd to back up a hard drive partition. I am working with the drive /dev/sdb. First, I save a text file that has information on the partition table layout.



fdisk -l /dev/sdb > hdpt.txt
fdisk -l -u /dev/sdb >> hdpt.txt


Then, I choose the compression format to use for the backup archive.


  • gzip
  • bzip2
  • lzma
  • xz


My choice for the compression format is lzma which provides superior compression and faster decompression. The following command backs up a partition at /dev/sdb1 with dd and lzma.



dd if=/dev/sdb1 | lzma -9c > backup01.bin.lzma


To restore this backup later, use the following command:



lzcat backup01.bin.lzma | dd of=/dev/sdb1

Thursday, July 22, 2010

Linux Commands To Partition and Format a Drive

Partitioning



In addition to the wonderful gparted, we can also use fdisk to partition a disk:



fdisk /dev/sdb


The device names for hard disks and USB drives are typically /dev/sd?, for example, /dev/sda, /dev/sdb, /dev/sdc, etc. For Linux kernels 2.6.18 or older, IDE hard drives may be called /dev/hda, /dev/hdb, etc.



Formatting



To format a FAT16 partition:



mkdosfs -F 16 -n LABEL -r 512 -v /dev/sdb1


To format EXT2 partition:



mke2fs -L SID -v /dev/sdb2


To format a JFS partition:



jfs_mkfs -c -L Debian_Sid /dev/sdb2


Installing MBR


MBR is a boot code necessary for booting from the hard drive or USB flash.



install-mbr /dev/sdb -v --drive 0x80 --enable +12


Installing bootloaders


For SYSLINUX:


syslinux /dev/sdb1


Checking Filesystem Integrity


For FAT16/FAT32:


dosfsck -r -v -V /dev/sdb1

Saturday, March 13, 2010

Windows 7 Installation

I installed the following programs on my Windows 7 machine.



  • Adobe Flash Player
  • Adobe Reader 10.0
  • Avast Antivirus 5
  • CDBurnerXP or ImgBurn
  • Google Apps or Thinkfree
  • Google Chrome
  • IBM Lotus Symphony
  • iTunes
  • Java
  • Microsoft Office 2010
  • NVIDIA Driver
  • QuickTime
  • RealPlayer
  • Skype
  • Windows Live Essentials
  • Zimbra
  • Zumodrive

Monday, July 6, 2009

Ripping a Bootable Acronis TrueImage Diskette

I am trying to incorporate Acronis TrueImage into my bootable Linux CD. Acronis TrueImage is backup software that saves the entire hard disk partition of Windows or Linux system. In short, I am going to use the Bootable Rescue Media Builder to turn my Zip100 or 128MB USB flash into a rescue media, rip it with WinImage and then copy it into my CD. Here's how I did step-by-step:


Start the Bootable Rescue Media Builder under Aronis Start menu.


Bootable_Rescue_Media_Builder_01

In the Rescue Media Contents Selection window, check Acronis True Image Home (Full version) at the left and check Start automatically after 10 sec. at the right. Then, click Next.


Rescue_Media_Contents_Selection

Plug in your USB flash. At the present, any media larger than 64MB will do. That means 128MB USB flash is the minimum. I am using 100MB Zip diskette. At the Bootable Media Selection window, choose a Removable Disk that's blank and more than 64MB, but not Floppy Diskette nor ISO image.


Bootable_Media_Selection

Acronis Media Builder says it's ready to start the media creation process.


Acronis_Media_Builder_Ready

Click Proceed. Acronis Media Builder formats the drive and copies files to it.


Acronis_Media_Builder_Processing

Upon completion, check your rescue media.


Acronis_Media_Builder_complete

Ripping the partition with Linux dd


Now, reboot to Linux and open xterm or your favorite terminal emulator. Plug in your USB flash if you haven't done so. Linux will automatically detect your USB drive. To find the device name of your USB drive, type:


dmesg | tail

dmesg will show the drive letter of the USB flash that was just plugged in. In case your USB flash is /dev/sdc1, type the following command:


dd if=/dev/sdc1 of=sdc1.bin bs=512

This saves the partition of Acronis rescue media as sdc1.bin. Copy it to your Windows partion. Then, reboot to Windows.



Using WinImage to Resize the Partition Image


Download and install WinImage.

Installing Acronis TrueImage Home 2009

Acronis True Image is a cross-platform backup solution for Windows and Linux. True Image is the right choice for regular Windows users besides Norton Ghost. Today I am installing True Image Home 2009 Demo. This download is good for only 15 days unless I purchase a serial. I downloaded the English-language installer (TrueImage2009_d_en.exe) and started it.


At first, clicking on any menu item wouldn't work. Finally I figured it out. I had to right-click on Install Acronis True Image Home and choose Install or Extract from the Right-click menu.


Acronis_True_Image_Home_2009

If it still doesn't work, bring up the Windows Task Manager by pressing Ctrl+Alt+Del and close the Acronis True Image Home Setup.


Korean Windows Vista Task Manager

A “Save As...” dialog will appear and ask for the location to save the installer in. Save the installer file AcronisTrueImage.msi in any folder you want. Then, double-click on AcronicTrueImage.msi to begin TrueImage installation.


Save AcronisTrueImage.msi installer

Just ignore the Serial Number window and continue. I chose Complete setup. Reboot is required after install.

Thursday, April 2, 2009

Tweaking Windows Vista for Slow PC

Is Windows Vista only for fast and powerful computers? Not really. Technically, Vista can run on old computers with a CPU as slow as 800MHz. But Vista runs sluggish on old computers. For those old and slow computers, there are some ways to improve the speed of Vista, as explained below.


Stop unnecessary programs from running or starting.


Don't use the Windows Sidebar. This program is unnecessary and graphics-intensive program that slows your computer down. You can easily disable it from starting.


Disable UAC


Disabling UAC may dramatically speed up Windows Vista.



Disable Windows Theme


If you don't need fancy Windows themes, you can change your theme to a plain one or disable the Themes service altogether.

About This Blog

KBlog logo This blog seeks to share useful information on hottest movies available on the Internet. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger