Showing posts with label lvm. Show all posts
Showing posts with label lvm. Show all posts

 How to resize VM partition on Vmware 

                                          by Jephe Wu - http://linuxtechres.blogspot.com

Extend a LVM partition

  1. from Vcenter, to edit configure, to add a new hard disk with required size
  2.   echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)
  3. dmesg and cat /proc/partition to confirm new disk is added.

      4. fdisk /dev/sdb to create a new partition and use t  to change it to 8e LVM

      5 . pvcreate /dev/sdb1

     6. vgextend vg_root /dev/sdb1

     7. lvextend -l +100%FREE /dev/vg_root/lv_root

or  8. lvextend -L +20G /dev/vg_root/lv_root (if only increase 20G)

     9.  resize2fs /dev/mapper/vg_root-lv_root 

or xfs_growfs mountpoint (if it's xfs partition)


Modify existing sdb LVM PV disk size and use it in vg

1. echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)

or

echo 1 > /sys/block/sdb/device/rescan

 

2.  use pvscan or  fdisk -l | grep -i sdb to confirm new disk size

3. blockdev --rereadpt /dev/sdb  to resize LVM volume size

4. pvresize /dev/sdb  to resize PV


Resize Procedure for /dev/sdb1 PV

https://access.redhat.com/solutions/57183

1. Confirm the actual storage size with fdisk -ul /dev/sdb. Observe the increased disk size. Depending on how the storage is presented, a system reboot may be necessary for this to appear.

2. Resize the partition on the disk. To achieve this, observe the starting sector in fdisk -ul /dev/sdb, then remove the partition with fdisk and re-create it with the same starting sector but the (default) last sector of the drive as the ending sector. Then write the partition table and confirm the change (and the correct starting sector) with fdisk -ul /dev/sdb.

3. Run pvresize /dev/sdb1 to grow (resize) the PV onto the rest of the expanded partition. This will create free extents within the Volume Group which then can be used to grow a Logical Volume. Running lvresize command with -r as lvresize -r will grow the filesystem within the Logical Volume as well.

Another solution would be creating a new partition under the same device starting where the first partition ended and using the rest of the cylinders to create the same, then put this new partition under LVM with the pvcreate command, extend the current VG (vgextend vg-name pv-name), then extend the current LV (lvextend) and finally resize the current filesystem (resize2fs).


Create a new LVM partition with new disk

pvcreate /dev/sdx1 

vgcreate vg01 /dev/sdx1

lvcreate -l +100%FREE -n apps vg01
mkfs -t xfs /dev/mapper/vg01_apps


For rollback

1) Unmount the mountpoint

umount -v /var/www

2) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

3) Reduce the logical volume

lvreduce --resize2fs -L -100G (-l 5119)  /dev/vg-repo/lv-repo

Note: use vgdisplay to record down existing used logic extent number, it's 5119 in this case before increase

4) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

5) Mount the filesystem back to the same mountpoint

mount /dev/vg-repo/lv-repo /var/www

6) Reduce the VG in order to release the PV /dev/sde1

vgreduce vg-repo /dev/sde1

7) Remove the PV

pvremove /dev/sde1

8) Remove the new created disk from vcenter in the backup plan?


How to add LUN disk online under CentOS 6.2



Jephe Wu - http://linuxtechres.blogspot.com.au

Environment: CentOS 6.2 64bit with multipath connected to HP EVA storage, the LUN disk was LVM disk
Objective: add a new LUN disk for server online and add into the existing LVM to make the partition size bigger
scenario: LVM add new lun disk, increase the existing lvm lun disk, increase the existing partition disk such as /dev/sda1


Steps:


1. add a new LUN disk in EVA storage and present it properly to the server
2. use commands below to rescan scsi hosts

 echo "- - -" > /sys/class/scsi_host/host0/scan   
 echo "- - -" > /sys/class/scsi_host/host1/scan 
 echo "- - -" > /sys/class/scsi_host/host2/scan 

you can find out how many scsi disks you have by running "ls /sys/class/scsi_host", or just run above commands for all hosts under /sys/class/scsi_host

2.1 if you increased the existing LUN disk size, please refer to http://serverfault.com/questions/66638/how-to-extend-a-san-based-vdisk-in-red-hat-without-rebooting as follows:
or refer to http://www.datadisk.co.uk/html_docs/redhat/rh_multipathing.htm  Resize online multpath LUN part  and Multipathing and DR part


resize SAN disk / physical device first.

# rescan disk size
multipath -ll # list all disks, for all disk, run
echo 1 > /sys/block/sdX/device/rescan
#run for all sdX under /sys/block

[#optional, then you can test multipath failover by running]
multipathd -k
del path sdx 
add path sdx


# resize mapname
note: refer to http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/pdf/DM_Multipath/Red_Hat_Enterprise_Linux-6-DM_Multipath-en-US.pdf page 21 - Resizing an Online Multipath Device
multipathd -k
resize map multipath-map-name # this might be optional too, according to
http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?lang=en&cc=us&taskId=120&prodSeriesId=3559651&prodTypeId=18964&objectID=c02000699

multipath # run this command to make multipath pickup the new size according to above hp bizsupport

use multipath -ll to verify the new size, then
pvresize,lvextend and resize2fs to expand the disk to new size.


References:
1. Moving root File Systems from a Single Path Device to a Multipath Device - http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/pdf/DM_Multipath/Red_Hat_Enterprise_Linux-6-DM_Multipath-en-US.pdf page 32.
2. Moving swap File Systems from a Single Path Device to a Multipath Device
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/pdf/DM_Multipath/Red_Hat_Enterprise_Linux-6-DM_Multipath-en-US.pdf page 34

3. verify wwid for new lun disk ndb01-b  - optonal
[root@db01 sys]# multipath -ll
mpatha (3600508b1001030363946364434300999) dm-0 HP,LOGICAL VOLUME
size=137G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  `- 2:0:0:0 sda 8:0    active ready running
ndb01 (3600143800648a76c0000b00037b10777) dm-5 HP,HSV300
size=200G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 1:0:0:2 sdc 8:32   active ready running
  |- 1:0:1:2 sdf 8:80   active ready running
  |- 0:0:0:2 sdi 8:128  active ready running
  `- 0:0:1:2 sdl 8:176  active ready running
ndb01-b (3600143800648a76c0000b001566f0888) dm-11 HP,HSV300
size=200G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 0:0:0:4 sdn 8:208  active ready running
  |- 0:0:1:4 sdq 65:0   active ready running
  |- 1:0:0:4 sdt 65:48  active ready running
  `- 1:0:1:4 sdw 65:96  active ready running\

you can get a lun disk wwid by running:
/lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/sdw
3600143800648a76c0000b001566f0888

verify fiber channel adapter port wwn matches between server and storage 


[root@db01 zabbix]# more /sys/class/fc_host/host0/node_name 
0x20000000c9928eb1
[root@db01 zabbix]# more /sys/class/fc_host/host1/node_name 
0x20000000c9928eb2

then check EVA storage Hosts - port tab part to confirm



4. modify /etc/multipath.conf to add new wwid for new LUN disk
vi /etc/multipath.conf
multipaths {
        multipath {
                wwid 3600143800648a76c0000b00037b50005
                alias db01
        }
        multipath {
                wwid 3600143800648a76c0000b001566f0888
                alias db01-b
        }
}

fdisk -l | grep sd # check the last disk detected by os
ls /dev/mapper -l # check the existing lun disks
chkconfig multipathd on
/etc/init.d/multipathd start # make sur start it
/etc/init.d/multipathd reload
go to /dev/mapper to run ls -l to verify newly add LUN disks
fdisk -l | grep sd #confirm new disks have been detected.

5. resize pv and file system
pvcreate /dev/mapper/ndb01-b
or
pvresize /dev/mapper/ndb01 # if you increase the existing lun disk

vgextend VgGroup1 /dev/mapper/ndb01-b
lvextend -L +150G /dev/VolGroup01/ndb01-mysql1
resize2fs /dev/VolGroup01/ndb01-mysql1
df -h

6. what if it's a single lun disk in OS - /dev/sda
lun admin to resize disk
echo "- - -" > /sys/block/sda/device/rescan
fdisk /dev/sda #remove then readd a partition that is the new disk size
partprobe # to update /proc/partitions
pvdisplay
pvresize /dev/sda1 or pvresize /dev/sda # grow pv
vgdisplay
lvextend
e2fsck -fy /dev/VolGroup1/LogVol1 # optional
resize2fs /dev/VolGroup1/LogVol1

or, instead of growing pv, you can use the new added partiton size to create another pv
fdisk /dev/sda # to add a new partition, not to delete/create
partprobe
pvcreate /dev/sda2
vgextend, lvextend, resize2fs etc


7. References:
a. Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest - http://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-guest.html

b. Multi-path Device Mapper for Linux Software - How to Resize an EVA LUN on RedHat 4.8 and Later -
http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?lang=en&cc=us&taskId=120&prodSeriesId=3559651&prodTypeId=18964&objectID=c02000699

c. HP business support center - http://www.hp.com/bizsupport/
d. search redhat customer portal for article - How to extend filesystem built on LVM SAN disks on RHEL5
e. HP EVA storage default port 2372 with https

How to make mysql slave db to sync with master again

Jephe Wu - http://linuxtechres.blogspot.com

Environment: mysql 5.5, CentOS 5.6 64bit for both master(192.168.0.1) and slave(192.168.0.2)
Objective: to make slave db to sync with master again

You can use manual method as stated on http://mysql-mmm.org/mmm2:guide for configuring mysql replication.


Steps:

1. [slave] stop slave mysql database
/etc/init.d/mysql stop
rm -fr /srv/mysql/data /srv/mysql/log


2. [master]
use mylvmbackup(http://www.lenzg.net/mylvmbackup/) to create snapshot for LVM volume where mysql db data and log file resides.
modify /etc/mylvmbackup.conf to keep_snapshot=1 and keep_mount=1

# copy mounted snapshot data and log files to slave database
scp -pr /snap/backup/data /snap/log slavedb:/srv/mysql/

# record down the master log file and position
root@db02:/srv/mysql-db2-snap/backup-pos/ # more backup-20111129_110147_mysql.pos
Master:File=mysql-bin.000046
Master:Position=25449360

Note: log folder on master database is not useful if there's no slave database which will use it, you can rm -fr log/* after shutting down master database, then make code backup for data folder only.

3. [slave]
cd /srv/mysql
chown mysql:mysql -R data log
/etc/init.d/mysql start
mysql -uroot -ppassword
mysql> show slave status\G

mysql> stop slave;
mysql> change master to MASTER_HOST='192.168.0.1', MASTER_USER='slave1_user', MASTER_PASSWORD='slave1_password', MASTER_LOG_FILE='mysql-bin.000046', MASTER_LOG_POS=25449360;

or after checking 'show slave status\G', the master host is correct, you can just use:
mysql> change master to master_log_file='mysql-bin.000046', MASTER_LOG_POS=25449360;

mysql> start slave;
mysql> show slave status;  make sure it shows:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

monitoring  Seconds_Behind_Master: 7770 column to make sure it's reducing until 0 which means it finishs syncing with master again.

4. [slave] make master to sync with slave too
on slavedb, run
mysql> show master status\G;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000055 | 17584079 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

5. [master] make it sync with slave
mysql> stop slave;
if not, maybe
mysql> reset slave;
mysql> change master to master_log_file='mysql-bin.000055', MASTER_LOG_POS=17584079;
mysql> start slave;
mysql> show slave status\G

note: you have to run 'show master status' first on slavedb, then record down master_log_file and master_log_pos, then use it on master db to make it sync with slave also.

6. [master] use pt-table-checksum to compare 2 databases
show tables status;
create database pt;
pt-table-checksum -uroot -ppassword  --create-replicate --replicate pt.checksums --databases zabbix --empty-replicate-table --chunk-size=5000 localhost

pt-table-checksum -uroot -ppassword  --create-replicate --replicate pt.checksums --databases zabbix --empty-replicate-table --chunk-size=5000 localhost --replicate-check=1

echo $?
0
----------------------------
or skip some huge tables
----------------------
pt-table-checksum -uroot -ppassword  --create-replicate --replicate pt.checksums --databases zabbix --empty-replicate-table --chunk-size=30000 --chunk-size-limit 50  localhost  --ignore-tables events,history,history_uint,trends,trends_uint --replicate-check 1

note:use phpmyadmin or show table status to get rough size of tables which might be skipped for pt-table-checksum.
 --------------------------
If it's different between master and slaves, it will show by paramter --replicate-check 1

pt-table-checksum -uroot -ppassword  --create-replicate --replicate pt.checksums --databases mysql --empty-replicate-table --chunk-size=30000 --chunk-size-limit 50  localhost --replicate-check 1
Differences on P=3306,h=db03
DB    TBL           CHUNK CNT_DIFF CRC_DIFF BOUNDARIES
mysql db                0        1        1 1=1
mysql help_keyword      0       -1        1 1=1
mysql help_relation     0        1        1 1=1
mysql help_topic        0        1        1 1=1
mysql proc              0        0        1 1=1

echo $?
1
------------------
You can make mysql database itself sync between master and slaves by the following method:

on master:
mysqldump --add-drop-table mysql -uroot -ppassword | ssh db03 'mysql -uroot -ppassword mysql'

mysql -uroot -ppassword -h db03
sql> flush privileges;

FAQ:
root@db02:/etc/cron.d/ # pt-table-checksum -uroot -ppassword  --create-replicate --replicate pt.checksums --databases zabbix --empty-replicate-table --chunk-size=5000 localhost
You do not have the PROCESS privilege at /usr/bin/pt-table-checksum line 3761.
root@db02:/etc/cron.d/ # mysql -uroot -ppassword -h slavedb zabbix
ERROR 1044 (42000): Access denied for user 'root'@'192.168.7.2' to database 'zabbix'

[root@db03 sysconfig]# mysql -uroot -ppassword
mysql> grant all on zabbix.* to root@'192.168.7.22' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>  exit

 try again.
or

The following method will definitely work when using pt-table-checksum:

mysql> grant all privileges on *.* to root@'172.17.7.22' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)



otherwise, you might encounter error like 'You do not have the PROCESS privilege at /usr/bin/pt-table-checksum line 3761.'


References:
1. how to completely delete snapshot logical volume
df -h
umount /mountpoint_for_snapshot_volume
lvdisplay -v
lvremove /dev/VolGroup02/snap02
cd /dev/mapper
dmsetup remove snap02
or
kpartx -d xxxxx


2. purge master log - http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html
This statement is safe to run while slaves are replicating. You need not stop them, it will Purge all log files up to but not including the target file.
example:
PURGE BINARY LOGS TO 'mysql-bin.010';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

You can also set the expire_logs_days system variable to expire binary log files automatically after a given number of days (see Section 5.1.3, 揝erver System Variables?. If you are using replication, you should set the variable no lower than the maximum number of days your slaves might lag behind the master.

mysql> show master logs;


#!/bin/bash
CURRENT_LOGFILE=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | awk '$1 == "Master_Log_File:" {print $2}')
/usr/bin/mysql -h MASTER -e "PURGE MASTER LOGS TO '${CURRENT_LOGFILE}'"
exit $?


note: cronjob script to purge master log on slave db:


3. master/slave /etc/my.cnf configuration:
 note: server_id must be different. If not, change it, restart mysqld service. 
sql> reset slave;
sql> change master to ....
sql> start slave;


slave:

root@db01:/srv/mysql/log/ # cat /etc/my.cnf | grep -v ^# | grep -v ^$
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
default-storage-engine=innodb
innodb_file_per_table
innodb_lock_wait_timeout = 150
innodb_rollback_on_timeout
innodb_buffer_pool_size=20000M
innodb_flush_method=O_DIRECT
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=4M
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED
log-queries-not-using-indexes
key_buffer_size = 64M
user            = mysql
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /srv/mysql/data
tmpdir          = /tmpfs
skip-external-locking
bind-address            = 0.0.0.0
key_buffer              = 128M
max_allowed_packet      = 128M
thread_stack            = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
max_connections=512
tmp_table_size=256M
max_heap_table_size=256M
table_cache=1024
thread_cache=16
read_buffer_size        = 2M
read_rnd_buffer_size    = 2M  
sort_buffer_size        = 2M   
thread_stack            = 256K
join_buffer_size        = 8M   
log-queries-not-using-indexes
thread_concurrency     = 32
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 16M
log_error                = /srv/mysql/log/error.log
log_slow_queries        = /srv/mysql/log/mysql-slow.log
long_query_time = 2
server_id=1
log_bin             = /srv/mysql/log/mysql-bin.log
log_bin_index       = /srv/mysql/log/mysql-bin.log.index
relay_log           = /srv/mysql/log/mysql-relay-bin
relay_log_index     = /srv/mysql/log/mysql-relay-bin.index
expire_logs_days    = 2
max_binlog_size     = 100M
log_slave_updates   = 1
binlog-format=MIXED
sync_binlog=1

[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]
[isamchk]
key_buffer              = 16M
------------------------------------
root@db02:/srv # cat /etc/my.cnf | grep -v ^# | grep -v ^$
[client]
port        = 3306
socket        = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket        = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
default-storage-engine=innodb
innodb_file_per_table
innodb_lock_wait_timeout = 150
innodb_rollback_on_timeout
innodb_buffer_pool_size=20000M
innodb_flush_method=O_DIRECT
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=4M
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED
log-queries-not-using-indexes
key_buffer_size = 64M
user        = mysql
socket        = /var/run/mysqld/mysqld.sock
port        = 3306
basedir        = /usr
datadir        = /srv/mysql/data
tmpdir        = /tmpfs
skip-external-locking
bind-address        = 0.0.0.0
key_buffer        = 128M
max_allowed_packet    = 128M
thread_stack        = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
max_connections=512
tmp_table_size=256M
max_heap_table_size=256M
table_cache=1024
thread_cache=16
read_buffer_size        = 2M
read_rnd_buffer_size    = 2M   
sort_buffer_size        = 2M  
thread_stack            = 256K 
join_buffer_size        = 8M  
log-queries-not-using-indexes
thread_concurrency     = 32
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 16M
log_error                = /srv/mysql/log/error.log
log_slow_queries    = /srv/mysql/log/mysql-slow.log
long_query_time = 2
server_id=2
log_bin             = /srv/mysql/log/mysql-bin.log
log_bin_index       = /srv/mysql/log/mysql-bin.log.index
relay_log           = /srv/mysql/log/mysql-relay-bin
relay_log_index     = /srv/mysql/log/mysql-relay-bin.index
expire_logs_days    = 2
max_binlog_size     = 100M
log_slave_updates   = 1
binlog-format=MIXED


#added by Jephe to ignore replication error, use all or comma separated error codes,such as 1507 for dropping non-existed partitions.
#slave-skip-errors=all

[mysqldump]
quick
quote-names
max_allowed_packet    = 16M

[mysql]
[isamchk]
key_buffer        = 16M

4. commands
a. grant pt.checksums table to my pc ip 192.168.0.100 with login id root and password as 'password'

mysql> grant all privileges on pt.* to root@'192.168.0.100' identified by 'password';
mysql> flush privileges;
mysql> show grants;


5. documents
http://www.howtoforge.com/mysql5_master_master_replication_debian_etch


6. References

http://dev.mysql.com/doc/refman/5.5/en/replication.html
http://mysql-mmm.org/mmm2:guide  - 2 masters/2 slaves mysql db and mmm2 setup guide 


7. how to ignore db for replication setup ( http://www.packtpub.com/article/install-manage-use-mmm-for-mysql-high-availability )
Now configure the mysqld section /etc/my.cnf on both nodes with the following steps:

  1. Prevent the server from modifying its data until told to do so by MMM. Note that this does not apply to users with SUPER privilege (that is, probably you at the command line!):
    read-only
  2. Prevent the server from modifying its mysql database as a result of a replicated query it receives as a slave:
    replicate-ignore-db = mysql
  3. Prevent this server from logging changes to its mysql database:
    binlog-ignore-db = mysql

Use RIP CD to fix the grub issue after RHEL 5 hard power shutdown

Jephe Wu -  http://linuxtechres.blogspot.com

Scenario: HP Proliant DL360G5 server running RHEL 5 and 32bit Oracle 11g database (11.1), after yum update and some Oracle impdp/expdp operations, the server hangs, we have to press power button to shut it down, after power it on again, the GRUB stops at 'loading grub stage 2'.

Steps:

1. use RIP(Rescue Is Possible - http://www.tux.org/pub/people/kent-robotti/looplinux/rip/) to reboot server.
2. re-generate grub
# vgdisplay -v
# lvdisplay -v (find out the root LVM partition name)
# vgchange -a y
# mount /dev/VolGroup00/LogVol00 /mnt/hd
# cd /mnt/hd; chroot .
# mount /dev/cciss/c0d0p0 boot
# cd /dev
# MAKEDEV cciss
# grub-install hd0


3. finishing job
# cd /mnt/hd
# umount boot
# exit
# umount /mnt/hd
# reboot



How to use LVM snapshot to clone CentOS 5 server

Jephe Wu - http://linuxtechres.blogspot.com

Environment: 36G IDE hard disk with CentOS 5.5 default installation which has /boot as /dev/hda1 and the rest are on LVM, this is server A.
Objective: to clone to another same kind of machine by using LVM snapshot. This is server B.
Tools used: RIP(Recovery Is Possible) CD V8.9, create LVM snapshot for / partition before using tar to copy to another machine.

Concept:
1. use RIP to boot up the destination machine
2. create partitions same as the original one and make file system for all partitions
3. use external hard disk or thumb drive on original machine to extend the volume group
4. create LVM snapshot logical volume on original machine before using tar to copy the whole file system
5. use tar on destinaion machine to copy over the whole file system from original machine
6. install grub on destiniation machine. reboot


Steps:
1.  use RIP to boot up the server B, choose skip the keyboard map.
2.  setting up the environment of RIP for network use
login as root without password
passwd root
ifconfig eth0 10.0.0.2 netmask 255.255.255.0 up
/usr/sbin/sshd


3.  copy over the partition configurations from server A (10.0.0.1/24)

ssh 10.0.0.1 'sfdisk -d /dev/hda' | sfdisk [--force] /dev/hda
or
use fdisk -ul /dev/hda on server A to get the sector layout, then configure it on server B

mkfs -t ext3 /dev/hda1
mkfs -t ext3 /dev/VolGroup00/LogVol00
mkswap /dev/VolGroup00/LogVol01
e2label /boot /dev/hda1


4. create snapshot on server A for intact tar backup over ssh.
4.1 extend the current volume group first
use external hard disk or thumb drive as the extra space for snapshot, as long as the thumb drive can hold the extra changes between the time you created snapshot and the time you finish then delete snapshot, thumb drive doesn't have to be same size as hard disk.

How LVM snapshot works?
As soon as you create a snapshot, LVM creates a pool of blocks. I believe that this pool also contains a full copy of the metadata of the volume. When writes happen to the main volume, the block being overwritten is copied to this new pool and the new block is written to the main volume. This is the 'copy-on-write'. Because of this, the more data that gets changed between when a snapshot was taken and the current state of the main volume, the more space will get consumed by that snapshot pool.

4.2 create snapshot (I used a 4G thumb drive as /dev/sda1)

vgextend VolGroup00 /dev/sda1
vgdisplay -v
lvcreate -n backup -l 126 VolGroup00
mkfs -t ext3 /dev/VolGroup00/backup
mkdir /backup
mount /dev/VolGroup00/backup /backup/
vcreate -l 126 -s -n rootsnapshot /dev/VolGroup00/LogVol00


4.3 to remove snapshot later, do:
umount /backup/
lvremove /dev/VolGroup00/backup
vgreduce VolGroup00 /dev/hda1

or
pvremove /dev/sda1
vgreduce --removemissing
vgreduce --removemissing VolGroup00


Note: If the physical volume is still used you will have to migrate the data to another physical volume using pvmove.

5.  copying the whole file system to server B
on server B:
mount /dev/VolGroup00/LogVol00 /mnt/hda2
mount /dev/hda1 /mnt/hda2/boot
scp 10.0.0.1:/etc/passwd /etc/
scp 10.0.0.1:/etc/group /etc/
ssh 10.0.0.1 'cd /backup; tar cvpf - .' | tar xvpf -


6. make grub
cd /mnt/hda2
chroot .
[MAKEDEV hda]
[vgchange -a y] to activate all LVM - optional
grub-install hd0


7. References:

http://www.howtoforge.com/linux_lvm_snapshots

How to expand array under Linux for HP Proliant server

Jephe Wu - http://linuxtechres.blogspot.com

Environment: HP Proliant DL360G6, CentOS 5.4 64bit, 6x300G hard disk with RAID5 (one for spare), hot added 2 more 300G hard disk, default disk partition layout by OS installation.
Objective: expand the existing RAID5 array with 2 more new added hard disk online

Steps:
1. Install HP Proliant support pack for RHEL 5

2. start up HP array configuration utility online for Linux
cd /opt/compaq/cpqacuxe/bld
./cpqacuxe -R
note: after finishing online configuration utility, you should stop it by running
./cpqacuxe -stop

3. expand array and logical drive

access https://log.domain.com:2381 then click on array configuration utility link
click on expand array, this will take long time to finish, after that, another button which is 'expand logical drive' will appear, come back to click on that also after finishing expanding array

4. make Linux kernel to recognize the new size of hardware raid5

reboot Linux server until the 'fdisk -l /dev/cciss/c0d0' shows the new size.
You can try 'partprobe' or 'sfdisk -R /dev/cciss/c0d0' first.

5. enlarge partition with fdisk

fdisk /dev/cciss/c0d0  (you might conside to use fdisk -u /dev/cciss/c0d0 to use sector instead of cyclinder)
p
press d then 2 to remove partition
press n then primary partition to use the full space
Make sure the old and new partition start at the same cylinder or sector position, otherwise, data will be destroyed.
press t to change partition type to LVM
w
q

note: you need to reboot again

6. resize physical volume size, logical volume size and file system online increase

after reboot, check again the new size

[root@log ~]# fdisk -l /dev/cciss/c0d0


Disk /dev/cciss/c0d0: 1799.7 GB, 1799797127168 bytes
255 heads, 63 sectors/track, 218812 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          13      104391   83  Linux
/dev/cciss/c0d0p2              14      218813  1757509959+  8e  Linux LVM


[root@log ~]# pvresize /dev/cciss/c0d0p2
  Physical volume "/dev/cciss/c0d0p2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
 
  note: use vgdisplay -v to check the number of free PE, let's say it's 17879.
 
[root@log ~]# lvextend -l +17879 /dev/VolGroup00/LogVol02

  Extending logical volume LogVol02 to 1.60 TB
  Logical volume LogVol02 successfully resized

[root@log ~]# resize2fs /dev/VolGroup00/LogVol02

resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol02 is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol02 to 430276608 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol02 is now 430276608 blocks long.

Clone HP Proliant DL360 G4p to HP Proliant DL360G6 with CentOS and LVM

Objective: clone HP Proliant DL360 G4p(S) to HP Proliant DL360G6(D)
Environment:

  • CentOS 5.4 64bit and Oracle 11g release 1 64bit were installed on HP Proliant DL360G4p(S) and HP Proliant DL360G6(D) is empty machine.
  • S has 2x160G hard disk as raid1 hardware mirroring, D has 4x300G hard disk as raid5.
  • CentOS on S has configured as LVM2.


Concepts:
1. refering to the article at http://linuxtechres.blogspot.com/2007/08/clone-linux-server-with-lvm2-partition.html
2. Since all HP Proliant storage controller uses Linux cciss driver, so we can clone them although the hard disk size is different.
3. after cloning, you can online resize the partition too since we are using LVM2

Steps:
1. since the hard disks are totally different in terms of type and size. So we cannot use sfdisk to clone partiton tables. We can manually configure partition table on D server, make the /boot as 100M and  the rest as the whole physical volume which is around 800G

bootup with RIP CD 9.3 non-X version in ILO, you can use local iso file in browser ILO, or you can refer to article http://linuxtechres.blogspot.com/2010/03/configure-virtual-media-through-vsp-and.html
boot up with 64bit kernel without keyboard map

fdisk /dev/cciss/c0d0
c0d0p1 as /boot as 100M (default type 83,Linux)
c0d0p2 as LVM partition type (8e)

2. refer to article http://linuxtechres.blogspot.com/2007/08/clone-linux-server-with-lvm2-partition.html

How to online resize LVM2 partitions size

Jephe Wu  - http://linuxtechres.blogspot.com

Environment: Fedora 3 or RHEL servers with LVM partitions
Objective: online increase partitions size including /, /usr, /var partitions


Steps:

1.  login as root, run 'vgdisplay' to find out the free PE extend and size

  Total PE              2039
  Alloc PE / Size       1745 / 54.53 GB
  Free  PE / Size       294 / 9.19 GB

2. run 'vgdisplay -v' to find out the logical volume LV name which you want to increase, let's say it's /dev/VolGroup00/LogVol06

3. increase the 5 Physical Extent(PE)
lvm lvresize -l +5 /dev/VolGroup00/LogVol06

4. use resize2fs(RHEL 4, 5) or ext2online(Fedora, starting from Fedora 6, this command is removed) to online increase partition file system size

ext2online /dev/VolGroup00/LogVol06 [newsize]
resize2fs  /dev/VolGroup00/LogVol06

Online reduce a /data/ partition and increase / partition
Objective: LVM partitions allocation is done, there's no free PE available already, need to reduce /data partition and increase / partition
Environment: CentOS 5.4, reduce /data from 100g to 50g, and increase / from 15g to 30g, still left 35g free for future
Steps:
umount /data
e2fsck -f /dev/VolGroup01/LogVol02
resize2fs /dev/VolGroup01/LogVol02 50G
lvreduce -L 50G /dev/VolGroup01/LogVol02
e2fsck -f /dev/VolGroup01/LogVol02

# online increase / partition from 15G to 30G and increase file system to make use of the full 30G space
lvresize -L 30G /dev/VolGroup01/LogVol00
resize2fs /dev/VolGroup01/LogVol00


vgdisplay -v

Use RIP Linux to shrink LVM root partition for default CentOS 5.3

Environment: default installation of CentOS 5.3 with a very bit /root LVM partition
Objective: reduce the root LVM partition to 20G file system size

Steps:

1. boot up with a RIP Linux CD
2. run command 'lvm -a y VolGroup00' to activate the volume group and logical volumes
3. resize2fs /dev/VolGroup00/LogVol00 20G
4. lvm lvresize --size 20G /dev/VolGroup00/LogVol00
note: to be very safe, you might want to resize logical volume to 21G instead of 20G, but according to the article from redhat access below, it's not required.
5. reboot



How do I reduce the size of the root file system after installation Red Hat Enterprise Linux 5?

I have attached above article from redhat below:

Release Found: Red Hat Enterprise Linux 5


The default file system layout from the Red Hat Enterprise Linux 5 installation process includes a special space for /boot and swap space then gives all left space to one logical volume and used the logical volume as root / volume.

Integrating all data files and system files in one file system is not always an ideal choice for production systems. If the system cannot be reinstalled, it is possible to reduce the size of the root file system and the logical volume on which it resides.

Reducing the logical volume on the root / volume must be done in rescue mode.

First, boot the system from Red Hat Enterprise Linux 5 Disc 1, and at the prompt, type linux rescue and press enter. When prompted for language, and keyboard, provide the pertinent information for the system. When prompted to enable the network devices on the system, select "No." Finally, select "Skip" when prompted to allow the rescue environment to mount Red Hat Enterprise Linux installation under the /mnt/sysimage directory. The filesystems MUST NOT be mounted to carry out the following steps.

Next run following commands to scan all disks LVM2 volume groups:

# lvm.static vgscan

Next, activate the logical volume to reduce. In this example, /dev/VolGroup00/LogVol00 was made available with the following command:


# lvm.static lvchange -ay /dev/VolGroup00/LogVol00

Next, reduce the size of file system and logical volume on /dev/VolGroup00/LogVol00. Please make sure there is enough space left on the root / file system and that the logical volume is large enough to contain all the data that was previously present. If the file system is at close to being full, for example, this may not work. Before resizing file system, run e2fsck to check file system first.


# e2fsck -f /dev/VolGroup00/LogVol00
# resize2fs /dev/VolGroup00/LogVol00 3000M
# lvm.static lvreduce -L 3000M /dev/VolGroup00/LogVol00

Please note that this is done on /dev/VolGroup00/LogVol00. The number at the end is the final size of the file system, not the amount it is reduced by.

Finally, verify the modification then reboot the system.


# lvm.static vgdisplay VolGroup00
# exit

WARNING: Resizing an active logical volume can cause catastrophic data loss if carried out incorrectly. Plan and act accordingly. ALWAYS create backups!

 References

http://www.redhat.com/magazine/009jul05/features/lvm2/ 

 How to remove a LVM partition forcely?

# kpartx -d xxxx 

Clone Linux server with LVM2 partition

Jephe Wu - http://linuxtechres.blogspot.com


You might want to clone your production Linux server to another, but the production server is having LVM2 partition which is enabled by default installation.


1. My test environment is as follows:

Source:
Dell Latitude C510
CentOS 5
IDE 30G HDD
/dev/hda1 mounted as /boot
/dev/VolGroup00/LogVol00 mounted as /
/dev/VolGroup00/LogVol01 is swap partition

Destination:
Acer TravelMate 603TER
IDE 20G HDD

2. Cloning concept
a. use RIP(Recovery Is Possible) CD to boot up Acer laptop
b. make /boot normal partition and LVM2 partition
c. create physical volume, volume group and logical volumes
d. mount logical volumes then clone all files over from the source
e. modify /boot/initrd image file if the destination VG and LV names are different from the source ones, it's recommended to use the same name so that this step can be ignored
f. modify /etc/fstab and /etc/sysconfig/network-scripts/ifcfg-ethX etc
g. done

3. Cloning steps
a. download RIP CD from http://www.tux.org/pub/people/kent-robotti/looplinux/rip/
download smaller non-X version which is about 37M since we don't need X window for cloning

b. boot up the Acer laptop using RIP cd, choose boot up option 2 to skip keyboard map

c. login as root without password

d. Set up the ip address for Acer
# ifconfig eth0 192.168.0.3 up (assuming the source server IP is 192.168.0.2 and they are on the same network)

e. Make partitions for Acer
If the both the source and destination hard disks are the same size, you can just use the following command to clone the partition table over.
# ssh 192.168.0.2 'sfdisk -d /dev/hda' | sfdisk /dev/hda

In my case, I have to do it manually since my Acer HDD is smaller. So I created /dev/hda1(type:83) and /dev/hda2 as LVM(type: 8e)

f. Create logical volumes and make file systems on Acer
# pvcreate /dev/hda2 (initialize it)
# vgcreate VolGroup00 /dev/hda2 (use the same volume group name as the source so that you don't have to modify /boot/initrd image file later)
# vgdisplay -v (to find out the total PE numbers and available space to create logical volumes)
# lvcreate -l 4617 -n LogVol00 VolGroup00 (to create / partition )
# lvcreate -l 128 -n LogVol01 VolGroup00 (for swap partition inside LVM)

note : you don't have to create the same number of extend for each logical volume, you can specify any value, this setting is not fixed somewhere in source server, so you can still be able to startup destination server later.

# mkfs -t ext3 /dev/VolGroup00/LogVol00
# mkswap /dev/VolGroup00/LogVol01
# mkfs -t ext3 /dev/hda1 (for /boot)
# e2label /dev/hda1 /boot (for labelling /boot partition, to be the same as the source which is indicated in /etc/fstab)


g. Cloning over everything from the source
cd /mnt
mkdir hd
mount /dev/VolGroup00/LogVol00 hd
cd hd
mkdir boot proc sys ( boot is a separated partition, and proc and sys are empty folder for kernel memory information)
mount /dev/hda1 boot
ssh 192.168.0.2 'cd /; tar --exclude ./proc --exclude ./sys -cpf - .'| tar xvpf -

h. Make necessary changes for Acer
cd /mnt/hd;chroot .

vi /etc/fstab(optional) (since you are using the same volume group and logical volume names, so you can ignore this step, otherwise, change the names to the new ones)

vi /etc/grub.conf (optional) (since your are using the same volume group and logical volume names, so you can ignore this step, otherwise, change the all root= line to the new logical volume path)

vi /etc/sysconfig/network-scripts/ifcfg-ethx (to change IP address and comment out hardware address line)

i. Install grub for Acer
cd /mnt/hd
chroot .
grub-install hd0
exit

change necessary configuration such as /etc/sysconfig/networking-scripts/ifcfg-eth0 mac address

j. Finishing up
cd /mnt/hd
umount boot
cd /
umount /mnt/hd
reboot

Note:

1. if you forgot to do something, you can always reboot the destination server with RIP CD again, the following are the steps:
login as root after RIP bootup
sh /etc/rc.d/rc.lvm2 start (to activate all volume groups)
(if not, use 'vgchange -a y' to activate all volume groups
cd /mnt
mount /dev/VolGroup00/LogVol00 hd
cd hd
mount /dev/hda1 boot
chroot .
now you can do whatever forgotten changes

2. If you used the different volume group and logical volume names, you need to do some additional changes:

2.1 change /boot/initrd-2.6.18-8.el5.img before rebooting destination
cd /mnt
mount /dev/VolGroup00/LogVol00 hd
cd hd
mount /dev/hda1 boot
chroot .
cp /boot/initrd-2.6.18.el5.img /boot/intrd-2.6.18-el5.img.orig -va (backup it first)
cp /boot/initrd-2.6.18-8.el5.img /tmp/a.img
cd /tmp
zcat a.img > a
mkdir a.dir
cd a.dir
cpio -iv < ../a vi init (to change VolGroup00 to vg0 and LogVol00 to lv0 and LogVol01 to lv1 provided you used the names vg0, lv0 and lv1) find . | cpio -co > ../b
cd ..
gzip b (zip file b as b.gz)
cp b.gz /boot/initrd-2.6.18-8.el5.img
sync
exit
cd /
umount /mnt/hd/boot
umount /mnt/hd
reboot

2.2 change /etc/fstab to reflect the new volume group and logical volume names
2.3 change /etc/grub.conf root= line to use the new names