LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2014, 09:09 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Adding a new LVM partition


Hi everyone,

I would like to add a new partition to my Centos 6.5 box. I want it to be ext3 with barriers=0.

I've come up with the following steps, but before trying, would like someone to give it a quick look and make sure I am not going to do anything bad. Also, in the steps, I have four questions and would appreciate some clarification on them. At the end of this post, I provided some information about my current configuration.

Thank you!

Code:
# Steps to add a 100G partition with ext3 and barriers=0 using LVM

# Note that you must be logged on directly as root so that lv_home isn't being used
umount /dev/VolGroup/lv_home

# IMPORTANT.  First, reduce the filesize to something smaller (10%?) than the new volumn size
# Question 1.  How do I know the current filesize, and that I am not doing something too small?
resize2fs /dev/VolGroup/lv_home 900G

# Shrink the volumn to make space for the new partion
lvreduce -L 1000G /dev/VolGroup/lv_home

# Allow file to take remaining space in volumn
resize2fs /dev/VolGroup/lv_home

# Mount home back to normal
mount -t ext4 /dev/VolGroup/lv_home /home

# Add a new volumn
# Question 2.  How can I tell it to use all remaining space?
lvcreate -L 100G -n lv_mysql VolGroup

# Partition the volumn
mkfs -t ext3 /dev/VolGroup/lv_mysql 

# To move files, stop mysql, move /var/lib/mysql to a temp directory, 
service mysqld stop
mv /var/lib/mysql /var/lib/mysql.bak

# Mount the new partition
mount -t ext3 -o barrier=0 /dev/VolGroup/lv_mysql /var/lib/mysql

