个人工具

“UbuntuHelp:FileServerOnLVMOnRAID1”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:FileServerOnLVMOnRAID1}}
 
{{Languages|UbuntuHelp:FileServerOnLVMOnRAID1}}
 
== WARNING UPDATE! ==
 
== WARNING UPDATE! ==
 
 
'' '''Note from NicholasIstre:''' The server I was testing this setup on had failed on a bootup with a kernel-panic (*slaps forehead for not writing the exact error down...*) a couple of bootups after I added a new RAID1 array to the main volume group.  Depending on further testing and discussion with the community, I may modify these instructions to have a /boot or even the root filesystem on the RAID1 outside of the LVM partition.''
 
'' '''Note from NicholasIstre:''' The server I was testing this setup on had failed on a bootup with a kernel-panic (*slaps forehead for not writing the exact error down...*) a couple of bootups after I added a new RAID1 array to the main volume group.  Depending on further testing and discussion with the community, I may modify these instructions to have a /boot or even the root filesystem on the RAID1 outside of the LVM partition.''
 
 
== Introduction ==
 
== Introduction ==
 
 
 
 
As I've collected a fair amount of hardware, I decided that I wanted to create a small file server with a few hard drives and a spare system I had lying around, like many others probably have done.  I also wanted RAID1 capability and the ability to add to the system, though not necessarily through hot-plugging, though I'm sure this HOW-TO can provide a jump-point if you have such hardware available.  No, I'm working with old-fashioned IDE drives, and I want to have a place that I can pretty reliably store anime and music that I... ahem...  acquire...
 
As I've collected a fair amount of hardware, I decided that I wanted to create a small file server with a few hard drives and a spare system I had lying around, like many others probably have done.  I also wanted RAID1 capability and the ability to add to the system, though not necessarily through hot-plugging, though I'm sure this HOW-TO can provide a jump-point if you have such hardware available.  No, I'm working with old-fashioned IDE drives, and I want to have a place that I can pretty reliably store anime and music that I... ahem...  acquire...
 
 
Unfortunately, the documentation for LVM and Software RAID is a bit sparse.  Among others, I've read [[UbuntuHelp:Installation/LVMOnRaid]], [http://www.tldp.org/HOWTO/LVM-HOWTO/index.html this very helpful LVM HOW-TO], [http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html this software RAID HOW-TO], and [http://www.tldp.org/FAQ/Linux-RAID-FAQ/x37.html this Linux RAID FAQ], but they only really provided the tools and hints.  I had to figure out how to setup this server by myself, it seems.
 
Unfortunately, the documentation for LVM and Software RAID is a bit sparse.  Among others, I've read [[UbuntuHelp:Installation/LVMOnRaid]], [http://www.tldp.org/HOWTO/LVM-HOWTO/index.html this very helpful LVM HOW-TO], [http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html this software RAID HOW-TO], and [http://www.tldp.org/FAQ/Linux-RAID-FAQ/x37.html this Linux RAID FAQ], but they only really provided the tools and hints.  I had to figure out how to setup this server by myself, it seems.
 
 
And, for more things for me to do, the only hardware I have available for this are a P-III system with 2 onboard PATA-100, a DVD/CD reader, a network card, 2 60-Gig drive, 2 120-Gig drives, and necessary cables for all.  If you didn't notice, I have connections for 4 IDE devices, where as I have 5 that I want to use.  Even worse, I'd have to master/slave two of the Hard drives together, which is pretty much a no-no.  So off I go to my trusty online computer parts retailer and order a PCI card with two more ATA-133 connections.
 
And, for more things for me to do, the only hardware I have available for this are a P-III system with 2 onboard PATA-100, a DVD/CD reader, a network card, 2 60-Gig drive, 2 120-Gig drives, and necessary cables for all.  If you didn't notice, I have connections for 4 IDE devices, where as I have 5 that I want to use.  Even worse, I'd have to master/slave two of the Hard drives together, which is pretty much a no-no.  So off I go to my trusty online computer parts retailer and order a PCI card with two more ATA-133 connections.
 
 
In the meantime, I still would like to put something together that would provide me with 2 of the hard drives until the IDE card comes in, where I will install it with the other 2 hard drives, RAID 1 them, then extend the existing filesystems onto that.
 
In the meantime, I still would like to put something together that would provide me with 2 of the hard drives until the IDE card comes in, where I will install it with the other 2 hard drives, RAID 1 them, then extend the existing filesystems onto that.
 
 
So, I've given you the hardware I have.  I will be using the Ubuntu 6.06 Server CD to do the following on LVM on RAID 1:
 
So, I've given you the hardware I have.  I will be using the Ubuntu 6.06 Server CD to do the following on LVM on RAID 1:
 
 
* FTP Server (only for my local network, to use with Acronis True Image software)
 
* FTP Server (only for my local network, to use with Acronis True Image software)
 
* SMB Server (for windows sharing)
 
* SMB Server (for windows sharing)
 
* SSH Server (pretty standard on all of my server setups)
 
* SSH Server (pretty standard on all of my server setups)
 
 
I will be creating this HOW-TO for my own reference, especially when I go and upgrade the fileserver with more harddrives.  I will be using VMWare Server software on a laptop to provide screenshots and help along when writing this article (So, feel sorry for me as this poor 4500 RPM drive will have to pretend to be up to 4 drives in RAID 1 format...)
 
I will be creating this HOW-TO for my own reference, especially when I go and upgrade the fileserver with more harddrives.  I will be using VMWare Server software on a laptop to provide screenshots and help along when writing this article (So, feel sorry for me as this poor 4500 RPM drive will have to pretend to be up to 4 drives in RAID 1 format...)
 
 
Please note, anything in ''italics'' will be me asking the community for help on certain things.
 
Please note, anything in ''italics'' will be me asking the community for help on certain things.
 
 
Now, onto the actual HOW-TO...
 
Now, onto the actual HOW-TO...
 
 
 
== Install ==
 
== Install ==
 
 
Setup the system to boot from the CD and boot-up your trusty Ubuntu 6.06 Server CD
 
Setup the system to boot from the CD and boot-up your trusty Ubuntu 6.06 Server CD
 
 
http://www.wisemouseboy.com/gallery2/d/3402-2/Ubuntu6_06Start.png
 
http://www.wisemouseboy.com/gallery2/d/3402-2/Ubuntu6_06Start.png
 
 
Choose '''Install to the hard disk''' and press ENTER.  You will then proceed to choose your language, location, and keyboard layout.
 
Choose '''Install to the hard disk''' and press ENTER.  You will then proceed to choose your language, location, and keyboard layout.
 
 
http://www.wisemouseboy.com/gallery2/d/3405-2/2ChooseLanguage.png
 
http://www.wisemouseboy.com/gallery2/d/3405-2/2ChooseLanguage.png
 
http://www.wisemouseboy.com/gallery2/d/3407-2/3ChooseLocation.png
 
http://www.wisemouseboy.com/gallery2/d/3407-2/3ChooseLocation.png
 
http://www.wisemouseboy.com/gallery2/d/3409-2/4ChooseKeyboardLayout.png
 
http://www.wisemouseboy.com/gallery2/d/3409-2/4ChooseKeyboardLayout.png
 
 
Enter the hostname of your server.
 
Enter the hostname of your server.
 
 
http://www.wisemouseboy.com/gallery2/d/3411-2/5SetHostName.png
 
http://www.wisemouseboy.com/gallery2/d/3411-2/5SetHostName.png
 
 
=== Setting up RAID ===
 
=== Setting up RAID ===
 
 
/!\ This section is incorrect.  Setup a /boot section outside of the LVM by creating two RAID 1 arrays, the boot section being at least 200 MBs or so.  Be sure to verify/setup the /boot partition after setting up the LVM.
 
/!\ This section is incorrect.  Setup a /boot section outside of the LVM by creating two RAID 1 arrays, the boot section being at least 200 MBs or so.  Be sure to verify/setup the /boot partition after setting up the LVM.
 
 
Select '''Manually edit partition table'''
 
Select '''Manually edit partition table'''
 
 
http://www.wisemouseboy.com/gallery2/d/3413-2/6ManualPartition.png
 
http://www.wisemouseboy.com/gallery2/d/3413-2/6ManualPartition.png
 
 
Select each drive and select '''Yes''' to create new empty partition tables.
 
Select each drive and select '''Yes''' to create new empty partition tables.
 
 
http://www.wisemouseboy.com/gallery2/d/3415-2/7SetupPartitionTables.png
 
http://www.wisemouseboy.com/gallery2/d/3415-2/7SetupPartitionTables.png
 
http://www.wisemouseboy.com/gallery2/d/3417-2/8SetupPartitionTables.png
 
http://www.wisemouseboy.com/gallery2/d/3417-2/8SetupPartitionTables.png
 
http://www.wisemouseboy.com/gallery2/d/3419-2/9EmptyPartitions.png
 
http://www.wisemouseboy.com/gallery2/d/3419-2/9EmptyPartitions.png
 
 
Now pick the smaller drive, move to the line saying '''FREE SPACE''' under it, and press ENTER.
 
Now pick the smaller drive, move to the line saying '''FREE SPACE''' under it, and press ENTER.
 
 
http://www.wisemouseboy.com/gallery2/d/3421-2/10ChooseFREESPACE.png
 
http://www.wisemouseboy.com/gallery2/d/3421-2/10ChooseFREESPACE.png
 
 
Create a new primary partition and keep the default size to use the full disk.
 
