วันจันทร์ที่ 30 สิงหาคม พ.ศ. 2553

mtime, ctime, and atime timestamp Linux

Recently, I've implemented a caching system. This involve removing old file from the cache. One important factor for making a decision is a file timestamp. There are many timestamp implemented in the file system here are method for viewing timestamp info.

mtime, ctime, and atime

atime - access time
mtime - if modify time
ctime - of change time

To view atime

ls -lu

To view ctime

ls -lc

To view mtime

ls -lt

Access time is when last time data from the file was access.

Modify time is when last change was done to the file.

Change time id when you change owner.

Or

Use stat command

stat filename

stat newname2.txt
File: `newname2.txt'
Size: 13 Blocks: 8 IO Block: 4096 regular file
Device: 805h/2053d Inode: 2338058 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-01-28 16:01:10.000000000 +0700
Modify: 2011-01-28 16:02:35.000000000 +0700
Change: 2011-01-28 16:06:26.000000000 +0700

to verify with ls command
--
References :

วันพุธที่ 4 สิงหาคม พ.ศ. 2553

Gentoo migration to raid

At some point, high availability become more essential to your server. Raid1(mirror) can help server to be able to continue even the disk go wrong. This blog is intend to be a complete just-type-guide for system admin. I hope that you guy succeeded in this migration

Background my system is gentoo on sda. The new disk will be sdb. After finishing copying data to sdb. The another new disk will be replace as sda. sda and sdb will be raid1 mirroring each other.

#0 move running service to another system
- make sure that the system can be down for maintainance


#1 shutdown system
shutdown -h now

#2 install new hdd as sdb
some vendor disable port B (for sdb) please make sure that it is enable so it can be visible from linux.

#3 boot system with live cd
modprobe raid1

#4 format disk and create raid on sdb
available 500GB
-> sdb1 boot 1GB ext2
-> sdb5 root entire ext3
-> sdb6 swap 4GB swap
cfdisk /dev/sdb
cd /dev && MAKEDEV md
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md5 --level=1 --raid-devices=2 missing /dev/sdb5
mke2fs /dev/md1
mke2fs -j /dev/md5
mkswap /dev/sdb6
swapon /dev/sdb6


#5 copy data from sda to raid
mkdir /mnt/gentoo1
mount /dev/sda5 /mnt/gentoo1
mount /dev/md5 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo1/boot
mkdir /mnt/gentoo/boot
mount /dev/md1 /mnt/gentoo/boot
cp -dpRx /mnt/gentoo1/* /mnt/gentoo/


#6 install boot loader to raid
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1=”(chroot) $PS1”
#Edit grub.conf change root=/dev/sdaxx to mdxx
nano /boot/grub/grub.conf
#install boot loader to the disk
grub –no-floppy
- device (hd0) /dev/sdb
- root (hd0,0)
- setup (hd0)

#7 edit fstab to mount disk on raid instead // or just copy from preedit @ /home/username/fstab
nano /etc/fstab

#8 shutdown & replace sda with new disk
exit
cd /
umount /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo/dev /mnt/gentoo
umount /mnt/gentoo1/boot /mnt/gentoo1
shutdown -h now
-replace new disk


#9 sync disk and install boot loader
-change bios priority to start boot from sdb
sfdisk -d /dev/sdb | sfdisk /dev/sda
mdadm --add /dev/md1 /dev/sda1
mdadm --add /dev/md5 /dev/sda5
#edit fstab add sda as swap
nano /etc/fstab
mkswap /dev/sda6
swapon /dev/sda6
grub –no-floppy
- device (hd0) /dev/sda
- root (hd0,0)
- setup (hd0)


#wait until sync finish
- reboot test
- restore bios boot priority
- restore sevice back to the server.