mv /var/lib/mysql.bak/* /var/lib/mysql
service mysqld start

# Question 3.  How do I update /etc/fstab to automatically mount?

# Question 4.  Is how I moved /var/lib/mysql of the /home partition to the new ext3 partition correct?
Existing configuration
Code:
[root@devserver ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@devserver ~]# fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00056f9a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64      182402  1464625152   8e  Linux LVM
[root@devserver ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                3LPnlL-M45t-Bc2k-Pe4y-OnP0-woWd-53h4Sa
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-04-19 05:52:22 -0700
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_home
  LV Name                lv_home
  VG Name                VolGroup
  LV UUID                sXZfcT-Onaj-t9xi-OG0C-3s0Z-gwcT-IqVku0
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-04-19 05:52:30 -0700
  LV Status              available
  # open                 1
  LV Size                1.31 TiB
  Current LE             343282
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                KPJ2YB-NtyE-hoFF-tq85-0e8E-Lv2N-FdAM5j
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-04-19 05:55:29 -0700
  LV Status              available
  # open                 1
  LV Size                5.83 GiB
  Current LE             1492
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@devserver ~]# ls -l /dev/mapper
total 0
crw-rw----. 1 root root 10, 58 Apr 21 23:12 control
lrwxrwxrwx. 1 root root      7 Apr 21 23:48 VolGroup-lv_home -> ../dm-2
lrwxrwxrwx. 1 root root      7 Apr 21 23:48 VolGroup-lv_root -> ../dm-0
lrwxrwxrwx. 1 root root      7 Apr 21 23:48 VolGroup-lv_swap -> ../dm-1
[root@devserver ~]#

Last edited by NotionCommotion; 04-24-2014 at 10:09 AM.
 
Old 04-24-2014, 10:28 AM   #2
kkoene
Member
 
Registered: May 2008
Location: Wisconsin
Distribution: Fedora, Ubuntu, RHEL, AIX6
Posts: 33

Rep: Reputation: 0
Ok, let me try to answer these.

Answer to #1: To find the size of the filesystem you can run df -h and the table will show you how much free space you have left in the logical volume.

Answer to #2: You can run pvscan and that will show you how much space is left on the pv. Just use that after the "-L".

Answer to #3: Just use a text editor to edit /etc/fstab...I prefer using vi so your command would be vi /etc/fstab Then just follow the same syntax as what is already listed there. After saving your changes you can run "mount -a" and that will read /etc/fstab and if you have the entry in correctly it will mount your new filesystem.

Answer to #4: It looks correct. I'm not sure how mysql handles manually moving libraries though.

Hope that helps!
 
Old 04-24-2014, 11:01 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by NotionCommotion View Post
# IMPORTANT. First, reduce the filesize to something smaller (10%?) than the new volumn size
# Question 1. How do I know the current filesize, and that I am not doing something too small?
resize2fs /dev/VolGroup/lv_home 900G
resize2fs won't let you make the filesystem too small for its current contents.
Quote:
# Add a new volumn
# Question 2. How can I tell it to use all remaining space?
lvcreate -L 100G -n lv_mysql VolGroup
Instead of "-L 100G" use "-l 100%FREE" (lower-case "L", or "--extents").
Quote:
# Partition the volumn
mkfs -t ext3 /dev/VolGroup/lv_mysql
That is "formatting", not "partitioning" (the only error is in the comment).
Quote:
# Mount the new partition
mount -t ext3 -o barrier=0 /dev/VolGroup/lv_mysql /var/lib/mysql

mv /var/lib/mysql.bak/* /var/lib/mysql
service mysqld start

# Question 3. How do I update /etc/fstab to automatically mount?
Just add a line:
Code:
/dev/VolGroup/lv_mysql /var/lib/mysql ext3 barrier=0  1 2
Quote:
# Question 4. Is how I moved /var/lib/mysql of the /home partition to the new ext3 partition correct?
In place of that final "mv", I would use
Code:
cp -a /var/lib/mysql.bak/ /var/lib/mysql
and later delete the originals after I was sure everything was working. Note that I left off the trailing "*" in "/var/lib/mysql.bak/*". The trailing "*" would not include any dotfiles in that directory. Ending that argument with the "/" lets cp do the recursion and include the dotfiles. That little trick won't work for your mv command, which would also have omitted any dotfiles (not that I know whether there actually are any in /var/lib/mysql).

Last edited by rknichols; 04-24-2014 at 11:02 AM.
 
Old 04-24-2014, 11:12 AM   #4
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thank you kkoene and rknichols,

Everything seems to be working MySQL is okay with moving the library. For unknown reasons, MySQL runs about 80 times slower if I use the default configuration on my hardware. Ever heard anything like that?

I was considering the following but wasn't sure if it was all space or all remaining space . Didn't want to take the chance without knowing for sure.
Code:
lvcreate -l 100%FREE -n lv_mysql VolGroup
I suppose I could do the following to regain the space after the fact as I already did the steps described in my original post. Agree?
Code:
umount /dev/VolGroup/lv_mysql
lvcreate -l 100%FREE -n lv_mysql VolGroup
resize2fs /dev/VolGroup/lv_mysql
mount -t ext3 -o barrier=0 /dev/VolGroup/lv_mysql /var/lib/mysql
EDIT. Actually, I don't want lvcreate but some sort of lv modify command, right?

Last edited by NotionCommotion; 04-24-2014 at 11:20 AM.
 
Old 04-24-2014, 11:25 AM   #5
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Also, my original /etc/fstab looks like:
Code:
/dev/mapper/VolGroup-lv_home  /home                   ext4    defaults        1 2
Do I want:
Code:
/dev/VolGroup/lv_mysql        /var/lib/mysql          ext3    barrier=0       1 2
or:
Code:
/dev/mapper/VolGroup-lv_mysql /var/lib/mysql          ext3    barrier=0       1 2
 
Old 04-24-2014, 01:39 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
"/dev/VolGroup/lv_mysql" and "/dev/mapper/VolGroup-lv_mysql" refer to the same thing. It doesn't matter which one you use, so go along with what is used in the rest of your /etc/fstab.

"100%FREE" is pretty explicit in meaning 100% of the free space in the VG. The command you want for expanding your current LV is lvextend, and you would want "-l +100%FREE" for that. (Without the "+" sign I believe it would set the size of the LV to whatever the current free space was, which might be smaller than the LV's current size. Pardon me for not actually trying that out.)
 
Old 04-24-2014, 02:12 PM   #7
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks rknichols,

And to change a logical volume to grow to utilize all remaining free space, just do the following?
Code:
lvextend -l +100%FREE /dev/VolGroup/mysql 
resize2fs /dev/VolGroup/lv_mysql
 
Old 04-24-2014, 05:33 PM   #8
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
fstab killed my box

Okay, it wasn't fstab, it was me.

I added the following to /etc/fstab (see below for the entire fstab).

Code:
/dev/mapper/VolGroup/lv_mysql /var/lib/mysql        ext3    barrier=0       1 2
Upon rebooting, the physical monitor spit out a bunch of stuff (sorry, I didn't record it), and ultimately did not boot.

Linux live to the rescue, and I reverted back and all is good.

What did I do wrong and what should I have done?

Thank you


Code:
#
# /etc/fstab
# Created by anaconda on Sat Apr 19 05:57:56 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=12a081eb-285e-4599-95ab-db23b70280df /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_home  /home                  ext4    defaults        1 2
/dev/mapper/VolGroup/lv_mysql /var/lib/mysql         ext3    barrier=0       1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
 
Old 04-24-2014, 05:35 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by NotionCommotion View Post
Code:
lvextend -l +100%FREE /dev/VolGroup/mysql 
resize2fs /dev/VolGroup/lv_mysql
That should do it.
 
Old 04-24-2014, 05:47 PM   #10
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
That should do it.
Thanks!
 
Old 04-24-2014, 05:54 PM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Since I was the one who suggested that, I guess I have to share in the blame, but I don't see what is wrong with it.

With the system running, put that line back in /etc/fstab, perhaps changing "barrier=0" to "barrier=0,noauto" to stop the automatic mounting during boot, and then see what messages you get from a simple
Code:
mount /var/lib/mysql
At least that way you can record the error messages.
 
Old 04-24-2014, 05:55 PM   #12
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Honestly, no idea
Maybe the names are wrong ..

Personally, when I intend on messingvwith fstab I manually mount, see man mount for options
Edit: then unmount!
I then edit fstab, and then mount the mountpoint
E.g.

Code:
mount /var/lib/mysql
Since you are 'messing' with mysql, I would stop mysql before that, restarting after the mount

And .... go from there..

But...

I wouldn't expect an unbootable system from what you did, but maybe I missed something

Last edited by Firerat; 04-24-2014 at 05:56 PM.
 
Old 04-24-2014, 06:17 PM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
So, lets's get some points straight:
- it did boot; init handles fstab
- whoever updated fstab is responsible, not fstab.
- why are you trying to disable write barriers in ext3 (which doesn't enable them by default) ?.
 
Old 04-24-2014, 06:26 PM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by syg00 View Post
- why are you trying to disable write barriers in ext3 (which doesn't enable them by default) ?.
Really? That is contrary to the mount command manpage, which states:
"The ext3 filesystem enables write barriers by default,"
and warns against turning them off.

To the OP: If it's the "barrier=0" causing a problem in /etc/fstab, you might try the alternative "nobarrier".

Last edited by rknichols; 04-24-2014 at 06:30 PM. Reason: Add alternative syntax
 
Old 04-24-2014, 07:12 PM   #15
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Thanks, my mistake apparently - I (now) see a bug filed against Redhat. I remember all the discussion on barriers as a feature for ext4, and took the (Fedora) manpage as authoratative.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert non LVM root partition to LVM? pinga123 Linux - Newbie 5 04-18-2012 11:08 PM
install LVM on a distro in an LVM partition. hen770 Linux - Server 2 11-20-2011 12:37 AM
Adding an LVM hard disk to a system already running/using LVM firewiz87 Linux - Hardware 5 08-15-2010 12:59 AM
Copy Contents of LVM Partition to Another Partition With a Different File System tmort Linux - General 3 03-07-2008 05:00 AM
lvm:didn't do pvcreate on partition, before adding it to volume group kpachopoulos Linux - General 3 03-11-2007 08:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration