Wednesday, October 24, 2012

Partitioning and Formatting Second Hard Drive in Linux - (ext3 and ext4)

SkyHi @ Wednesday, October 24, 2012

Recently, I bought an external hard disk formatted with NTFS. Not that there is something really wrong with NTFS but I prefer using ext4.
First, I deleted the existing partition and created a new Linux partition using fdisk:
?
1
# fdisk /dev/sdb
Assuming /dev/sdb is the external hard disk. Use d to delete the partition and use n to create a new partition. 83 is the ID of the native Linux partition.
Them, I use mkfs.ext4 to format the partition with ext4:
?
1
# mkfs.ext4 /dev/sdb1
Note that mkfs.ext4 expects a partition as its argument.
Finally, I use tune2fs to adjust some parameters: // don't need this
?
1
2
# tune2fs -m 0 /dev/sdb1
# tune2fs -L bakap01 /dev/sdb1
The -m option is for adjusting the percentage of reserved blocks. The reserved blocks are used by privileged processes which is by default 5% of the hard disk size. Since I’m using the external hard disk solely as a storage, I set this to 0 so I can also use those 5% for storage. The -L option is for labeling the filesystem.



Introduction

This article presents the commands used to partition and format a second hard drive in Linux using the ext3 file system. For the purpose of this example, I installed a second hard drive in a Red Had Linux system where the drive is recognized as /dev/hdb. I want to make only one partition on this hard drive which will be /dev/hdb1.

fdisk

First, you will need to run the fdisk command in order to partition the disk. For this example, I only want to create one ext3 partition. Here is an example session:
[root@racnode1 ~]# fdisk /dev/hdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 4865.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4865, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-4865, default 4865): 4865

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create ext3 File System

The next step is to create an ext3 file system on the new partition. Provided with the distribution is a script named /sbin/mkfs.ext3. Here is an example session of using themkfs.ext3 script:
[root@racnode1 ~]# mkfs.ext3 -b 4096 /dev/hdb1
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
4889248 inodes, 9769520 blocks
488476 blocks (5.00%) reserved for the super user
First data block=0
299 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Mounting the File System

Now that the new hard drive is partition and formated, the last step is to mount the new drive. For this example, I will be mounting the new hard drive on the directory /db.
 
You will first need to create the /db directory before mouting the disk! (e.g. mkdir /db)
Edit the /etc/fstab file and add an entry for the new drive. For my example, I will create the /dev/hdb1 entry as follows:
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
/dev/hdb1               /db                     ext3    defaults        1 1
/dev/hda2               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
After making the entry in the /etc/fstab file, it is now just a matter of mounting the disk:
[root@racnode1 ~]# mount /db

[root@racnode1 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda3             37191660  11016692  24285724  32% /
/dev/hda1               101089     12130     83740  13% /boot
none                    515524         0    515524   0% /dev/shm
/dev/hdb1             38464340     32828  36477608   1% /db



  237  dmesg
  238  df -h
  239  fdisk -l
  240  fdisk /dev/sdb (n -> p-> default to rest)
  247  mkfs.ext4 /dev/sdb1
  261  mount -t ext4 /dev/sdb1 /opt


REFERENCES
http://blag.borap.net/2011/08/10/formatting-an-external-hard-disk-with-ext4/
http://ashok-linux-tips.blogspot.ca/2011/05/createconvert-ext2-or-ext3-or-ext4.html
http://www.idevelopment.info/data/Unix/Linux/LINUX_PartitioningandFormattingSecondHardDrive_ext3.shtml

Monday, October 22, 2012

Hard Disk: BadCRC errors from dma_intr on bootup

SkyHi @ Monday, October 22, 2012

If dma is enabled on a controller that is not well supported, these errors can appear. ( I had it on a VIA KT266a with kernel 2.2. Upgrading to kernel 2.4 fixed it beautifully.
If you are sure that the IDE controller is supported, the drive is on its way out. You can run fsck with the badblock option turned on to mark these blocks as bad... As a rule, once these errors start, we throw the disk away(This is a high availability production environment).
If you dont mind that the disk can crash in the near future, make a backup and continue using it, it might work for a long time to come.
If the disk is under guarantee... take it back, it is not worth risking data loss if the drive can be replaced for free.
This is how you hunt for and fix badblocks.
# e2fsck -c /dev/hda1
Make sure that you have a backup, badblock scans can destroy data running with certain switches.
# man badblocks && man e2fsck (And read them carefully)
To turn of dma per drive
# hdparm -d0 /dev/hd[a-d]
To list dma settings
# hdparm -d /dev/hd[a-d]
To turn dma on
# hdparm -d1 /dev/hd[a-d]
Where hd[a-d] is hda, hdb, hdc, hdd.

REFERENCES
http://linuxgazette.net/issue76/tag/10.html

Tuesday, October 16, 2012

grant sudo privileges to an existing user

SkyHi @ Tuesday, October 16, 2012

sudo usermod -a -G sudo hduser

Change Default Editor for visudo in Ubuntu

SkyHi @ Tuesday, October 16, 2012

Ubuntu and Debian use the alternatives system to maintain the symbolic links for programs. When you first run visudo, it will prompt a list of editors for you to choose from. Unfortunately, it doesn’t tell you how to change that setting again. The mostly happend situation is: you set it to “nano” at first, and can’t change it to “vi” at a later time.
Here is the command to bring up that list again:
sudo update-alternatives --config editor
Some people suggest using command EDITOR=vi visudo, or export EDITOR=vi; visudo, but it’s really annoying if you have to remember and type so many letters everytime you run this command


REFERENCES

Thursday, October 11, 2012

How to rename a file or folder in Mac OS X

SkyHi @ Thursday, October 11, 2012

Renaming a folder in Mac OS X is very easy, and there’s a few different ways you can do it.
Rename a file or folder by selecting it and hitting the ‘return’ key – just click on the icon of the file/folder and hit the return key, then type in the new name.
Rename a file or folder by selecting it and clicking on the filename with your cursor – after you have selected the icon, click on the actual filename text and hover for a moment, then you can rename the item.
Rename a file or folder via command line – you can also rename any file or directory via the Terminal, from the command line type:mv oldfilename newfilename
A note on file extensions: be aware when renaming certain files that changing the file extension (.jpg or .txt, etc) can effect the behavior of that file and how applications respond to it. Generally speaking, you should leave the file extension the same.
I realize this is pretty rudimentary stuff to many of our readers, but two recent switchers have asked me this question so surely they can’t be alone in wondering, both were trying to do the Windows right-click -> rename method which is sure to cause some confusion in Mac OS X.

REFERENCES

How To Capture a Screen Shot with Mac OS X

SkyHi @ Thursday, October 11, 2012

Here's How:

  1. To capture the entire desktop, press Command-Shift-3. The screen shot will be automatically saved as a PNG file on your desktop.
  2. To copy the entire desktop, press Command-Control-Shift-3. The screen shot will be placed on your clipboard for you to paste into another program.
  3. To capture a portion of the desktop, press Command-Shift-4. A cross-hair cursor will appear and you can click and drag to select the area you wish to capture. When you release the mouse button, the screen shot will be automatically saved as a PNG file on your desktop. (The file is saved as PDF in Mac OS 10.3 and earlier.)
  4. To capture a specific application window, press Command-Shift-4, then press theSpacebar. The cursor will change to a camera, and you can move it around the screen. As you move the cursor over an application window, the window will be highlighted. The entire window does not need to be visible for you to capture it. When you have the cursor over a window you want to capture, just click the mouse button and the screen shot will be saved as a PNG file on your desktop. (The file is saved as PDF in Mac OS 10.3 and earlier.)
  5. Add Control to the two shortcuts above to place the screen shot on the clipboard instead of saving it to the desktop.
  6. Another method for capturing screen shots in Mac OS X is by using the bundled Apple utility, Grab, located in the Applications > Utilities folder. Grab is useful if you need to include a cursor or a menu in your screen shot, or if you want to save your screen shot to TIFF format. To include a cursor, first go to Grab Preferences and select the cursor icon you wish to have in your screen shot. To capture the screen with Grab, run Grab, then choose of the capture modes from the "Capture" menu: Selection, Window, Screen, Timed Screen.
  7. When you choose the Selection mode in Grab, you can capture a specific region of the screen by dragging around it. Grab will display a tooltip showing the size of the region you have selected and the screen shot will open in a window when you release the mouse button. The cursor will not be included.
  8. When you choose the Window mode in Grab, an instruction window will appear asking you to select the window you wish to capture, then click the "Choose Window" button. When you click the button, the instructions will disappear and the window you click ill be captured, including the mouse cursor at the position where you click (if a cursor was selected in Preferences).
  9. When you choose the Screen mode in Grab, an instruction window will appear asking you to click the screen when you are ready to capture. The mouse cursor will be included in your screen shot at the position where you click (if a cursor was selected in Preferences).
  10. When you choose the Timed Screen mode in Grab, an instruction window will appear, allowing you to prepare your screen for capture. When you are ready, press the "Start Timer" button and you will have ten seconds before the screen is captured. This allows you to open menus and sub-menus, if necessary. After ten seconds the entire screen will be captured. The mouse cursor will be included in your screen shot if a cursor was selected in Preferences.



REFERENCES
http://graphicssoft.about.com/od/screencapturemac/ht/macscreenshot.htm

Wednesday, September 12, 2012

Symptoms of duplex mismatches

SkyHi @ Wednesday, September 12, 2012

In Ethernet, a duplex mismatch is a condition where two connected devices operate in different duplex modes, that is, one operates in half duplex while the other one operates in full duplex. The effect of a duplex mismatch is a network that works but is often much slower than its nominal speed. Duplex mismatch may derive from manually setting two connected network interfaces at different duplex modes, but also derives from connecting a device that performs autonegotiation to one that is manually set to a full duplex mode.

Communication is possible over a connection in spite of a duplex mismatch. Single packets are sent and acknowledged without problems. As a result, a simple ping command fails to highlight a duplex mismatch because single packets and their resulting acknowledgments at 1-second intervals do not cause any problem on the network. A terminal session which sends data slowly (in very short bursts) can also communicate successfully. However, as soon as either end of the connection attempts to send any significant amount of data, the network suddenly slows to very low speed. Since the network is otherwise working, the cause is not so readily apparent.

A duplex mismatch causes problems when both ends of the connection attempts to transfer data at the same time. This happens even if the channel is used (from a high-level or user's perspective) in one direction only, in case of large data transfers. Indeed, when a large data transfer is sent over a TCP, data is sent in multiple packets, some of which will trigger an acknowledgment packet back to the sender. This results in packets being sent in both directions at the same time.

In such conditions, the full-duplex end of the connection sends its packets while receiving other packets; this is exactly the point of a full-duplex connection. Meanwhile, the half-duplex end cannot accept the incoming data while it is sending -- it will sense it as a collision. As a result, almost all of the packets sent by the full-duplex end will be lost because the half-duplex end is streaming either data packet or acknowledgments at the time.

The lost packets force the TCP protocol to perform error recovery, but the initial (streamlined) recovery attempts fail because the retransmitted packets are lost in exactly the same way as the original packets. Eventually, the TCP transmission window becomes full and the TCP protocol refuses to transmit any further data until the previously-transmitted data is acknowledged. This, in turn, will quiesce the new traffic over the connection, leaving only the retransmissions and acknowledgments. Since the retransmission timer grows progressively longer between attempts, eventually a retransmission will occur when there is no reverse traffic on the connection, and the acknowledgment are finally received. This will restart the TCP traffic, which in turn immediately causes lost packets as streaming resumes.

The end result is a connection that is working but performs extremely poorly because of the duplex mismatch.



Netgear FS728TS setting:
-Full duplex and MDIX
-Manually set cisco to full duplex

REFERENCES