Create a new primary partition and keep the default size to use the full disk.
 
 
http://www.wisemouseboy.com/gallery2/d/3423-2/11CreateaNewPartition.png
 
http://www.wisemouseboy.com/gallery2/d/3423-2/11CreateaNewPartition.png
 
http://www.wisemouseboy.com/gallery2/d/3425-2/12ChooseFullDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3425-2/12ChooseFullDisk.png
 
 
Remember this value when creating the partition on the larger disk!  Not necessary if both disks are exactly the same size.   
 
Remember this value when creating the partition on the larger disk!  Not necessary if both disks are exactly the same size.   
 
''I do not know how the RAID 1 would work with different size partitions''
 
''I do not know how the RAID 1 would work with different size partitions''
 
 
http://www.wisemouseboy.com/gallery2/d/3427-2/13SetPrimaryType.png
 
http://www.wisemouseboy.com/gallery2/d/3427-2/13SetPrimaryType.png
 
 
Change the partition type to RAID, set the bootable flag, and you're done with this disk!
 
Change the partition type to RAID, set the bootable flag, and you're done with this disk!
 
 
http://www.wisemouseboy.com/gallery2/d/3429-2/14ChangeUseAs.png
 
http://www.wisemouseboy.com/gallery2/d/3429-2/14ChangeUseAs.png
 
http://www.wisemouseboy.com/gallery2/d/3431-2/15ChoosephysicalvolumeforRAID.png
 
http://www.wisemouseboy.com/gallery2/d/3431-2/15ChoosephysicalvolumeforRAID.png
 
http://www.wisemouseboy.com/gallery2/d/3433-2/16SetBootableFlag.png
 
http://www.wisemouseboy.com/gallery2/d/3433-2/16SetBootableFlag.png
 
http://www.wisemouseboy.com/gallery2/d/3435-2/17Donesettingupthepartition.png
 
http://www.wisemouseboy.com/gallery2/d/3435-2/17Donesettingupthepartition.png
 
 
Do the same process on the other disk, but set the size of the partition as the same as the other disk, if they are different sizes.  Choose '''Beginning''' if asked where to place the partition.
 
Do the same process on the other disk, but set the size of the partition as the same as the other disk, if they are different sizes.  Choose '''Beginning''' if asked where to place the partition.
 
 
http://www.wisemouseboy.com/gallery2/d/3437-2/18SetupOtherDrive.png
 
http://www.wisemouseboy.com/gallery2/d/3437-2/18SetupOtherDrive.png
 
http://www.wisemouseboy.com/gallery2/d/3439-2/19CreateaNewPartition2.png
 
http://www.wisemouseboy.com/gallery2/d/3439-2/19CreateaNewPartition2.png
第92行: 第55行:
 
http://www.wisemouseboy.com/gallery2/d/3451-2/25SetBootableflag.png
 
http://www.wisemouseboy.com/gallery2/d/3451-2/25SetBootableflag.png
 
http://www.wisemouseboy.com/gallery2/d/3453-2/26DoneWithDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3453-2/26DoneWithDisk.png
 
 
Now that both disks are setup, we need to setup the Software RAID.  Say yes to write the changes to disk and select '''Create MD device'''.
 
Now that both disks are setup, we need to setup the Software RAID.  Say yes to write the changes to disk and select '''Create MD device'''.
 
 
http://www.wisemouseboy.com/gallery2/d/3455-2/27ConfiguresoftwareRAID.png
 
http://www.wisemouseboy.com/gallery2/d/3455-2/27ConfiguresoftwareRAID.png
 
http://www.wisemouseboy.com/gallery2/d/3457-2/28WriteChangesToDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3457-2/28WriteChangesToDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3459-2/29CreateMDdevice.png
 
http://www.wisemouseboy.com/gallery2/d/3459-2/29CreateMDdevice.png
 
 
Select '''RAID1''', choose 2 Active Devices, 0 Spares, Select the two RAID partitions you just created, and you're now finished with setting up the RAID.
 
Select '''RAID1''', choose 2 Active Devices, 0 Spares, Select the two RAID partitions you just created, and you're now finished with setting up the RAID.
 
 
http://www.wisemouseboy.com/gallery2/d/3461-2/30ChooseRAID1.png
 
http://www.wisemouseboy.com/gallery2/d/3461-2/30ChooseRAID1.png
 
http://www.wisemouseboy.com/gallery2/d/3463-2/31Set2ActiveDevices.png
 
http://www.wisemouseboy.com/gallery2/d/3463-2/31Set2ActiveDevices.png
第106行: 第65行:
 
http://www.wisemouseboy.com/gallery2/d/3467-2/33SelectActiveDevices.png
 
http://www.wisemouseboy.com/gallery2/d/3467-2/33SelectActiveDevices.png
 
http://www.wisemouseboy.com/gallery2/d/3469-2/34FinishRAIDSetup.png
 
http://www.wisemouseboy.com/gallery2/d/3469-2/34FinishRAIDSetup.png
 
 
=== Setting up LVM ===
 
=== Setting up LVM ===
 
 
We now have a '''Software RAID device''' to play with, so select that device's space to set it up to use as a physical volume for LVM, and '''Done setting up the partition'''.
 
We now have a '''Software RAID device''' to play with, so select that device's space to set it up to use as a physical volume for LVM, and '''Done setting up the partition'''.
 
 
http://www.wisemouseboy.com/gallery2/d/3471-2/35SelectingRAIDPartition.png
 
http://www.wisemouseboy.com/gallery2/d/3471-2/35SelectingRAIDPartition.png
 
http://www.wisemouseboy.com/gallery2/d/3473-2/36SelectUseAs.png
 
http://www.wisemouseboy.com/gallery2/d/3473-2/36SelectUseAs.png
 
http://www.wisemouseboy.com/gallery2/d/3475-2/37SelectphysicalvolumeforLVM.png
 
http://www.wisemouseboy.com/gallery2/d/3475-2/37SelectphysicalvolumeforLVM.png
 
http://www.wisemouseboy.com/gallery2/d/3477-2/38Donesettingupthepartition.png
 
http://www.wisemouseboy.com/gallery2/d/3477-2/38Donesettingupthepartition.png
 
 
Now that we have a physical LVM volume, select '''Configure the Logical Volume Manager''', and write the changes to disk.
 
Now that we have a physical LVM volume, select '''Configure the Logical Volume Manager''', and write the changes to disk.
 
 
http://www.wisemouseboy.com/gallery2/d/3479-2/39ConfiguretheLogicalVolumeManager.png
 
http://www.wisemouseboy.com/gallery2/d/3479-2/39ConfiguretheLogicalVolumeManager.png
 
http://www.wisemouseboy.com/gallery2/d/3481-2/40WriteChangesToDisks.png
 
http://www.wisemouseboy.com/gallery2/d/3481-2/40WriteChangesToDisks.png
 
 
/!\ I got an error here, but when I chose '''Ignore''' and continued on with the rest of the setup, it seems to install and setup just fine.   
 
/!\ I got an error here, but when I chose '''Ignore''' and continued on with the rest of the setup, it seems to install and setup just fine.   
 
 
(!) I find that waiting until the RAID arrays finish syncing will cause fewer issues after the install.  Switch to another terminal using ALT-F2 and run "cat /proc/mdstat/" until the arrays are finished syncing (This may take some time, depending on how large the hard drives are).  Once it is finished, switch back to the installer with ALT-F1.
 
(!) I find that waiting until the RAID arrays finish syncing will cause fewer issues after the install.  Switch to another terminal using ALT-F2 and run "cat /proc/mdstat/" until the arrays are finished syncing (This may take some time, depending on how large the hard drives are).  Once it is finished, switch back to the installer with ALT-F1.
 
 
http://www.wisemouseboy.com/gallery2/d/3483-2/41Error.png
 
http://www.wisemouseboy.com/gallery2/d/3483-2/41Error.png
 
 
Setup the Volume Group using the physical LVM volume we just created.
 
Setup the Volume Group using the physical LVM volume we just created.
 
 
http://www.wisemouseboy.com/gallery2/d/3485-2/42ModifyVG.png
 
http://www.wisemouseboy.com/gallery2/d/3485-2/42ModifyVG.png
 
http://www.wisemouseboy.com/gallery2/d/3487-2/43CreateVolumeGroups.png
 
http://www.wisemouseboy.com/gallery2/d/3487-2/43CreateVolumeGroups.png
 
http://www.wisemouseboy.com/gallery2/d/3489-2/44SelectDevice.png
 
http://www.wisemouseboy.com/gallery2/d/3489-2/44SelectDevice.png
 
 
Choose whatever name you wish.  Since I will only have one volume group, I'm including the name of the server in the name.  Once the name is picked, you can leave the volume group configuration menu.
 
Choose whatever name you wish.  Since I will only have one volume group, I'm including the name of the server in the name.  Once the name is picked, you can leave the volume group configuration menu.
 
 
http://www.wisemouseboy.com/gallery2/d/3491-2/45SetVolumeGroupName.png
 
http://www.wisemouseboy.com/gallery2/d/3491-2/45SetVolumeGroupName.png
 
http://www.wisemouseboy.com/gallery2/d/3493-2/46LeaveVolumeGroupConfig.png
 
http://www.wisemouseboy.com/gallery2/d/3493-2/46LeaveVolumeGroupConfig.png
 
 
We will now create our logical volumes.  I will be making 4, for the root, /boot, /home, and swap areas.  For simplicity, I will name them "root", "boot", "home", and "swap".
 
We will now create our logical volumes.  I will be making 4, for the root, /boot, /home, and swap areas.  For simplicity, I will name them "root", "boot", "home", and "swap".
 
 
http://www.wisemouseboy.com/gallery2/d/3495-2/47ModifyLogicalVolumes.png
 
http://www.wisemouseboy.com/gallery2/d/3495-2/47ModifyLogicalVolumes.png
 
http://www.wisemouseboy.com/gallery2/d/3497-2/48CreateLogicalVolumes.png
 
http://www.wisemouseboy.com/gallery2/d/3497-2/48CreateLogicalVolumes.png
第149行: 第94行:
 
http://www.wisemouseboy.com/gallery2/d/3509-2/54SelectVG.png
 
http://www.wisemouseboy.com/gallery2/d/3509-2/54SelectVG.png
 
http://www.wisemouseboy.com/gallery2/d/3511-2/55SetSize.png
 
http://www.wisemouseboy.com/gallery2/d/3511-2/55SetSize.png
 
 
I will continue with making a "swap" logical volume that's 1 gig, and a "home" logical volume that takes up the rest of the drive.
 
I will continue with making a "swap" logical volume that's 1 gig, and a "home" logical volume that takes up the rest of the drive.
 
 
Now that the LVs are setup, leave the LVM configuration menu.
 
Now that the LVs are setup, leave the LVM configuration menu.
 
 
http://www.wisemouseboy.com/gallery2/d/3513-2/56LeaveLVMConfigurationMenu.png
 
http://www.wisemouseboy.com/gallery2/d/3513-2/56LeaveLVMConfigurationMenu.png
 
 
 
=== Setting up filesystem ===
 
=== Setting up filesystem ===
 
 
We now have the four logical volumes (or however many you setup) in the partition list ready to be setup.  Select each one and configure them as wanted.  You may notice that I used the XFS filesystem for root and /home because it can be expanded on the fly, while ''(from what I can tell)'' ext3 has to be unmounted to be resized.  Some of the others have this ability, though.   
 
We now have the four logical volumes (or however many you setup) in the partition list ready to be setup.  Select each one and configure them as wanted.  You may notice that I used the XFS filesystem for root and /home because it can be expanded on the fly, while ''(from what I can tell)'' ext3 has to be unmounted to be resized.  Some of the others have this ability, though.   
 
''Help for filesystem advice here would be appreciated!''
 
''Help for filesystem advice here would be appreciated!''
 
 
http://www.wisemouseboy.com/gallery2/d/3515-2/57PartitionList.png
 
http://www.wisemouseboy.com/gallery2/d/3515-2/57PartitionList.png
 
http://www.wisemouseboy.com/gallery2/d/3517-2/58BootUseAs.png
 
http://www.wisemouseboy.com/gallery2/d/3517-2/58BootUseAs.png
第169行: 第107行:
 
http://www.wisemouseboy.com/gallery2/d/3525-2/62done.png
 
http://www.wisemouseboy.com/gallery2/d/3525-2/62done.png
 
http://www.wisemouseboy.com/gallery2/d/3527-2/63LVsetup.png
 
http://www.wisemouseboy.com/gallery2/d/3527-2/63LVsetup.png
 
 
Now that the partitions are how we like them, we will finish with setting up the disks.  Please note that same error comes back, but we will ignore it again.  The system will then start setting up the filesystem for you.
 
Now that the partitions are how we like them, we will finish with setting up the disks.  Please note that same error comes back, but we will ignore it again.  The system will then start setting up the filesystem for you.
 
 
http://www.wisemouseboy.com/gallery2/d/3529-2/64FinishedPartitioningDisks.png
 
http://www.wisemouseboy.com/gallery2/d/3529-2/64FinishedPartitioningDisks.png
 
http://www.wisemouseboy.com/gallery2/d/3531-2/65WriteChangesToDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3531-2/65WriteChangesToDisk.png
 
http://www.wisemouseboy.com/gallery2/d/3533-2/66ErrorAgain.png
 
http://www.wisemouseboy.com/gallery2/d/3533-2/66ErrorAgain.png
 
 
 
=== Finishing up Install ===
 
=== Finishing up Install ===
 
 
Setup your Timezone and UTC information.
 
Setup your Timezone and UTC information.
 
 
http://www.wisemouseboy.com/gallery2/d/3535-2/67SetTimeZone.png
 
http://www.wisemouseboy.com/gallery2/d/3535-2/67SetTimeZone.png
 
http://www.wisemouseboy.com/gallery2/d/3537-2/68SetUTC.png
 
http://www.wisemouseboy.com/gallery2/d/3537-2/68SetUTC.png
 
 
Setup your initial user and password.
 
Setup your initial user and password.
 
 
http://www.wisemouseboy.com/gallery2/d/3539-2/69SetupUserName.png
 
http://www.wisemouseboy.com/gallery2/d/3539-2/69SetupUserName.png
 
http://www.wisemouseboy.com/gallery2/d/3541-2/70SetupUserLogin.png
 
http://www.wisemouseboy.com/gallery2/d/3541-2/70SetupUserLogin.png
 
http://www.wisemouseboy.com/gallery2/d/3543-2/71SetPassword.png
 
http://www.wisemouseboy.com/gallery2/d/3543-2/71SetPassword.png
 
http://www.wisemouseboy.com/gallery2/d/3545-2/72ConfirmPassword.png
 
http://www.wisemouseboy.com/gallery2/d/3545-2/72ConfirmPassword.png
 
 
The installer will now starting copying packages and setting up your new server
 
The installer will now starting copying packages and setting up your new server
 
 
http://www.wisemouseboy.com/gallery2/d/3547-2/73InstallingSystem.png
 
http://www.wisemouseboy.com/gallery2/d/3547-2/73InstallingSystem.png
 
 
Setup LILO by selecting the default option, '''/dev/md0: software RAID array'''
 
Setup LILO by selecting the default option, '''/dev/md0: software RAID array'''
 
 
http://www.wisemouseboy.com/gallery2/d/3549-2/74SetupLILO.png
 
http://www.wisemouseboy.com/gallery2/d/3549-2/74SetupLILO.png
 
 
Again, the installer tells you something fails, in this case LILO installation, but continue anyways.
 
Again, the installer tells you something fails, in this case LILO installation, but continue anyways.
 
 
http://www.wisemouseboy.com/gallery2/d/3551-2/75ContinueAfterFailure.png
 
http://www.wisemouseboy.com/gallery2/d/3551-2/75ContinueAfterFailure.png
 
 
Installation complete!  Or so says the installer.  Remove your trusty Ubuntu 6.06 Server CD and select continue.  Cross your fingers as it reboots...  
 
Installation complete!  Or so says the installer.  Remove your trusty Ubuntu 6.06 Server CD and select continue.  Cross your fingers as it reboots...  
 
 
http://www.wisemouseboy.com/gallery2/d/3553-2/76InstallComplete.png
 
http://www.wisemouseboy.com/gallery2/d/3553-2/76InstallComplete.png
 
 
...and success!  Well, in my case.  Your mileage may vary.
 
...and success!  Well, in my case.  Your mileage may vary.
 
 
http://www.wisemouseboy.com/gallery2/d/3555-2/77FirstBoot.png
 
http://www.wisemouseboy.com/gallery2/d/3555-2/77FirstBoot.png
 
 
Now we have a base Ubuntu Server installation up and running, on LVM on RAID1 no doubt!   
 
Now we have a base Ubuntu Server installation up and running, on LVM on RAID1 no doubt!   
 
 
=== Verifying installation ===
 
=== Verifying installation ===
 
 
If you want to check on the status of your RAID drive, type in `cat /proc/mdstat`.  The output should look like the following:
 
If you want to check on the status of your RAID drive, type in `cat /proc/mdstat`.  The output should look like the following:
 
<pre><nowiki>
 
<pre><nowiki>
第220行: 第137行:
 
md0 : active raid1 hda1[1] sda1[1]
 
md0 : active raid1 hda1[1] sda1[1]
 
5237056 blocks [2/2] [UU]
 
5237056 blocks [2/2] [UU]
 
 
unused devices: <none> </nowiki></pre>
 
unused devices: <none> </nowiki></pre>
 
 
To see a listing of your LVM volumes groups, use `sudo vgdisplay`.  The display on my system looks like this:  
 
To see a listing of your LVM volumes groups, use `sudo vgdisplay`.  The display on my system looks like this:  
 
<pre><nowiki>
 
<pre><nowiki>
第245行: 第160行:
 
Free  PE / Size      0 / 0
 
Free  PE / Size      0 / 0
 
VG UUID              3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo</nowiki></pre>
 
VG UUID              3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo</nowiki></pre>
 
 
To see a listing of your logical volumes, use `sudo lvdisplay`.  This command outputs the following in my system:  
 
To see a listing of your logical volumes, use `sudo lvdisplay`.  This command outputs the following in my system:  
 
<pre><nowiki>
 
<pre><nowiki>
第261行: 第175行:
 
Read ahead sectors    0
 
Read ahead sectors    0
 
Block device          253:0
 
Block device          253:0
 
 
--- Logical volume ---
 
--- Logical volume ---
 
LV Name                /dev/asanoVG/root
 
LV Name                /dev/asanoVG/root
第275行: 第188行:
 
Read ahead sectors    0
 
Read ahead sectors    0
 
Block device          253:1
 
Block device          253:1
 
 
--- Logical volume ---
 
--- Logical volume ---
 
LV Name                /dev/asanoVG/swap
 
LV Name                /dev/asanoVG/swap
第289行: 第201行:
 
Read ahead sectors    0
 
Read ahead sectors    0
 
Block device          253:2
 
Block device          253:2
 
 
--- Logical volume ---
 
--- Logical volume ---
 
LV Name                /dev/asanoVG/home
 
LV Name                /dev/asanoVG/home
第303行: 第214行:
 
Read ahead sectors    0
 
Read ahead sectors    0
 
Block device          253:3</nowiki></pre>
 
Block device          253:3</nowiki></pre>
 
 
''And the hard part is over!  (I hope!)''
 
''And the hard part is over!  (I hope!)''
 
 
== Setting up FTP, Samba, and SSH ==
 
== Setting up FTP, Samba, and SSH ==
 
 
Now I built this system for a specific purpose, and here I get to actually setup and use it for that purpose.  In anycase, the above section can easily apply to any server, desktop, or even workstation purpose, but I want a local FTP, Samba, and SSH server.  Please note that I will be using vsFTPd server for the FTP server.  But first things first:
 
Now I built this system for a specific purpose, and here I get to actually setup and use it for that purpose.  In anycase, the above section can easily apply to any server, desktop, or even workstation purpose, but I want a local FTP, Samba, and SSH server.  Please note that I will be using vsFTPd server for the FTP server.  But first things first:
 
 
=== Dist-upgrade of base system ===
 
=== Dist-upgrade of base system ===
 
 
For the first thing after a base install, I usually do a `dist-upgrade` to get my kernel version current and to properly setup LILO to use the new kernel.  Before that, I also usually disable the CD as a source, so do `sudo nano /etc/apt/sources.list`, put a `#` in front of the line listing the CD-Rom, then `Ctrl-X` to save and exit.  Then do your  update then dist-upgrade using your favorite packager (I.E., `sudo apt-get update; sudo apt-get dist-upgrade`).   
 
For the first thing after a base install, I usually do a `dist-upgrade` to get my kernel version current and to properly setup LILO to use the new kernel.  Before that, I also usually disable the CD as a source, so do `sudo nano /etc/apt/sources.list`, put a `#` in front of the line listing the CD-Rom, then `Ctrl-X` to save and exit.  Then do your  update then dist-upgrade using your favorite packager (I.E., `sudo apt-get update; sudo apt-get dist-upgrade`).   
 
 
LILO will ask to '''Install a boot block using the existing /etc/lilo.conf? [Yes]''', and say `Yes` to that.  Once it finishes reboot with `sudo reboot`.   
 
LILO will ask to '''Install a boot block using the existing /etc/lilo.conf? [Yes]''', and say `Yes` to that.  Once it finishes reboot with `sudo reboot`.   
 
 
=== Setup network interfaces ===
 
=== Setup network interfaces ===
 
 
First we shall setup the server to use a static IP address.  Edit the `/etc/network/interfaces` file and modify the entry for eth0 to something like the following (Inserting your own network values, of course):
 
First we shall setup the server to use a static IP address.  Edit the `/etc/network/interfaces` file and modify the entry for eth0 to something like the following (Inserting your own network values, of course):
 
<pre><nowiki>
 
<pre><nowiki>
第327行: 第230行:
 
broadcast      192.168.1.255
 
broadcast      192.168.1.255
 
gateway        192.168.1.1</nowiki></pre>
 
gateway        192.168.1.1</nowiki></pre>
 
 
Modify your hosts file to use this static address for the host name by editing `/etc/hosts` with something similar to the following line:  
 
Modify your hosts file to use this static address for the host name by editing `/etc/hosts` with something similar to the following line:  
 
<pre><nowiki>
 
<pre><nowiki>
 
192.168.1.10    asano.br.br.cox.net    asano</nowiki></pre>
 
192.168.1.10    asano.br.br.cox.net    asano</nowiki></pre>
 
 
Finally setup your DNS server entry by editing `/etc/resolv.conf` to something similar to:
 
Finally setup your DNS server entry by editing `/etc/resolv.conf` to something similar to:
 
<pre><nowiki>
 
<pre><nowiki>
第337行: 第238行:
 
nameserver  192.168.1.1
 
nameserver  192.168.1.1
 
nameserver  192.168.1.2</nowiki></pre>
 
nameserver  192.168.1.2</nowiki></pre>
 
 
Restart the system by running `sudo reboot`.  ''Update with command that does not require reboot!''
 
Restart the system by running `sudo reboot`.  ''Update with command that does not require reboot!''
 
 
=== Installing server software ===
 
=== Installing server software ===
 
 
Installing is the simple part.  Install the following packages:  
 
Installing is the simple part.  Install the following packages:  
 
<pre><nowiki>
 
<pre><nowiki>
 
ssh openssh-server vsftpd samba </nowiki></pre>
 
ssh openssh-server vsftpd samba </nowiki></pre>
 
 
=== Configuring server software ===
 
=== Configuring server software ===
 
 
==== SSH ====
 
==== SSH ====
 
 
SSH was ready 'right out of the box' for me, though you may customize it by editing `/etc/ssh/sshd_config`.  The ssh daemon (server) <code><nowiki>sshd</nowiki></code> can be controlled through the associated init script.  To restart it, for example,
 
SSH was ready 'right out of the box' for me, though you may customize it by editing `/etc/ssh/sshd_config`.  The ssh daemon (server) <code><nowiki>sshd</nowiki></code> can be controlled through the associated init script.  To restart it, for example,
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/ssh restart
 
sudo /etc/init.d/ssh restart
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Verify the installation by logging in with a client SSH program from another system.
 
Verify the installation by logging in with a client SSH program from another system.
 
 
==== FTP ====
 
==== FTP ====
 
 
vsftpd requires some modifying to work like I need it too.  Mainly, I wish to disable the anonymous login and let local users login and upload files, so I will open up /etc/vsftpd.conf and change the following entries:  
 
vsftpd requires some modifying to work like I need it too.  Mainly, I wish to disable the anonymous login and let local users login and upload files, so I will open up /etc/vsftpd.conf and change the following entries:  
 
<pre><nowiki>
 
<pre><nowiki>
第366行: 第258行:
 
local_umask=022
 
local_umask=022
 
ftpd_banner=Welcome to asano local FTP server.</nowiki></pre>
 
ftpd_banner=Welcome to asano local FTP server.</nowiki></pre>
 
 
Save the file and tell the server to restart vsftp  
 
Save the file and tell the server to restart vsftp  
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/vsftpd restart
 
sudo /etc/init.d/vsftpd restart
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
Finally, test logging in with a client FTP program from another system.
 
Finally, test logging in with a client FTP program from another system.
 
 
==== Samba ====
 
==== Samba ====
 
 
Configure Samba by editing `/etc/samba/smb.conf`.  I do the following changes:  
 
Configure Samba by editing `/etc/samba/smb.conf`.  I do the following changes:  
 
<pre><nowiki>
 
<pre><nowiki>
第382行: 第269行:
 
security = user
 
security = user
 
guest account = nobody
 
guest account = nobody
 
 
[homes]
 
[homes]
 
comment = Home Directories
 
comment = Home Directories
第390行: 第276行:
 
create mask = 0644
 
create mask = 0644
 
directory mask = 0755
 
directory mask = 0755
 
 
[public]
 
[public]
 
comment = Public share
 
comment = Public share
第399行: 第284行:
 
create mask = 0666
 
create mask = 0666
 
directory mask = 0777</nowiki></pre>
 
directory mask = 0777</nowiki></pre>
 
 
I then make sure to create the public directory with the following commands:  
 
I then make sure to create the public directory with the following commands:  
 
<pre><nowiki>
 
<pre><nowiki>
第405行: 第289行:
 
sudo chmod 0777 /home/public
 
sudo chmod 0777 /home/public
 
sudo chown nobody:nogroup /home/public</nowiki></pre>
 
sudo chown nobody:nogroup /home/public</nowiki></pre>
 
 
Restart Samba with:
 
Restart Samba with:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo /etc/init.d/samba restart
 
sudo /etc/init.d/samba restart
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Don't forget to setup users with `sudo smbpasswd <username>` to give them access to windows shares.   
 
Don't forget to setup users with `sudo smbpasswd <username>` to give them access to windows shares.   
 
 
Test the setup by accessing the server and writing and reading files on the shares.
 
Test the setup by accessing the server and writing and reading files on the shares.
 
 
== Adding hard drives ==
 
== Adding hard drives ==
 
 
Now we come to the fun part: Expanding the file system!  Say we get two new hard drives to add to the server (in this example,  two pathetic little 2 gig drives... ;) ).  So we install them, start up the server, and now what?
 
Now we come to the fun part: Expanding the file system!  Say we get two new hard drives to add to the server (in this example,  two pathetic little 2 gig drives... ;) ).  So we install them, start up the server, and now what?
 
 
=== Finding the drives ===
 
=== Finding the drives ===
 
 
First, we need to find out how to access the new drives.  One thing that may give a clue is to run `cat /proc/partitions`.  ''Need to better show how to find out where the new drives are mounted!''
 
First, we need to find out how to access the new drives.  One thing that may give a clue is to run `cat /proc/partitions`.  ''Need to better show how to find out where the new drives are mounted!''
 
 
=== Setting up RAID ===
 
=== Setting up RAID ===
 
 
Once we figure out how they are represented in the server (in my server's case, `/dev/hdb` and `/dev/hdd`), they will have to be first setup in a new RAID array.  For this, I will use fdisk for each drive.  It would be advisable to start with the smaller drive and use the same number of cylinders on the larger drive.  I also set the type of each partition to `fd`, the code for Linux raid autodetect.  
 
Once we figure out how they are represented in the server (in my server's case, `/dev/hdb` and `/dev/hdd`), they will have to be first setup in a new RAID array.  For this, I will use fdisk for each drive.  It would be advisable to start with the smaller drive and use the same number of cylinders on the larger drive.  I also set the type of each partition to `fd`, the code for Linux raid autodetect.  
 
<pre><nowiki>
 
<pre><nowiki>
第432行: 第307行:
 
until you decide to write them. After that, of course, the previous
 
until you decide to write them. After that, of course, the previous
 
content won't be recoverable.
 
content won't be recoverable.
 
 
 
The number of cylinders for this disk is set to 4161.
 
The number of cylinders for this disk is set to 4161.
 
There is nothing wrong with that, but this is larger than 1024,
 
There is nothing wrong with that, but this is larger than 1024,
第441行: 第314行:
 
(e.g., DOS FDISK, OS/2 FDISK)
 
(e.g., DOS FDISK, OS/2 FDISK)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
Command (m for help):  n
 
Command (m for help):  n
 
Command action
 
Command action
第452行: 第324行:
 
Last cylinder or +size or +sizeM or +sizeK (1-4161, default 4161):
 
Last cylinder or +size or +sizeM or +sizeK (1-4161, default 4161):
 
Using default value 4161
 
Using default value 4161
 
 
Command (m for help):  t
 
Command (m for help):  t
 
Selected partition 1
 
Selected partition 1
 
Hex code (type L to list codes): fd
 
Hex code (type L to list codes): fd
 
 
Command (m for help): p
 
Command (m for help): p
 
 
Disk /dev/hdb: 2147 MB, 2147483648 bytes
 
Disk /dev/hdb: 2147 MB, 2147483648 bytes
 
16 heads, 63 sectors/track, 4161 cylinders
 
16 heads, 63 sectors/track, 4161 cylinders
 
Units == cylinders of 1008 * 512 == 516096 bytes
 
Units == cylinders of 1008 * 512 == 516096 bytes
 
 
Device Boot      Start        End      Blocks  Id  System
 
Device Boot      Start        End      Blocks  Id  System
 
/dev/hdb1              1        4161    2097112+  fd  Linux raid autodetect
 
/dev/hdb1              1        4161    2097112+  fd  Linux raid autodetect
 
 
Command (m for help):  w
 
Command (m for help):  w
 
The partition table has been altered!
 
The partition table has been altered!
 
 
Calling ioctl() to re-read partition table.
 
Calling ioctl() to re-read partition table.
 
Syncing disks.
 
Syncing disks.
第476行: 第342行:
 
until you decide to write them. After that, of course, the previous
 
until you decide to write them. After that, of course, the previous
 
content won't be recoverable.
 
content won't be recoverable.
 
 
 
The number of cylinders for this disk is set to 4369.
 
The number of cylinders for this disk is set to 4369.
 
There is nothing wrong with that, but this is larger than 1024,
 
There is nothing wrong with that, but this is larger than 1024,
第485行: 第349行:
 
(e.g., DOS FDISK, OS/2 FDISK)
 
(e.g., DOS FDISK, OS/2 FDISK)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
Command (m for help): n
 
Command (m for help): n
 
Command action
 
Command action
第495行: 第358行:
 
Using default value 1
 
Using default value 1
 
Last cylinder or +size or +sizeM or +sizeK (1-4369, default 4369): 4161
 
Last cylinder or +size or +sizeM or +sizeK (1-4369, default 4369): 4161
 
 
Command (m for help): t
 
Command (m for help): t
 
Selected partition 1
 
Selected partition 1
 
Hex code (type L to list codes): fd
 
Hex code (type L to list codes): fd
 
Changed system type of partition 1 to fd (Linux raid autodetect)
 
Changed system type of partition 1 to fd (Linux raid autodetect)
 
 
Command (m for help): p
 
Command (m for help): p
 
 
Disk /dev/hdd: 2254 MB, 2254857728 bytes
 
Disk /dev/hdd: 2254 MB, 2254857728 bytes
 
16 heads, 63 sectors/track, 4369 cylinders
 
16 heads, 63 sectors/track, 4369 cylinders
 
Units == cylinders of 1008 * 512 == 516096 bytes
 
Units == cylinders of 1008 * 512 == 516096 bytes
 
 
Device Boot      Start        End      Blocks  Id  System
 
Device Boot      Start        End      Blocks  Id  System
 
/dev/hdd1              1        4161    2097112+  fd  Linux raid autodetect
 
/dev/hdd1              1        4161    2097112+  fd  Linux raid autodetect
 
 
Command (m for help): w
 
Command (m for help): w
 
The partition table has been altered!
 
The partition table has been altered!
 
 
Calling ioctl() to re-read partition table.
 
Calling ioctl() to re-read partition table.
 
Syncing disks.
 
Syncing disks.
 
$</nowiki></pre>
 
$</nowiki></pre>
 
 
Once the two partitions are created, we use the mdadm command to create and build the new array:  
 
Once the two partitions are created, we use the mdadm command to create and build the new array:  
 
<pre><nowiki>
 
<pre><nowiki>
 
$ sudo mdadm --create --verbose /dev/md1 --level=raid1 --raid-devices=2 /dev/hdb1 /dev/hdd1</nowiki></pre>
 
$ sudo mdadm --create --verbose /dev/md1 --level=raid1 --raid-devices=2 /dev/hdb1 /dev/hdd1</nowiki></pre>
 
 
The RAID system will sync the drives in the background.  We are now free to setup the new array and expand the existing Volume Group into it!
 
The RAID system will sync the drives in the background.  We are now free to setup the new array and expand the existing Volume Group into it!
 
 
=== Expanding the LVM Volume Group ===
 
=== Expanding the LVM Volume Group ===
 
 
Before we can expand the volume group we created (On my system, named `asanoVG`.  You can remind yourself using the `sudo vgdisplay` command), we need to initialize the new RAID array with:  
 
Before we can expand the volume group we created (On my system, named `asanoVG`.  You can remind yourself using the `sudo vgdisplay` command), we need to initialize the new RAID array with:  
 
<pre><nowiki>
 
<pre><nowiki>
第530行: 第383行:
 
Physical volume "/dev/md1" successfully created
 
Physical volume "/dev/md1" successfully created
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
Then we add this physical volume to our volume group:  
 
Then we add this physical volume to our volume group:  
 
<pre><nowiki>
 
<pre><nowiki>
第536行: 第388行:
 
Volume group "asanoVG" successfully extended
 
Volume group "asanoVG" successfully extended
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
If you now run vgdisplay, you will now notice we have free space available in our volume group:  
 
If you now run vgdisplay, you will now notice we have free space available in our volume group:  
 
<pre><nowiki>
 
<pre><nowiki>
第560行: 第411行:
 
Free  PE / Size      511 / 2.00 GB
 
Free  PE / Size      511 / 2.00 GB
 
VG UUID              3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo
 
VG UUID              3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo
 
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
=== Expanding Logical Volume and Filesystem ===
 
=== Expanding Logical Volume and Filesystem ===
 
 
In this case, I want to extend my `home` logical volume the rest of the drive.  The easier way to do this is to use the Free PE (511 in the display above) to expand the drive, by doing the following:  
 
In this case, I want to extend my `home` logical volume the rest of the drive.  The easier way to do this is to use the Free PE (511 in the display above) to expand the drive, by doing the following:  
 
<pre><nowiki>
 
<pre><nowiki>
第571行: 第419行:
 
Logical volume home successfully resized
 
Logical volume home successfully resized
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
Now for the home stretch!  Since I had the foresight to use the XFS file system, I can simply run the following:
 
Now for the home stretch!  Since I had the foresight to use the XFS file system, I can simply run the following:
 
<pre><nowiki>
 
<pre><nowiki>
第585行: 第432行:
 
data blocks changed from 496640 to 1019904
 
data blocks changed from 496640 to 1019904
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
If you used ext3fs, it's still easy to resize, you just have to unmount it first.  If this is /home, log out as a user, stop anything that uses /home, and log in as root.  You need a root password for this.  It may be easier to just boot with a live cd if you can't unmount.  The commands `lsof` and `fuser` will give you information about what files are being used on a filesystem.
 
If you used ext3fs, it's still easy to resize, you just have to unmount it first.  If this is /home, log out as a user, stop anything that uses /home, and log in as root.  You need a root password for this.  It may be easier to just boot with a live cd if you can't unmount.  The commands `lsof` and `fuser` will give you information about what files are being used on a filesystem.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
umount /home
 
umount /home
第594行: 第439行:
 
mount /home
 
mount /home
 
</nowiki></pre>
 
</nowiki></pre>
 
 
`e2fsck` is a good idea to make sure the filesystem is in a consistent state before resizing.
 
`e2fsck` is a good idea to make sure the filesystem is in a consistent state before resizing.
 
 
And I'm finished!  I have now expanded my /home partition by adding another drive.
 
And I'm finished!  I have now expanded my /home partition by adding another drive.
 
 
To compare the drive sizes, here's before:  
 
To compare the drive sizes, here's before:  
 
<pre><nowiki>
 
<pre><nowiki>
第613行: 第455行:
 
/dev/mapper/asanoVG-home
 
/dev/mapper/asanoVG-home
 
2.1G  121M  2.0G  6% /home</nowiki></pre>
 
2.1G  121M  2.0G  6% /home</nowiki></pre>
 
 
And here's after:  
 
And here's after:  
 
<pre><nowiki>
 
<pre><nowiki>
第628行: 第469行:
 
/dev/mapper/asanoVG-home
 
/dev/mapper/asanoVG-home
 
4.2G  121M  4.1G  3% /home</nowiki></pre>
 
4.2G  121M  4.1G  3% /home</nowiki></pre>
 
 
=== Other help on LVM ===
 
=== Other help on LVM ===
 
 
For more information on administrating LVM, use [http://www.tldp.org/HOWTO/LVM-HOWTO/index.html this very informative HOW-TO].
 
For more information on administrating LVM, use [http://www.tldp.org/HOWTO/LVM-HOWTO/index.html this very informative HOW-TO].
 
 
== Recovering from failed drive ==
 
== Recovering from failed drive ==
 
 
So now your server has been running and being used for some time.  Maybe you've even added several new drives.  Say one day, you run `cat /proc/mdstat` and receive the following output:   
 
So now your server has been running and being used for some time.  Maybe you've even added several new drives.  Say one day, you run `cat /proc/mdstat` and receive the following output:   
 
<pre><nowiki>
 
<pre><nowiki>
 
Personalities : [raid1]
 
Personalities : [raid1]
 
 
md1 : active raid1 sda1[1]
 
md1 : active raid1 sda1[1]
 
5237056 blocks [2/1] [_U]
 
5237056 blocks [2/1] [_U]
 
 
md0 : active raid1 hda1[0] hdd1[1]
 
md0 : active raid1 hda1[0] hdd1[1]
 
2097024 blocks [2/2] [UU]
 
2097024 blocks [2/2] [UU]
 
 
unused devices: <none></nowiki></pre>
 
unused devices: <none></nowiki></pre>
 
 
What the?  Didn't one of the arrays have two working drives?  Looks like our md1 array has degraded, and you're off to the store/online to get a replacement.  Install it into the system, start it up, and find out how the drive is accessed (In my case, it's `/dev/sdb').
 
What the?  Didn't one of the arrays have two working drives?  Looks like our md1 array has degraded, and you're off to the store/online to get a replacement.  Install it into the system, start it up, and find out how the drive is accessed (In my case, it's `/dev/sdb').
 
 
First, we want to look at the size of the partition on /dev/sda, so I'll be using fdisk:  
 
First, we want to look at the size of the partition on /dev/sda, so I'll be using fdisk:  
 
<pre><nowiki>
 
<pre><nowiki>
 
$ sudo fdisk /dev/sda
 
$ sudo fdisk /dev/sda
 
Password:
 
Password:
 
 
Command (m for help): p
 
Command (m for help): p
 
 
Disk /dev/sda: 5476 MB, 5476083200 bytes
 
Disk /dev/sda: 5476 MB, 5476083200 bytes
 
255 heads, 63 sectors/track, 665 cylinders
 
255 heads, 63 sectors/track, 665 cylinders
 
Units == cylinders of 16065 * 512 == 8225280 bytes
 
Units == cylinders of 16065 * 512 == 8225280 bytes
 
 
Device Boot      Start        End      Blocks  Id  System
 
Device Boot      Start        End      Blocks  Id  System
 
/dev/sda1  *          1        657    5277321  fd  Linux raid autodetect
 
/dev/sda1  *          1        657    5277321  fd  Linux raid autodetect
 
 
Command (m for help): q
 
Command (m for help): q
 
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
Now configure /dev/sdb with a raid partition of the same size.  Don't forget to make it bootable:  
 
Now configure /dev/sdb with a raid partition of the same size.  Don't forget to make it bootable:  
 
<pre><nowiki>
 
<pre><nowiki>
第674行: 第500行:
 
until you decide to write them. After that, of course, the previous
 
until you decide to write them. After that, of course, the previous
 
content won't be recoverable.
 
content won't be recoverable.
 
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 
Command (m for help): n
 
Command (m for help): n
 
Command action
 
Command action
第686行: 第510行:
 
Using default value 1
 
Using default value 1
 
Last cylinder or +size or +sizeM or +sizeK (1-665, default 665): 657
 
Last cylinder or +size or +sizeM or +sizeK (1-665, default 665): 657
 
 
Command (m for help): t
 
Command (m for help): t
 
Selected partition 1
 
Selected partition 1
 
Hex code (type L to list codes): fd
 
Hex code (type L to list codes): fd
 
Changed system type of partition 1 to fd (Linux raid autodetect)
 
Changed system type of partition 1 to fd (Linux raid autodetect)
 
 
Command (m for help): a
 
Command (m for help): a
 
Partition number (1-4): 1
 
Partition number (1-4): 1
 
 
Command (m for help): p
 
Command (m for help): p
 
 
Disk /dev/sdb: 5476 MB, 5476083200 bytes
 
Disk /dev/sdb: 5476 MB, 5476083200 bytes
 
255 heads, 63 sectors/track, 665 cylinders
 
255 heads, 63 sectors/track, 665 cylinders
 
Units == cylinders of 16065 * 512 == 8225280 bytes
 
Units == cylinders of 16065 * 512 == 8225280 bytes
 
 
Device Boot      Start        End      Blocks  Id  System
 
Device Boot      Start        End      Blocks  Id  System
 
/dev/sdb1  *          1        657    5277321  fd  Linux raid autodetect
 
/dev/sdb1  *          1        657    5277321  fd  Linux raid autodetect
 
 
Command (m for help): w
 
Command (m for help): w
 
The partition table has been altered!
 
The partition table has been altered!
 
 
Calling ioctl() to re-read partition table.
 
Calling ioctl() to re-read partition table.
 
Syncing disks.
 
Syncing disks.
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
Now run the following to add the partition to the array:  
 
Now run the following to add the partition to the array:  
 
<pre><nowiki>
 
<pre><nowiki>
第716行: 第532行:
 
mdadm: hot added /dev/sdb1
 
mdadm: hot added /dev/sdb1
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
The RAID system will automatically start syncing the drives and you're free to continue on your way.  If you look at mdstats, it'll look like this:   
 
The RAID system will automatically start syncing the drives and you're free to continue on your way.  If you look at mdstats, it'll look like this:   
 
<pre><nowiki>
 
<pre><nowiki>
第724行: 第539行:
 
5237056 blocks [2/1] [_U]
 
5237056 blocks [2/1] [_U]
 
[>....................]  recovery =  2.5% (133056/5237056) finish=21.5min speed=3949K/sec
 
[>....................]  recovery =  2.5% (133056/5237056) finish=21.5min speed=3949K/sec
 
 
md0 : active raid1 hda1[0] hdd1[1]
 
md0 : active raid1 hda1[0] hdd1[1]
 
2097024 blocks [2/2] [UU]
 
2097024 blocks [2/2] [UU]
 
 
unused devices: <none>
 
unused devices: <none>
 
$ </nowiki></pre>
 
$ </nowiki></pre>
 
 
== Final Statements ==
 
== Final Statements ==
 
 
I do hope this guide has been informative and helpful to you.  I will be using it myself on a server as a reference for different tasks.   
 
I do hope this guide has been informative and helpful to you.  I will be using it myself on a server as a reference for different tasks.   
 
 
== External Links ==
 
== External Links ==
 
*[http://www.debian-administration.org/articles/424 Add disks to RAID array without rebooting]
 
*[http://www.debian-administration.org/articles/424 Add disks to RAID array without rebooting]

2007年11月30日 (五) 17:14的版本

WARNING UPDATE!

Note from NicholasIstre: The server I was testing this setup on had failed on a bootup with a kernel-panic (*slaps forehead for not writing the exact error down...*) a couple of bootups after I added a new RAID1 array to the main volume group. Depending on further testing and discussion with the community, I may modify these instructions to have a /boot or even the root filesystem on the RAID1 outside of the LVM partition.

Introduction

As I've collected a fair amount of hardware, I decided that I wanted to create a small file server with a few hard drives and a spare system I had lying around, like many others probably have done. I also wanted RAID1 capability and the ability to add to the system, though not necessarily through hot-plugging, though I'm sure this HOW-TO can provide a jump-point if you have such hardware available. No, I'm working with old-fashioned IDE drives, and I want to have a place that I can pretty reliably store anime and music that I... ahem... acquire... Unfortunately, the documentation for LVM and Software RAID is a bit sparse. Among others, I've read UbuntuHelp:Installation/LVMOnRaid, this very helpful LVM HOW-TO, this software RAID HOW-TO, and this Linux RAID FAQ, but they only really provided the tools and hints. I had to figure out how to setup this server by myself, it seems. And, for more things for me to do, the only hardware I have available for this are a P-III system with 2 onboard PATA-100, a DVD/CD reader, a network card, 2 60-Gig drive, 2 120-Gig drives, and necessary cables for all. If you didn't notice, I have connections for 4 IDE devices, where as I have 5 that I want to use. Even worse, I'd have to master/slave two of the Hard drives together, which is pretty much a no-no. So off I go to my trusty online computer parts retailer and order a PCI card with two more ATA-133 connections. In the meantime, I still would like to put something together that would provide me with 2 of the hard drives until the IDE card comes in, where I will install it with the other 2 hard drives, RAID 1 them, then extend the existing filesystems onto that. So, I've given you the hardware I have. I will be using the Ubuntu 6.06 Server CD to do the following on LVM on RAID 1:

  • FTP Server (only for my local network, to use with Acronis True Image software)
  • SMB Server (for windows sharing)
  • SSH Server (pretty standard on all of my server setups)

I will be creating this HOW-TO for my own reference, especially when I go and upgrade the fileserver with more harddrives. I will be using VMWare Server software on a laptop to provide screenshots and help along when writing this article (So, feel sorry for me as this poor 4500 RPM drive will have to pretend to be up to 4 drives in RAID 1 format...) Please note, anything in italics will be me asking the community for help on certain things. Now, onto the actual HOW-TO...

Install

Setup the system to boot from the CD and boot-up your trusty Ubuntu 6.06 Server CD Ubuntu6_06Start.png Choose Install to the hard disk and press ENTER. You will then proceed to choose your language, location, and keyboard layout. 2ChooseLanguage.png 3ChooseLocation.png 4ChooseKeyboardLayout.png Enter the hostname of your server. 5SetHostName.png

Setting up RAID

/!\ This section is incorrect. Setup a /boot section outside of the LVM by creating two RAID 1 arrays, the boot section being at least 200 MBs or so. Be sure to verify/setup the /boot partition after setting up the LVM. Select Manually edit partition table 6ManualPartition.png Select each drive and select Yes to create new empty partition tables. 7SetupPartitionTables.png 8SetupPartitionTables.png 9EmptyPartitions.png Now pick the smaller drive, move to the line saying FREE SPACE under it, and press ENTER. 10ChooseFREESPACE.png Create a new primary partition and keep the default size to use the full disk. 11CreateaNewPartition.png 12ChooseFullDisk.png Remember this value when creating the partition on the larger disk! Not necessary if both disks are exactly the same size. I do not know how the RAID 1 would work with different size partitions 13SetPrimaryType.png Change the partition type to RAID, set the bootable flag, and you're done with this disk! 14ChangeUseAs.png 15ChoosephysicalvolumeforRAID.png 16SetBootableFlag.png 17Donesettingupthepartition.png Do the same process on the other disk, but set the size of the partition as the same as the other disk, if they are different sizes. Choose Beginning if asked where to place the partition. 18SetupOtherDrive.png 19CreateaNewPartition2.png 20SetSize.png 21SelectPrimary.png 22ChooseBeginning.png 23ChooseUseAs.png 24ChoosephysicalvolumeforRAID.png 25SetBootableflag.png 26DoneWithDisk.png Now that both disks are setup, we need to setup the Software RAID. Say yes to write the changes to disk and select Create MD device. 27ConfiguresoftwareRAID.png 28WriteChangesToDisk.png 29CreateMDdevice.png Select RAID1, choose 2 Active Devices, 0 Spares, Select the two RAID partitions you just created, and you're now finished with setting up the RAID. 30ChooseRAID1.png 31Set2ActiveDevices.png 32Set0SpareDevices.png 33SelectActiveDevices.png 34FinishRAIDSetup.png

Setting up LVM

We now have a Software RAID device to play with, so select that device's space to set it up to use as a physical volume for LVM, and Done setting up the partition. 35SelectingRAIDPartition.png 36SelectUseAs.png 37SelectphysicalvolumeforLVM.png 38Donesettingupthepartition.png Now that we have a physical LVM volume, select Configure the Logical Volume Manager, and write the changes to disk. 39ConfiguretheLogicalVolumeManager.png 40WriteChangesToDisks.png /!\ I got an error here, but when I chose Ignore and continued on with the rest of the setup, it seems to install and setup just fine. (!) I find that waiting until the RAID arrays finish syncing will cause fewer issues after the install. Switch to another terminal using ALT-F2 and run "cat /proc/mdstat/" until the arrays are finished syncing (This may take some time, depending on how large the hard drives are). Once it is finished, switch back to the installer with ALT-F1. 41Error.png Setup the Volume Group using the physical LVM volume we just created. 42ModifyVG.png 43CreateVolumeGroups.png 44SelectDevice.png Choose whatever name you wish. Since I will only have one volume group, I'm including the name of the server in the name. Once the name is picked, you can leave the volume group configuration menu. 45SetVolumeGroupName.png 46LeaveVolumeGroupConfig.png We will now create our logical volumes. I will be making 4, for the root, /boot, /home, and swap areas. For simplicity, I will name them "root", "boot", "home", and "swap". 47ModifyLogicalVolumes.png 48CreateLogicalVolumes.png 49CreateBootLV.png 50ChooseVG.png 51SetSize.png 52CreateLV.png 53CreateRootLV.png 54SelectVG.png 55SetSize.png I will continue with making a "swap" logical volume that's 1 gig, and a "home" logical volume that takes up the rest of the drive. Now that the LVs are setup, leave the LVM configuration menu. 56LeaveLVMConfigurationMenu.png

Setting up filesystem

We now have the four logical volumes (or however many you setup) in the partition list ready to be setup. Select each one and configure them as wanted. You may notice that I used the XFS filesystem for root and /home because it can be expanded on the fly, while (from what I can tell) ext3 has to be unmounted to be resized. Some of the others have this ability, though. Help for filesystem advice here would be appreciated! 57PartitionList.png 58BootUseAs.png 59BootExt3.png 60MountPoint.png 61boot.png 62done.png 63LVsetup.png Now that the partitions are how we like them, we will finish with setting up the disks. Please note that same error comes back, but we will ignore it again. The system will then start setting up the filesystem for you. 64FinishedPartitioningDisks.png 65WriteChangesToDisk.png 66ErrorAgain.png

Finishing up Install

Setup your Timezone and UTC information. 67SetTimeZone.png 68SetUTC.png Setup your initial user and password. 69SetupUserName.png 70SetupUserLogin.png 71SetPassword.png 72ConfirmPassword.png The installer will now starting copying packages and setting up your new server 73InstallingSystem.png Setup LILO by selecting the default option, /dev/md0: software RAID array 74SetupLILO.png Again, the installer tells you something fails, in this case LILO installation, but continue anyways. 75ContinueAfterFailure.png Installation complete! Or so says the installer. Remove your trusty Ubuntu 6.06 Server CD and select continue. Cross your fingers as it reboots... 76InstallComplete.png ...and success! Well, in my case. Your mileage may vary. 77FirstBoot.png Now we have a base Ubuntu Server installation up and running, on LVM on RAID1 no doubt!

Verifying installation

If you want to check on the status of your RAID drive, type in `cat /proc/mdstat`. The output should look like the following:

Personalities : [raid1]
md0 : active raid1 hda1[1] sda1[1]
5237056 blocks [2/2] [UU]
unused devices: <none> 

To see a listing of your LVM volumes groups, use `sudo vgdisplay`. The display on my system looks like this:

--- Volume group ---
VG Name               asanoVG
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  5
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                4
Open LV               4
Max PV                0
Cur PV                1
Act PV                1
VG Size               4.99 GB
PE Size               4.00 MB
Total PE              1278
Alloc PE / Size       1278 / 4.99 GB
Free  PE / Size       0 / 0
VG UUID               3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo

To see a listing of your logical volumes, use `sudo lvdisplay`. This command outputs the following in my system:

--- Logical volume ---
LV Name                /dev/asanoVG/boot
VG Name                asanoVG
LV UUID                b4VHMI-Axz7-p8xF-3FU5-PQtC-5t6A-MIe1t8
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                100.00 MB
Current LE             25
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:0
--- Logical volume ---
LV Name                /dev/asanoVG/root
VG Name                asanoVG
LV UUID                x64Jyr-H6ZA-g3IH-cZKd-7sdp-mEL5-nRm8kJ
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                2.00 GB
Current LE             512
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:1
--- Logical volume ---
LV Name                /dev/asanoVG/swap
VG Name                asanoVG
LV UUID                T9c18T-9aH3-6DZF-OuQX-Iu0f-M0fw-72tVbn
LV Write Access        read/write
LV Status              available
# open                 2
LV Size                1.00 GB
Current LE             256
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:2
--- Logical volume ---
LV Name                /dev/asanoVG/home
VG Name                asanoVG
LV UUID                eoodOA-zv2r-84Y7-y9a6-uzBo-A5q8-9TMCe5
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                1.89 GB
Current LE             485
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:3

And the hard part is over! (I hope!)

Setting up FTP, Samba, and SSH

Now I built this system for a specific purpose, and here I get to actually setup and use it for that purpose. In anycase, the above section can easily apply to any server, desktop, or even workstation purpose, but I want a local FTP, Samba, and SSH server. Please note that I will be using vsFTPd server for the FTP server. But first things first:

Dist-upgrade of base system

For the first thing after a base install, I usually do a `dist-upgrade` to get my kernel version current and to properly setup LILO to use the new kernel. Before that, I also usually disable the CD as a source, so do `sudo nano /etc/apt/sources.list`, put a `#` in front of the line listing the CD-Rom, then `Ctrl-X` to save and exit. Then do your update then dist-upgrade using your favorite packager (I.E., `sudo apt-get update; sudo apt-get dist-upgrade`). LILO will ask to Install a boot block using the existing /etc/lilo.conf? [Yes], and say `Yes` to that. Once it finishes reboot with `sudo reboot`.

Setup network interfaces

First we shall setup the server to use a static IP address. Edit the `/etc/network/interfaces` file and modify the entry for eth0 to something like the following (Inserting your own network values, of course):

# The primary network interface
auto eth0
iface eth0 inet static
address         192.168.1.10
netmask         255.255.255.0
broadcast       192.168.1.255
gateway         192.168.1.1

Modify your hosts file to use this static address for the host name by editing `/etc/hosts` with something similar to the following line:

192.168.1.10     asano.br.br.cox.net     asano

Finally setup your DNS server entry by editing `/etc/resolv.conf` to something similar to:

search br.br.cox.net
nameserver  192.168.1.1
nameserver  192.168.1.2

Restart the system by running `sudo reboot`. Update with command that does not require reboot!

Installing server software

Installing is the simple part. Install the following packages:

ssh openssh-server vsftpd samba 

Configuring server software

SSH

SSH was ready 'right out of the box' for me, though you may customize it by editing `/etc/ssh/sshd_config`. The ssh daemon (server) sshd can be controlled through the associated init script. To restart it, for example,

sudo /etc/init.d/ssh restart

Verify the installation by logging in with a client SSH program from another system.

FTP

vsftpd requires some modifying to work like I need it too. Mainly, I wish to disable the anonymous login and let local users login and upload files, so I will open up /etc/vsftpd.conf and change the following entries:

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
ftpd_banner=Welcome to asano local FTP server.

Save the file and tell the server to restart vsftp

sudo /etc/init.d/vsftpd restart

Finally, test logging in with a client FTP program from another system.

Samba

Configure Samba by editing `/etc/samba/smb.conf`. I do the following changes:

workgroup = HOUSE
security = user
guest account = nobody
[homes]
comment = Home Directories
browseable = yes
valid users = %S
writable = yes
create mask = 0644
directory mask = 0755
[public]
comment = Public share
path = /home/public
browseable = no
guest ok = yes
writable = yes
create mask = 0666
directory mask = 0777

I then make sure to create the public directory with the following commands:

sudo mkdir /home/public
sudo chmod 0777 /home/public
sudo chown nobody:nogroup /home/public

Restart Samba with:

sudo /etc/init.d/samba restart

Don't forget to setup users with `sudo smbpasswd <username>` to give them access to windows shares. Test the setup by accessing the server and writing and reading files on the shares.

Adding hard drives

Now we come to the fun part: Expanding the file system! Say we get two new hard drives to add to the server (in this example, two pathetic little 2 gig drives... ;) ). So we install them, start up the server, and now what?

Finding the drives

First, we need to find out how to access the new drives. One thing that may give a clue is to run `cat /proc/partitions`. Need to better show how to find out where the new drives are mounted!

Setting up RAID

Once we figure out how they are represented in the server (in my server's case, `/dev/hdb` and `/dev/hdd`), they will have to be first setup in a new RAID array. For this, I will use fdisk for each drive. It would be advisable to start with the smaller drive and use the same number of cylinders on the larger drive. I also set the type of each partition to `fd`, the code for Linux raid autodetect.

$ sudo fdisk /dev/hdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 4161.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help):  n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4161, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-4161, default 4161):
Using default value 4161
Command (m for help):  t
Selected partition 1
Hex code (type L to list codes): fd
Command (m for help): p
Disk /dev/hdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders
Units == cylinders of 1008 * 512 == 516096 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/hdb1               1        4161     2097112+  fd  Linux raid autodetect
Command (m for help):  w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo fdisk /dev/hdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 4369.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4369, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-4369, default 4369): 4161
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/hdd: 2254 MB, 2254857728 bytes
16 heads, 63 sectors/track, 4369 cylinders
Units == cylinders of 1008 * 512 == 516096 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/hdd1               1        4161     2097112+  fd  Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
$

Once the two partitions are created, we use the mdadm command to create and build the new array:

$ sudo mdadm --create --verbose /dev/md1 --level=raid1 --raid-devices=2 /dev/hdb1 /dev/hdd1

The RAID system will sync the drives in the background. We are now free to setup the new array and expand the existing Volume Group into it!

Expanding the LVM Volume Group

Before we can expand the volume group we created (On my system, named `asanoVG`. You can remind yourself using the `sudo vgdisplay` command), we need to initialize the new RAID array with:

$ sudo pvcreate /dev/md1
Physical volume "/dev/md1" successfully created
$ 

Then we add this physical volume to our volume group:

$  sudo vgextend asanoVG /dev/md1
Volume group "asanoVG" successfully extended
$ 

If you now run vgdisplay, you will now notice we have free space available in our volume group:

$ sudo vgdisplay
--- Volume group ---
VG Name               asanoVG
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  6
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                4
Open LV               4
Max PV                0
Cur PV                2
Act PV                2
VG Size               6.99 GB
PE Size               4.00 MB
Total PE              1789
Alloc PE / Size       1278 / 4.99 GB
Free  PE / Size       511 / 2.00 GB
VG UUID               3qgmFG-Mioc-R5ue-L3Aw-BNkF-IrhK-6HzIzo
$ 

Expanding Logical Volume and Filesystem

In this case, I want to extend my `home` logical volume the rest of the drive. The easier way to do this is to use the Free PE (511 in the display above) to expand the drive, by doing the following:

$ sudo lvextend -l+511 /dev/asanoVG/home
Extending logical volume home to 3.89 GB
Logical volume home successfully resized
$ 

Now for the home stretch! Since I had the foresight to use the XFS file system, I can simply run the following:

$ sudo xfs_growfs /home
meta-data=/dev/mapper/asanoVG-home isize=256    agcount=8, agsize=62080 blks
=                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=496640, imaxpct=25
=                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096
log      =internal               bsize=4096   blocks=2560, version=1
=                       sectsz=512   sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
data blocks changed from 496640 to 1019904
$ 

If you used ext3fs, it's still easy to resize, you just have to unmount it first. If this is /home, log out as a user, stop anything that uses /home, and log in as root. You need a root password for this. It may be easier to just boot with a live cd if you can't unmount. The commands `lsof` and `fuser` will give you information about what files are being used on a filesystem.

umount /home
e2fsck -f -C /dev/asanoVG/home
resize2fs /dev/asanoVG/home
mount /home

`e2fsck` is a good idea to make sure the filesystem is in a consistent state before resizing. And I'm finished! I have now expanded my /home partition by adding another drive. To compare the drive sizes, here's before:

$ df -H
Filesystem             Size   Used  Avail Use% Mounted on
/dev/mapper/asanoVG-root
2.2G   419M   1.8G  20% /
varrun                 264M    95k   264M   1% /var/run
varlock                264M   4.1k   264M   1% /var/lock
udev                   264M    74k   264M   1% /dev
devshm                 264M      0   264M   0% /dev/shm
/dev/mapper/asanoVG-boot
99M    25M    69M  26% /boot
/dev/mapper/asanoVG-home
2.1G   121M   2.0G   6% /home

And here's after:

$ df -H
Filesystem             Size   Used  Avail Use% Mounted on
/dev/mapper/asanoVG-root
2.2G   419M   1.8G  20% /
varrun                 264M    95k   264M   1% /var/run
varlock                264M   4.1k   264M   1% /var/lock
udev                   264M    74k   264M   1% /dev
devshm                 264M      0   264M   0% /dev/shm
/dev/mapper/asanoVG-boot
99M    25M    69M  26% /boot
/dev/mapper/asanoVG-home
4.2G   121M   4.1G   3% /home

Other help on LVM

For more information on administrating LVM, use this very informative HOW-TO.

Recovering from failed drive

So now your server has been running and being used for some time. Maybe you've even added several new drives. Say one day, you run `cat /proc/mdstat` and receive the following output:

Personalities : [raid1]
md1 : active raid1 sda1[1]
5237056 blocks [2/1] [_U]
md0 : active raid1 hda1[0] hdd1[1]
2097024 blocks [2/2] [UU]
unused devices: <none>

What the? Didn't one of the arrays have two working drives? Looks like our md1 array has degraded, and you're off to the store/online to get a replacement. Install it into the system, start it up, and find out how the drive is accessed (In my case, it's `/dev/sdb'). First, we want to look at the size of the partition on /dev/sda, so I'll be using fdisk:

$ sudo fdisk /dev/sda
Password:
Command (m for help): p
Disk /dev/sda: 5476 MB, 5476083200 bytes
255 heads, 63 sectors/track, 665 cylinders
Units == cylinders of 16065 * 512 == 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         657     5277321   fd  Linux raid autodetect
Command (m for help): q
$ 

Now configure /dev/sdb with a raid partition of the same size. Don't forget to make it bootable:

$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-665, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-665, default 665): 657
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb: 5476 MB, 5476083200 bytes
255 heads, 63 sectors/track, 665 cylinders
Units == cylinders of 16065 * 512 == 8225280 bytes
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         657     5277321   fd  Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
$ 

Now run the following to add the partition to the array:

$ sudo mdadm --add /dev/md1 /dev/sdb1
mdadm: hot added /dev/sdb1
$ 

The RAID system will automatically start syncing the drives and you're free to continue on your way. If you look at mdstats, it'll look like this:

$ cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[2] sda1[1]
5237056 blocks [2/1] [_U]
[>....................]  recovery =  2.5% (133056/5237056) finish=21.5min speed=3949K/sec
md0 : active raid1 hda1[0] hdd1[1]
2097024 blocks [2/2] [UU]
unused devices: <none>
$ 

Final Statements

I do hope this guide has been informative and helpful to you. I will be using it myself on a server as a reference for different tasks.

External Links