Tuesday, November 5, 2013
Monday, October 28, 2013
Wednesday, July 31, 2013
Acl (Access Control List)
Acl (Access Control List)
Files and directories have permission sets for the
owner of the file, the group associated with the file, and all other users for
the system. However, these permission sets have limitations. For example,
different permissions cannot be configured for different users. Thus, Access Control Lists (ACLs) were implemented.
The Red Hat Enterprise Linux kernel provides ACL
support for the ext3 file system and NFS-exported file systems. ACLs are also
recognized on ext3 file systems accessed via Samba.
Along with support in the kernel, the
acl
package
is required to implement ACLs. It contains the utilities used to add, modify,
remove, and retrieve ACL information.
The
cp
and mv
commands copy or move any ACLs
associated with files and directories.
Mounting
File Systems
Before using ACLs for a file or directory, the
partition for the file or directory must be mounted with ACL support. If it is
a local ext3 file system, it can mounted with the following command:
mount -t ext3 -o acl device-name partition
For example:
mount -t ext3 -o acl /dev/VolGroup00/LogVol02
/work
Alternatively, if the partition is listed in the
/etc/fstab file, the entry for the partition can include the acl option:
#
vi /etc/fstab
LABEL=/ / ext3 defaults,acl 1 1
:wq
(save and exit)
#
mount -o remount,rw /
#
mkdir work
#
cd work
#
cat >aclwork.txt
Ctrl
+ D
Login
with other user and open the file.
#
getfacl /root/work/aclwork.txt (Command
will show the permission on the file.)
#
setfacl -m u:user1:r-x /root/work/aclwork.txt (Will set the permission on the
file.)
#
getfacl /root/work/aclwork.txt
Login
with user1 and try to open the file.
#
setfacl -x u:user1 /root/work/aclwork.txt
(command will remove the acl permission from the file).
How to Use the vi Editor
How to Use the vi Editor
The vi editor is available on almost all Linux/Unix
systems. vi can be used from any type of terminal because it does not depend on
arrow keys and function keys--it uses the standard alphabetic keys for
commands.
vi is short form for visual editor. It displays a window into the file being edited that
shows 24 lines of text. vi is a text editor, not a "what you see is what
you get" word processor. vi lets you add, change, and delete text, but
does not provide such formatting capabilities as centering lines or indenting
paragraphs.
This explains the basics of vi:
- opening and closing a
file
- moving around in a file
- elementary editing
You may use vi to open an already existing file by
typing
vi filename
where "filename" is the name of the
existing file. If the file is not in your current directory, you must use the
full pathname.
Or you may create a new file by typing
vi newname
where "newname" is the name you wish to
give the new file.
To open a new file called "test,"
enter
vi test
On-screen, you will see blank lines, each with a
tilde (~) at the left, and a line at the bottom giving the name and status of
the new file:
~
"test" [New file]
vi Modes
vi has two modes:
- command mode
- insert mode
In command mode, the letters of the keyboard
perform editing functions (like moving the cursor, deleting text, etc.). To
enter command mode, press the escape key.
In insert mode, the letters you type form words
and sentences. Unlike many word processors, vi starts up in command mode.
Entering Text
In order to begin entering text in this empty
file, you must change from command mode to insert mode. To do this, type
i
Nothing appears to change, but you are now in
insert mode and can begin typing text. In general, vi's commands do not display
on the screen and do not require the Return key to be pressed.
Type a few short lines and press at
the end of each line. If you type a long line, you will notice the vi does not
word wrap, it merely breaks the line unceremoniously at the edge of the screen.
Moving the Cursor
To move the cursor to another position, you must
be in command mode. If you have just finished typing text, you are still in
insert mode. Go back to command mode by pressing . If you are not
sure which mode you are in, press once or twice until you hear a
beep. When you hear the beep, you are in command mode.
The cursor is controlled with four keys: h, j, k,
l.
Key Cursor Movement
--- ---------------
h left one space
j down one line
k up one line
l right one space
When you have gone as far as possible in one
direction, the cursor stops moving and you hear a beep. For example, you cannot
use l to move right and wrap around to the next line, you must use j to move
down a line. See the section entitled "Moving Around in a File" for
ways to move more quickly through a file.
Basic Editing
Editing commands require that you be command mode.
Many of the editing commands have a different function depending on whether
they are typed as upper- or lowercase. Often, editing commands can be preceded
by a number to indicate a repetition of the command.
Deleting Characters
To delete a character from a file, move the cursor
until it is on the incorrect letter, then type
x
The character under the cursor disappears. To
remove four characters (the one under the cursor and the next three) type
4x
To delete the character before the cursor, type
X (uppercase)
Deleting Words
To delete a word, move the cursor to the first
letter of the word, and type
dw
This command deletes the word and the space
following it.
To delete three words type
3dw
Deleting Lines
To delete a whole line, type
dd
The cursor does not have to be at the beginning of
the line. Typing dd deletes the entire line containing the cursor and places
the cursor at the start of the next line. To delete two lines, type
2dd
To delete from the cursor position to the end of
the line, type
D (uppercase)
Replacing Characters
To replace one character with another:
- Move the cursor to the
character to be replaced.
- Type r
- Type the replacement
character.
Replacing Words
To replace one word with another, move to the
start of the incorrect word and type
cw
The last letter of the word to be replaced will
turn into a $. You are now in insert mode and may type the replacement. The new
text does not need to be the same length as the original. Press to
get back to command mode. To replace three words, type
3cw
Replacing Lines
To change text from the cursor position to the end
of the line:
- Type C (uppercase).
- Type the replacement
text.
- Press
.
Inserting Text
To insert text in a line:
- Position the cursor
where the new text should go.
- Type i
- Enter the new text.
The text is inserted BEFORE the cursor.
Appending Text
To add text to the end of a line:
- Position the cursor on
the last letter of the line.
- Type a
- Enter the new text.
This adds text AFTER the cursor.
Opening a Blank
Line
To insert a blank line below the current line,
type
- (lowercase)
To insert a blank line above the current line,
type
O (uppercase)
Joining Lines
To join two lines together:
- Put the cursor on the
first line to be joined.
- Type J
To join three lines together:
- Put the cursor on the
first line to be joined.
- Type 3J
Undoing
To undo your most recent edit, type
u
To undo all the edits on a single line, type
U (uppercase)
Undoing all edits on a single line only works as
long as the cursor stays on that line. Once you move the cursor off a line, you
cannot use U to restore the line.
Moving Around in a
File
There are shortcuts to move more quickly though a
file. All these work in command mode.
Key Movement
--- --------
w forward word by word
b backward word by word
$ to end of line
0 (zero) to beginning of line
H to top line of screen
M to middle line of screen
L to last line of screen
G to last line of file
1G to first line of file
f scroll forward one screen
b scroll backward one screen
d scroll down one-half screen
u scroll up one-half screen
Moving by Searching
To move quickly by searching for text, while in
command mode:
- Type / (slash).
- Enter the text to
search for.
- Press
.
The cursor moves to the first occurrence of that
text.
To repeat the search in a forward direction, type
n
To repeat the search in a backward direction, type
N
Closing and Saving a File
With vi, you edit a copy of the file, rather than
the original file. Changes are made to the original only when you save your
edits.
To save the file and quit vi, type
ZZ
The vi editor editor is built on an earler Unix
text editor called ex. ex commands can be used within vi. ex commands begin
with a : (colon) and end with a . The command is displayed on the
status line as you type. Some ex commands are useful when saving and closing
files.
To save the edits you have made, but leave vi
running and your file open:
- Press
. - Type :w
- Press
.
To quit vi, and discard any changes your have made
since last saving:
- Press
. - Type :q!
- Press
.
Command Summary
STARTING vi
vi filename edit a file named "filename"
vi newfile create a new file named "newfile"
ENTERING TEXT
i insert text left of cursor
a append text right of cursor
MOVING THE CURSOR
h left one space
j down one line
k up one line
l right one space
BASIC EDITING
x delete character
nx delete n characters
X delete character before cursor
dw delete word
ndw delete n words
dd delete line
ndd delete n lines
D delete characters from cursor to end of line
r replace character under cursor
cw replace a word
ncw replace n words
C change text from cursor to end of line
o insert blank line below cursor
(ready for insertion)
O insert blank line above cursor
(ready for insertion)
J join succeeding line to current cursor line
nJ join n succeeding lines to current cursor line
u undo last change
U restore current line
MOVING AROUND IN A FILE
w forward word by word
b backward word by word
$ to end of line
0 (zero) to beginning of line
H to top line of screen
M to middle line of screen
L to last line of screen
G to last line of file
1G to first line of file
f scroll forward one screen
b scroll backward one screen
d scroll down one-half screen
u scroll up one-half screen
n repeat last search in same direction
N repeat last search in opposite direction
CLOSING AND SAVING A FILE
ZZ save file and then quit
:w save file
:q! discard changes and quit file
Tuesday, July 30, 2013
LVM (Logical Volume Manager)
LVM
(Logical Volume Manager)
LVM
is a tool for logical volume management which includes allocating disks,
striping, mirroring and resizing logical volumes. With LVM, a hard drive or set
of hard drives is allocated to one or more physical
volumes.
LVM physical volumes can be placed on other block devices which might span two
or more disks.
The
physical volumes are combined into logical
volumes,
with the exception of the /boot/ partition.
The/boot/ partition cannot be on a logical volume group because the boot
loader cannot read it. If the root (/)
partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.
Since
a physical volume cannot span over multiple drives, to span over more than one
drive, create one or more physical volumes per drive.
The
volume groups can be divided into logical
volumes,
which are assigned mount points, such as /homeand / and
file system types, such as ext2 or ext3. When "partitions" reach
their full capacity, free space from the volume group can be added to the
logical volume to increase the size of the partition. When a new hard drive is
added to the system, it can be added to the volume group, and partitions that
are logical volumes can be increased in size.
On
the other hand, if a system is partitioned with the ext3 file system, the hard
drive is divided into partitions of defined sizes. If a partition becomes full,
it is not easy to expand the size of the partition. Even if the partition is
moved to another hard drive, the original hard drive space has to be
reallocated as a different partition or not used.
Create 3 partitions for implementing RAID
using fdisk command.
e.g. #fdisk /dev/sda
Press n to create the 3 new partitions each
of 100Mb in size.
Press p to see the partition table.
Press t to change the partition id of all the
three partitions created by you to 8e (Linux LVM).
Press wq to save and exit from fdisk utility
in linux.
Use fdisk -l to list the partition table.
Creating
LVM
# pvcreate /dev/sda6 /dev/sda7 /dev/sda8
# pvdisplay
#vgcreate vg /dev/sda6 /dev/sda7 /dev/sda8
#vgdisplay vg
#lvcreate -L +10M -n data vg
-L is used to define size.
-n is used to define the name.
#mkfs.ext3 /dev/vg/data
#lvdisplay /dev/vg/data
#mkdir disk
#mount /dev/vg/data disk
#df -h disk
#lvextend -L +10M /dev/vg/data
#ext2online /dev/vg/data
#df -h disk
#umount disk
#vgchange -an vg (optional) -a control the avability of the
logical volume in the volume group for input and output.
#lvremove /dev/vg/data
Press y to continue
#lvdisplay
#vgremove /dev/vg
#vgdisplay
#pvremove /dev/sda6 /dev/sda7 /dev/sda8
#pvdisplay
Linux Tutorials
RAID (Redundant
Array of Inexpensive Disks)
configuring RAID
Create
3 partitions for implementing RAID using fdisk command.
e.g.
#fdisk /dev/sda
Press
n to create the 3 new partitions each of 100Mb in size.
Press
p to see the partition table.
Press
t to change the partition id of all the three partitions created by you to fd
(linux raid auto).
Press
wq to save and exit from fdisk utility in linux.
#partprobe
Use
fdisk -l to list the partition table.
Creating RAID
#
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda6 /dev/sda7
/dev/sda8
Press
y to create the arrays.
To see the details of raid use the following
command: -
#
cat /proc/mdstat
#
mdadm --detail /dev/md0
Creating the file system for your RAID devices
#mkfs.ext3
/dev/md0
Mounting the RAID partition
#mkdir
data
#
mount /dev/md0 data
#df
-h /root/data (Command is used to see the space allocation).
Crashing the raid devices
#
mdadm --manage /dev/md0 --fail /dev/sda8
Removing raid devices
#
mdadm --manage /dev/md0 --remove /dev/sda8
Adding raid devices
#
mdadm --manage /dev/md0 --add /dev/sda8
View failed and working raid devices
#
cat /proc/mdstat
#
mdadm --detail /dev/md0
#
tail /var/log/messages
To remove the RAID follow these steps: -
1)
unmount the mounted directory where raid is mounted.
e.g.
umount data
2)
Stop the device
e.g.
mdadm --stop /dev/md0
3) View the details of your raid level using
following command: -
#cat
/proc/mdstat
#mdadm
--detail /dev/md0
Subscribe to:
Posts (Atom)