个人工具

“UbuntuHelp:SettingUpLVM-WithoutACleanInstall”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示同一用户的4个中间版本)
第2行: 第2行:
 
{{Languages|UbuntuHelp:SettingUpLVM-WithoutACleanInstall}}
 
{{Languages|UbuntuHelp:SettingUpLVM-WithoutACleanInstall}}
 
== Introduction ==
 
== Introduction ==
This HowTo explains how to setup LVM (Logical Volume Management) on an existing system.  The typically way of setting up LVM on Ubuntu is to use the alternative installation CD to wipe your whole hard drive and setup LVM.  Instead of starting from scratch with a clean system, we're going to add LVM to your already running Ubuntu. :-)
+
This [[UbuntuHelp:HowTo|HowTo]] explains how to setup LVM (Logical Volume Management) on an existing system.  The typically way of setting up LVM on Ubuntu is to use the alternative installation CD to wipe your whole hard drive and setup LVM.  Instead of starting from scratch with a clean system, we're going to add LVM to your already running Ubuntu. :-)
This has been tested on Ubuntu 7.07 (Feisty Fawn), but should work on previous releases.
+
This has been tested on Ubuntu 7.04 (Feisty Fawn) through 8.04 (Hardy Heron), but should work on previous releases.
""NOTE:  This HowTo is still a work in progress, but it should have enough details to get you on your way....""
+
''NOTE:  This [[UbuntuHelp:HowTo|HowTo]] is still a work in progress, but it should have enough details to get you on your way....''
 
== Installation ==
 
== Installation ==
# """Backup your data!!"""
+
<ol><li>'''''Backup your data!!'''''
# Map out your goals for LVM.  Do you just want some expandable space for media files?  Do you want to move your /home into LVM?  Do you want to move everything under LVM?  If you want to put everything under LVM, you should create a separate /boot partition (100MB should be fine) - otherwise you may not be able to boot your system.
+
</li><li>Map out your goals for LVM.  Do you just want some expandable space for media files?  Do you want to move your /home into LVM?  Do you want to move everything under LVM?  If you want to put everything under LVM, you should create a separate /boot partition (100MB should be fine) - otherwise you may not be able to boot your system.
# You're going to need some free space to setup your volume groups.  You can use:
+
</li><li>You're going to need some free space to setup your volume groups.  You can use:
## Free space on your primary hard drive.
+
<ol><li>Free space on your primary hard drive.
## A partition that you are not using any more. (such as the Windows partion you haven't booted in 6 months, that is what Qemu/VMWare are for isn't it??)
+
</li><li>A partition that you are not using any more. (such as the Windows partion you haven't booted in 6 months, that is what Qemu/VMWare are for isn't it??)
## A new blank hard drive you've added to your system.
+
</li><li>A new blank hard drive you've added to your system.
# Format your free space/partition/new drive using your favorite disk management tool to "Linux LVM".  Also use some of this space to create your separate /boot partition (100MB, ext3, bootable flag) if you are planning on putting everything under LVM.
+
</li></ol></li><li>Format your free space/partition/new drive using your favorite disk management tool to "Linux LVM".  Also use some of this space to create your separate /boot partition (100MB, ext3, bootable flag) if you are planning on putting everything under LVM.
# Now that you have an LVM partition you can create your volume groups on.  Note that you don't need a single large partition formated to Linux LVM, you can format as many smaller LVM partitions as you like, and combine them into a single filesystem using the power of LVM later - this is the preferred method as it allows more flexibility.
+
</li><li>Now that you have an LVM partition you can create your volume groups on.  Note that you don't need a single large partition formated to Linux LVM, you can format as many smaller LVM partitions as you like, and combine them into a single filesystem using the power of LVM later - this is the preferred method as it allows more flexibility.
# Install "lvm2" from the Ubuntu repositories. ("sudo aptitude install lvm2")
+
</li><li>Install "lvm2" from the Ubuntu repositories. ("sudo aptitude install lvm2")
# Install "system-config-lvm" from the repositories.
+
</li><li>Optionally install "system-config-lvm". Here: http://ubuntuforums.org/showthread.php?t=216117 is a forum thread on how to install it from Fedora RPM, (its not available in Ubuntu repositories.)
#* ''This packages does not exist in the repos'' -Derick_eisenhardt@13:21CDT-2007-07-09
+
</li><li>Load the LVM module - modprobe dm-mod. You can skip this step in Jaunty (9.04) because the `dm-mod` module is ''compiled into'' the kernel.
# Load the LVM module - modprobe dm-mod
+
</li><li>If that works without any errors, you can go ahead and add dm-mod to the end of your /etc/modules file (sudo nano /etc/modules).  This will autoload LVM when Ubuntu starts - very important if you plan on moving your system directories under LVM.</li></ol>
# If that works without any errors, you can go ahead and add dm-mod to the end of your /etc/modules file (sudo nano /etc/modules).  This will autoload LVM when Ubuntu starts - very important if you plan on moving your system directories under LVM.
+
 
 
== Configuration ==
 
== Configuration ==
 
Code Listing 2.2: Activating LVM
 
Code Listing 2.2: Activating LVM
 
(Avoid scanning all devices but our disks)
 
(Avoid scanning all devices but our disks)
# #sudo nano -w /etc/lvm/lvm.conf
+
<pre><nowiki>
 +
#sudo nano -w /etc/lvm/lvm.conf
 +
</nowiki></pre>
 
(Look for the following line)
 
(Look for the following line)
 +
<pre><nowiki>
 
filter = [ "a/.*/" ]
 
filter = [ "a/.*/" ]
(Replace it with the following one to scan
+
</nowiki></pre>
/dev/hda and /dev/hdb and reject anything else)
+
(Replace it with the following one to scan /dev/hda and /dev/hdb and reject anything else)
 +
<pre><nowiki>
 
filter = [ "a|/dev/hd[ab]|", "r/.*/" ]
 
filter = [ "a|/dev/hd[ab]|", "r/.*/" ]
 +
</nowiki></pre>
 
(Save the file and quit nano)
 
(Save the file and quit nano)
""NOTE: The default setup of Ubuntu 7.04 LVM2 already has this setup correctly.""
+
''NOTE: The default setup of Ubuntu 7.04 LVM2 already has this setup correctly.''
# #sudo vgscan
+
<pre><nowiki>
 +
#sudo vgscan
 
Reading all physical volumes.  This may take a while...
 
Reading all physical volumes.  This may take a while...
 
No volume groups found
 
No volume groups found
 +
</nowiki></pre>
 
(Make any previously set up volume groups available)
 
(Make any previously set up volume groups available)
# #sudo vgchange -a y
+
<pre><nowiki>
 +
#sudo vgchange -a y
 +
</nowiki></pre>
 
Prepare the partitions.
 
Prepare the partitions.
 
Preparing the partitions
 
Preparing the partitions
 +
<pre><nowiki>
 
# sudo pvcreate /dev/hda4 /dev/hdb1
 
# sudo pvcreate /dev/hda4 /dev/hdb1
 
No physical volume label read from /dev/hda4
 
No physical volume label read from /dev/hda4
第42行: 第52行:
 
No physical volume label read from /dev/hdb1
 
No physical volume label read from /dev/hdb1
 
Physical volume "/dev/hdb1" successfully created
 
Physical volume "/dev/hdb1" successfully created
 +
</nowiki></pre>
 
Setup a volume group. A volume group is the result of combining several physical units into a single logical device.
 
Setup a volume group. A volume group is the result of combining several physical units into a single logical device.
 
In our example, /dev/hda1, /dev/hda2 and /dev/hda3 are the /boot, swap and root partitions so we need to combine /dev/hda4 and /dev/hdb1. It can be done with a single command, but, as an example, we will create our volume group and extend it.
 
In our example, /dev/hda1, /dev/hda2 and /dev/hda3 are the /boot, swap and root partitions so we need to combine /dev/hda4 and /dev/hdb1. It can be done with a single command, but, as an example, we will create our volume group and extend it.
 
Code Listing 2.4: Creating and extending a volume group
 
Code Listing 2.4: Creating and extending a volume group
 
(Create a volume group named vg)
 
(Create a volume group named vg)
 +
<pre><nowiki>
 
# sudo vgcreate vg /dev/hda4
 
# sudo vgcreate vg /dev/hda4
 
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning)
 
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning)
第53行: 第65行:
 
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning, again and later as well)
 
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning, again and later as well)
 
Volume group "vg" successfully extended
 
Volume group "vg" successfully extended
 +
</nowiki></pre>
 
Create the logical volumes. Logical volumes are the equivalent of partitions you would create using fdisk in a non LVM2 environment. In our example, we create the following partitions:
 
Create the logical volumes. Logical volumes are the equivalent of partitions you would create using fdisk in a non LVM2 environment. In our example, we create the following partitions:
Directory Size
+
<pre><nowiki>
/usr 10 GB
+
Directory Size
/home 5 GB
+
/usr   10 GB
/opt 5 GB
+
/home   5 GB
/var 10 GB
+
/opt   5 GB
/tmp 2 GB
+
/var   10 GB
 +
/tmp   2 GB
 +
</nowiki></pre>
 
Since we are going to use LVM2, we should not worry too much about partition sizes because they can always be expanded as needed.  However, it is easier to enlarge partitions than it is to shrink them, so it is best to start smaller and add space as needed.
 
Since we are going to use LVM2, we should not worry too much about partition sizes because they can always be expanded as needed.  However, it is easier to enlarge partitions than it is to shrink them, so it is best to start smaller and add space as needed.
 
Creating and extending logical volumes
 
Creating and extending logical volumes
 +
<pre><nowiki>
 
# sudo lvcreate -L10G -nusr  vg
 
# sudo lvcreate -L10G -nusr  vg
 
Logical volume "usr" created (Further similar messages not displayed)
 
Logical volume "usr" created (Further similar messages not displayed)
第68行: 第84行:
 
# sudo lvcreate -L10G -nvar  vg
 
# sudo lvcreate -L10G -nvar  vg
 
# sudo lvcreate -L2G  -ntmp  vg
 
# sudo lvcreate -L2G  -ntmp  vg
 +
</nowiki></pre>
 
(As an example, let's extend a logical volume with 5 extra Gbytes)
 
(As an example, let's extend a logical volume with 5 extra Gbytes)
 +
<pre><nowiki>
 
# sudo lvextend -L+5G /dev/vg/home
 
# sudo lvextend -L+5G /dev/vg/home
 +
</nowiki></pre>
 
Create filesystems on the logical volumes the same way you would on a regular partition. We use ext3 on the logical volumes but any filesystem of your choice will work:
 
Create filesystems on the logical volumes the same way you would on a regular partition. We use ext3 on the logical volumes but any filesystem of your choice will work:
 
Creating the filesystems:
 
Creating the filesystems:
 +
<pre><nowiki>
 
# sudo mke2fs -j /dev/vg/usr
 
# sudo mke2fs -j /dev/vg/usr
 
# sudo mke2fs -j /dev/vg/home
 
# sudo mke2fs -j /dev/vg/home
第77行: 第97行:
 
# sudo mke2fs -j /dev/vg/var
 
# sudo mke2fs -j /dev/vg/var
 
# sudo mke2fs -j /dev/vg/tmp
 
# sudo mke2fs -j /dev/vg/tmp
 +
</nowiki></pre>
 
Mount your partitions as described in the handbook and mount your LVM2 logical volumes as if they were partitions. Replace the usual /dev/hdxx with /dev/vg/logical_volumename.
 
Mount your partitions as described in the handbook and mount your LVM2 logical volumes as if they were partitions. Replace the usual /dev/hdxx with /dev/vg/logical_volumename.
 
Code Listing 2.7: Mounting your logical volumes
 
Code Listing 2.7: Mounting your logical volumes
 
(Make sure you have mounted your root partition as described in the handbook first)
 
(Make sure you have mounted your root partition as described in the handbook first)
 +
<pre><nowiki>
 
# sudo mkdir /mnt/ubuntu/usr
 
# sudo mkdir /mnt/ubuntu/usr
 
# sudo mount /dev/vg/usr /mnt/ubuntu/usr
 
# sudo mount /dev/vg/usr /mnt/ubuntu/usr
第90行: 第112行:
 
# sudo mkdir /mnt/ubuntu/tmp
 
# sudo mkdir /mnt/ubuntu/tmp
 
# sudo mount /dev/vg/tmp /mnt/ubuntu/tmp
 
# sudo mount /dev/vg/tmp /mnt/ubuntu/tmp
 +
</nowiki></pre>
 
NOTE:  These mount points are for testing purposes.  After you have copied /usr to /mnt/ubuntu/usr, (and also for home, opt, var, tmp, etc), You can change your /etc/fstab mount points to permantent paths.
 
NOTE:  These mount points are for testing purposes.  After you have copied /usr to /mnt/ubuntu/usr, (and also for home, opt, var, tmp, etc), You can change your /etc/fstab mount points to permantent paths.
 
For a nice GUI, you can run system-config-lvm from the shell.  This will let you manage your LVM volume groups more easily.  However, be careful, as changes are made immediately and you don't want to accidentally wipe your data.
 
For a nice GUI, you can run system-config-lvm from the shell.  This will let you manage your LVM volume groups more easily.  However, be careful, as changes are made immediately and you don't want to accidentally wipe your data.
 
== Acknowledgements ==
 
== Acknowledgements ==
Much of this HowTo was copied from the Gentoo Documentation and modified for Ubuntu.  http://www.gentoo.org/doc/en/lvm2.xml
+
Much of this [[UbuntuHelp:HowTo|HowTo]] was copied from the Gentoo Documentation and modified for Ubuntu.  http://www.gentoo.org/doc/en/lvm2.xml
 
----
 
----
[[category:CategoryDocumentation]]
 
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2009年5月12日 (二) 18:48的最新版本

Introduction

This HowTo explains how to setup LVM (Logical Volume Management) on an existing system. The typically way of setting up LVM on Ubuntu is to use the alternative installation CD to wipe your whole hard drive and setup LVM. Instead of starting from scratch with a clean system, we're going to add LVM to your already running Ubuntu. :-) This has been tested on Ubuntu 7.04 (Feisty Fawn) through 8.04 (Hardy Heron), but should work on previous releases. NOTE: This HowTo is still a work in progress, but it should have enough details to get you on your way....

Installation

  1. Backup your data!!
  2. Map out your goals for LVM. Do you just want some expandable space for media files? Do you want to move your /home into LVM? Do you want to move everything under LVM? If you want to put everything under LVM, you should create a separate /boot partition (100MB should be fine) - otherwise you may not be able to boot your system.
  3. You're going to need some free space to setup your volume groups. You can use:
    1. Free space on your primary hard drive.
    2. A partition that you are not using any more. (such as the Windows partion you haven't booted in 6 months, that is what Qemu/VMWare are for isn't it??)
    3. A new blank hard drive you've added to your system.
  4. Format your free space/partition/new drive using your favorite disk management tool to "Linux LVM". Also use some of this space to create your separate /boot partition (100MB, ext3, bootable flag) if you are planning on putting everything under LVM.
  5. Now that you have an LVM partition you can create your volume groups on. Note that you don't need a single large partition formated to Linux LVM, you can format as many smaller LVM partitions as you like, and combine them into a single filesystem using the power of LVM later - this is the preferred method as it allows more flexibility.
  6. Install "lvm2" from the Ubuntu repositories. ("sudo aptitude install lvm2")
  7. Optionally install "system-config-lvm". Here: http://ubuntuforums.org/showthread.php?t=216117 is a forum thread on how to install it from Fedora RPM, (its not available in Ubuntu repositories.)
  8. Load the LVM module - modprobe dm-mod. You can skip this step in Jaunty (9.04) because the `dm-mod` module is compiled into the kernel.
  9. If that works without any errors, you can go ahead and add dm-mod to the end of your /etc/modules file (sudo nano /etc/modules). This will autoload LVM when Ubuntu starts - very important if you plan on moving your system directories under LVM.

Configuration

Code Listing 2.2: Activating LVM (Avoid scanning all devices but our disks)

#sudo nano -w /etc/lvm/lvm.conf

(Look for the following line)

filter = [ "a/.*/" ]

(Replace it with the following one to scan /dev/hda and /dev/hdb and reject anything else)

filter = [ "a|/dev/hd[ab]|", "r/.*/" ]

(Save the file and quit nano) NOTE: The default setup of Ubuntu 7.04 LVM2 already has this setup correctly.

#sudo vgscan
Reading all physical volumes.  This may take a while...
No volume groups found

(Make any previously set up volume groups available)

#sudo vgchange -a y

Prepare the partitions. Preparing the partitions

# sudo pvcreate /dev/hda4 /dev/hdb1
No physical volume label read from /dev/hda4
Physical volume "/dev/hda4" successfully created
No physical volume label read from /dev/hdb1
Physical volume "/dev/hdb1" successfully created

Setup a volume group. A volume group is the result of combining several physical units into a single logical device. In our example, /dev/hda1, /dev/hda2 and /dev/hda3 are the /boot, swap and root partitions so we need to combine /dev/hda4 and /dev/hdb1. It can be done with a single command, but, as an example, we will create our volume group and extend it. Code Listing 2.4: Creating and extending a volume group (Create a volume group named vg)

# sudo vgcreate vg /dev/hda4
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning)
Volume group "vg" successfully created
(Extending an existing volume group)
# sudo vgextend vg /dev/hdb1
/etc/lvm/backup: fsync failed: Invalid argument (Ignore this warning, again and later as well)
Volume group "vg" successfully extended

Create the logical volumes. Logical volumes are the equivalent of partitions you would create using fdisk in a non LVM2 environment. In our example, we create the following partitions:

Directory  Size
/usr 	   10 GB
/home 	   5 GB
/opt 	   5 GB
/var 	   10 GB
/tmp 	   2 GB

Since we are going to use LVM2, we should not worry too much about partition sizes because they can always be expanded as needed. However, it is easier to enlarge partitions than it is to shrink them, so it is best to start smaller and add space as needed. Creating and extending logical volumes

# sudo lvcreate -L10G -nusr  vg
Logical volume "usr" created (Further similar messages not displayed)
# sudo lvcreate -L5G  -nhome vg
# sudo lvcreate -L5G  -nopt  vg
# sudo lvcreate -L10G -nvar  vg
# sudo lvcreate -L2G  -ntmp  vg

(As an example, let's extend a logical volume with 5 extra Gbytes)

# sudo lvextend -L+5G /dev/vg/home

Create filesystems on the logical volumes the same way you would on a regular partition. We use ext3 on the logical volumes but any filesystem of your choice will work: Creating the filesystems:

# sudo mke2fs -j /dev/vg/usr
# sudo mke2fs -j /dev/vg/home
# sudo mke2fs -j /dev/vg/opt
# sudo mke2fs -j /dev/vg/var
# sudo mke2fs -j /dev/vg/tmp

Mount your partitions as described in the handbook and mount your LVM2 logical volumes as if they were partitions. Replace the usual /dev/hdxx with /dev/vg/logical_volumename. Code Listing 2.7: Mounting your logical volumes (Make sure you have mounted your root partition as described in the handbook first)

# sudo mkdir /mnt/ubuntu/usr
# sudo mount /dev/vg/usr /mnt/ubuntu/usr
# sudo mkdir /mnt/ubuntu/home
# sudo mount /dev/vg/home /mnt/ubuntu/home
# sudo mkdir /mnt/ubuntu/opt
# sudo mount /dev/vg/opt /mnt/ubuntu/opt
# sudo mkdir /mnt/ubuntu/var
# sudo mount /dev/vg/var /mnt/ubuntu/var
# sudo mkdir /mnt/ubuntu/tmp
# sudo mount /dev/vg/tmp /mnt/ubuntu/tmp

NOTE: These mount points are for testing purposes. After you have copied /usr to /mnt/ubuntu/usr, (and also for home, opt, var, tmp, etc), You can change your /etc/fstab mount points to permantent paths. For a nice GUI, you can run system-config-lvm from the shell. This will let you manage your LVM volume groups more easily. However, be careful, as changes are made immediately and you don't want to accidentally wipe your data.

Acknowledgements

Much of this HowTo was copied from the Gentoo Documentation and modified for Ubuntu. http://www.gentoo.org/doc/en/lvm2.xml