Pages

Tuesday, March 25, 2014

Parted Partitioning Tool


Parted Installation
-----------------------
You can install parted using yum
#yum -y install parted
How to Viewing the Current Partition Layout?
------------------------------------------------------------
You can use either 'p' or 'print' to view the current partition layout
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
(parted)
Mklabel
-------------
NOTE: One of the major advantage over fdisk is, we can create huge partitions (2GB and more)
To accomplish this, you must use a gpt label (the GUID Partition Type) for your disk.
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
NOTE: Changing the partition type will remove all partitions from your disk. All data on the disk
will be lost.
How to create an ext4 partition?
------------------------------------------
Create an ext4 parttion using the remaining space on a HDD
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512BPartition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
(parted) mkpart primary ext4 92.3GB -1s
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
After the reboot:
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
(parted)
How to create a swap parttion?
-------------------------------------
(parted) mkpart primary linux-swap 92.3GB 100G
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
(parted) quit
[root@localhost ~]#
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primaryHow to convert to LVM partition?
--------------------------------------------
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
(parted) set 3 lvm on
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
After the reboot:
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
lvm
(parted)
How to create RAID partition using parted?
--------------------------------------------------------
Create an ext4 for partition with the desired space and set the raid flag on it.
Creating the partition:
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primary
(parted) mkpart primary ext4 100G -1s
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted)
(parted)
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
4
100GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primary
400GB primary
How to set the raid flag?
(parted) set 4 raid on
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource
busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
3
92.3GB 100GB 7724MB primary
4
100GB 500GB 400GB primary
raid
(parted)How to Remove a partition?
-------------------------------------
You can remove the parttion using the parttion number.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
3
92.3GB 100GB 7724MB primary
4
100GB 500GB 400GB primary
(parted)
(parted) rm 3
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
100GB 500GB
(parted)
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
400GB primary

ARP with OpenVZ

Your OpenVZ VPS may got inaccessible due to the ARP conflict.   This problem is not a bug or a server configuration issue, its caused by the network configuration at your data-centre and the way that OpenVZ networking works.

OpenVZ VPS don't have their own network interfaces or mac addresses, instead it uses an internal Proxy/ARP based IP forwarding system, which forwards packets via the host machine.

The switch or router your node is connected to will have an ARP table which is a list of IP Addresses and the mac addresses they are routed to. This gets updated whenever an IP is accessed from a system.

When a VPS is initially created, the IP is brought up through the node and the ARP table is updated with the mac address of the node, which then forwards packets to the VPS.

If you have a VPS suspended or offline for some time, that entry in the ARP table on the switch/router will timeout and be removed. When you un-suspend or boot the VPS, the ARP table will not be updated because the VPS does not have its own mac address, and the router won't know what to do with that IP. 

This description may not be 100% accurate depending on how your datacentre has configured their network, but that's what's happening. When the VPS is offline, the router is losing it's entry of where it needs to route that IP Address.

The only way to get around the problem is to bring up the IP on the node's interface e.g. as eth0:0 or eth0:1, then ping it which will update the router's table. Then you can remove it from the node and boot the VPS.

A permanent solution would be to use a virtualization technology such as Xen or KVM, where each VPS has its own unique mac address, or find an alternate provider unless they can help you resolve this. 


(1) You can add the arp entries for the IPs on the actual virtual environment as follows

#arp -s [INSERT IP HERE] `ifconfig eth0 | grep eth0 | awk '{print $5}'` pub

Make sure you run the command above for every IP on the VPS

(2) To delete the entry from the ARP cache:

#arp -d <IP_ADDRESS>

If you get an error “SIOCDARP(pub): No such file or directory”, then you should provide an extra argument to the above command

# arp -d <IP_ADDRESS> -i <ethernet_interface>

Migrate the Emails using imapsync


To migrate an email account sales@example.com from server1.example.com to server2.example.com, please do the following.
server1.example.com (source)
server2.example.com (target)
First create the corresponding email account (sales@example.com) at the destination.
Install "imapsync" utility on your Linux machine.
Save the passwords of your email accounts in the corresponding files and change the permission to 600 as given below.
/etc/secret1 contains the password of the source email account.
/etc/secret2 contains the password of the destination email account.
Changing permission.
chmod 600 /etc/secret1
chmod 600 /etc/secret2
Initiate the following command and wait for the process to complete.
imapsync --host1 server1.example.com --user1 sales@example.com --passfile1 /etc/secret1 --host2 server2.example.com --user2 sales@example.com --passfile2 /etc/secret2

Read-only locking type set. Write locks are prohibited. (LVM)

If you receive the following error while creating the LVM, here is the fix
-----------------------------
Read-only locking type set. Write locks are prohibited.
Can't get lock for Xen1
-----------------------------
[root@test~]# grep locking_type /etc/lvm/lvm.conf
locking_type = 4
Check locking_type in the lvm config and change it to 1

Compile kernel source rpm and biuild with .spec file

Here we are recompiling source rpm with latest linux kernel(kernel.org)
(1) Download the source rpm
http://repo.smartservermanagement.com/el6/x86_64/kernel-xen-3.4.58-1.src.rpm
(2) Installed the source RPM
#rpm -ivh kernel-xen-3.4.58-1.src.rpm
This wil create rpbnild folder under /root

cd /root/rpmbuild/SPECS/
vi kernel-xen.spec
(Changed .58 to 80))
(3)Downloaded the kernel source from kernel.org(3.4.80) to /root/rpmbuild/SOURCES/
cd /root/rpmbuild/SPECS
(4)Replace the version in the spec file. Here the change is from .58 to .80
(5)Build the rpm using the .spc file as follows.
[root@test SPECS]# rpmbuild -ba kernel-xen.spec
The rpms will be available here(/root/rpmbuild/RPMS)
------------------------------------
[root@test rpmbuild]# ls RPMS/x86_64/
kernel-xen-3.4.80-1.x86_64.rpm kernel-xen-devel-3.4.80-1.x86_64.rpm kernel-xen-firmware-3.4.80-1.x86_64.rpm kernel-xen-headers-3.4.80-1.x86_64.rpm
[root@test rpmbuild]#
-------------------------------------
You can install the rpm using yum/rpm. here is the sample grub.conf after the installation.
[root@test ~]# cat /etc/grub.conf 
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd1,0)
# kernel /boot/vmlinuz-version ro root=/dev/sdb1
# initrd /boot/initrd-[generic-]version.img
#boot=/dev/sdc
default=0
timeout=5
splashimage=(hd1,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.4.80-1.el6xen.x86_64)
root (hd1,0)
kernel /boot/vmlinuz-3.4.80-1.el6xen.x86_64 ro root=UUID=2e3c5488-2950-4143-ad6c-b522fc689685 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /boot/initramfs-3.4.80-1.el6xen.x86_64.img
title CentOS (2.6.32-431.5.1.el6.x86_64)
[root@test ~]# uname -r
3.4.80-1.el6xen.x86_64
[root@test ~]#s