<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tolaris.com &#187; raid</title>
	<atom:link href="http://www.tolaris.com/tag/raid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tolaris.com</link>
	<description>When the going gets tough, the tough sniff packets.</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:47:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>libblkid, or why you don&#8217;t need to worry about 4K disk format</title>
		<link>http://www.tolaris.com/2011/07/21/libblkid-or-why-you-dont-need-to-worry-about-4k-disk-format/</link>
		<comments>http://www.tolaris.com/2011/07/21/libblkid-or-why-you-dont-need-to-worry-about-4k-disk-format/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 20:15:24 +0000</pubDate>
		<dc:creator>Tyler Wagner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[raid]]></category>

		<guid isPermaLink="false">http://www.tolaris.com/?p=1431</guid>
		<description><![CDATA[You may have read of the new 4K Advanced Format drives now becoming popular on the market. In fact, if you&#8217;ve got a drive larger than 1 TB, you probably have one, even if you don&#8217;t know it. I&#8217;ve found lots of people assembling home NAS servers using 2 TB drives, linux software RAID or [...]]]></description>
			<content:encoded><![CDATA[<p>You may have read of the new <a href="http://www.bit-tech.net/hardware/storage/2010/04/01/the-facts-4k-advanced-format-hard-disks/1">4K Advanced Format drives</a> now becoming popular on the market. In fact, if you&#8217;ve got a drive larger than 1 TB, you probably have one, even if you don&#8217;t know it. I&#8217;ve found lots of people assembling home NAS servers using 2 TB drives, linux software RAID or LVM, and all of them are <a href="http://askubuntu.com/questions/8592/how-do-i-align-my-partition-table-properly">concerned</a> about <a href="http://busybox.net/~aldot/mkfs_stride.html">aligning</a> various parts of the storage infrastructure to the new <a href="https://ata.wiki.kernel.org/index.php/ATA_4_KiB_sector_issues">4K format</a>. But, thanks to libblkid, you don&#8217;t have to.</p>
<p><span id="more-1431"></span>Full disclosure: I&#8217;m one of those people who assembled such a NAS. And I was one of those people who spent an inordinate amount of time worrying about the 4K alignment problem. I eventually learned that I&#8217;d been wasting my time. When you find people on various mailing lists, forums, and blogs talking about this, please point them here.</p>
<p>The fundamental problem is the need to align data structures to the physical storage device&#8217;s boundaries. If your device stores data in block of 4K, then you want to begin writing your data at a multiple of 4K. You do not want to start writing 4K of data beginning 2K from the start of the device, because that will mean reading and writing two blocks of data. It would be more efficient to align to the boundary and write only one block.</p>
<p>All low-level storage systems, from filesystems (ext4) to logical volume managers (lvm2) to software raid (mdadm) use various block sizes. The terms vary from blocks to chunks to stripes, but the concept is the same. We want these blocks to align to what is best for the underlying layers, from any RAID configuration down to the physical devices.</p>
<p>To solve this problem, <a href="http://www.kernel.org/pub/linux/utils/util-linux/libblkid-docs/libblkid-Topology-information.html">libblkid</a> provides topology information for block devices. This includes physical and logical block sizes. As of spring 2010, support for libblkid is available in all the standard tools:</p>
<ol>
<li>fdisk, since util-linux >= 2.15. You should start with &#8216;-c -u&#8217; to disable DOS compatibility and use sectors instead of cylinders.</li>
<li>parted, since parted >= 2.1. Parted defaults to 1 MiB alignment for unknown disks, which should align to just about any sector size. This includes gparted and other graphical tools such as the partitioner used in the Ubuntu desktop installer.</li>
<li>mdadm, since util-linux >= 2.15. It is no longer necessary to manually specify stride and stripe-width. All MD superblocks are positioned either at the end of the array (0.9 and 1.0) or in multiples of 4K from the beginning (1.1, 1.2).</li>
<li>lvm2, since util-linux >= 2.15.</li>
<li>mkfs.{ext,xfs,gfs2,ocfs2} all support libblkid directly.</li>
</ol>
<p>If you&#8217;re uncertain, verify that your tool depends on util-linux or libblkid. You can use the package manager, although you may need to examine a dependant library:</p>
<pre>user@server:~$ dpkg -s libparted0debian1 | grep libblkid
Depends: libblkid1 (>= 2.17), libc6 (>= 2.8), libdevmapper1.02.1 (>= 2:1.02.36), libuuid1 (>= 2.16)
</pre>
<p>Or use ldd, which is more direct:</p>
<pre>user@server:~$ ldd /sbin/parted | grep libblkid
        libblkid.so.1 => /lib/libblkid.so.1 (0x00007f5833228000)
</pre>
<p>Conclusion: if you are running Ubuntu 10.04, Fedora 13, or RHEL 6 or later, you do not have to do anything to use your 4K disk efficiently. Create the RAID array, logical volume, and filesystem exactly as you normally would.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tolaris.com/2011/07/21/libblkid-or-why-you-dont-need-to-worry-about-4k-disk-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using LVM to make a live copy of a BackupPC pool</title>
		<link>http://www.tolaris.com/2010/04/23/using-lvm-to-make-a-live-copy-of-a-backuppc-pool/</link>
		<comments>http://www.tolaris.com/2010/04/23/using-lvm-to-make-a-live-copy-of-a-backuppc-pool/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 20:32:41 +0000</pubDate>
		<dc:creator>Tyler Wagner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[backuppc]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[raid]]></category>

		<guid isPermaLink="false">http://www.tolaris.com/?p=787</guid>
		<description><![CDATA[&#8220;How do I backup my BackupPC pool&#8221; is perhaps the most common topic of discussion on the backuppc-users mailing list. BackupPC stores all files in a common compressed pool (cpool, although I&#8217;ll use simply &#8220;pool&#8221; for this discussion), and maintains trees of hardlinks into the pool for each backup host. Therefore BackupPC requires a Linux/Unix [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;How do I backup my <a href="http://backuppc.sourceforge.net/">BackupPC</a> pool&#8221; is perhaps the most <a href="http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/backuppc-21/backup-the-backuppc-pool-with-bacula-98217/?sid=f13fcfba7eafa7ee90702cf4eecf946f">common</a> <a href="http://www.experts-exchange.com/Storage/Backup_Restore/rSync/Q_24448762.html">topic</a> of <a href="http://www.mail-archive.com/bacula-users@lists.sourceforge.net/msg01324.html">discussion</a> on the <a href="https://lists.sourceforge.net/lists/listinfo/backuppc-users">backuppc-users</a> mailing list. BackupPC stores all files in a common compressed pool (cpool, although I&#8217;ll use simply &#8220;pool&#8221; for this discussion), and maintains trees of hardlinks into the pool for each backup host. Therefore BackupPC requires a Linux/Unix filesystem. If you want to back up the BackupPC server itself, you must duplicate the pool, and the hardlinks to it.</p>
<p><span id="more-787"></span>The problem with this design is that conventional duplication/archival tools like <code>rsync</code> and <code>tar</code> can&#8217;t be used to duplicate the cpool in a reasonable period of time. Any file with more than one hardlink must be tracked and restored correctly on the destination host or filesystem. Copying my 700 GB pool with rsync between two identical disks with rsync would take a minimum of 3 days. Copying the same amount of raw data would take only a few hours.</p>
<p>So we can&#8217;t use filesystem-aware tools to backup a BackupPC server&#8217;s pool. Instead, we must make a bit-for-bit copy of the disk image.</p>
<p>One suggestion I&#8217;ve seen is to make the cpool part of a RAID1 array of two disks. When you want to make a backup, pull one disk and replace it. Or make it a 3-disk mirror with a removable drive, and periodically swap it out and carry it elsewhere. This is a sound solution, but it is still <a href="http://en.wikipedia.org/wiki/Sneakernet">sneakernet</a>.</p>
<p>What I want is a solution that:</p>
<ol>
<li>Duplicates the entire BackupPC storage to a second server,</li>
<li>in a matter of hours not days,</li>
<li>over the network,</li>
<li>such that the secondary server can quickly replace the primary server if it fails,</li>
<li>without interrupting normal operations on the disk, including BackupPC itself.</li>
</ol>
<p>To accomplish this, we build the BackupPC storage on <a href="http://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29">LVM</a>, and use LVM snapshots and netcat to copy the disk image.</p>
<p>My BackupPC server uses a 3ware hardware RAID card with two arrays:</p>
<ol>
<li>/dev/sda is a RAID1 of two disks, and provides the / and /var filesystems.</li>
<li>/dev/sdb is a RAID5 array of 5 disks, and provides the physical volume for the backuppc logical volume and filesystem</li>
</ol>
<p>The server&#8217;s filesystem looks like this:</p>
<pre>root@backuppc:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.2G  1.2G  8.0G  13% /
/dev/sda3              63G   21G   41G  34% /var
/dev/mapper/volgroup-backuppc
                      1.4T  711G  644G  53% /var/lib/backuppc</pre>
<p>If you&#8217;re planning to install BackupPC on a new server, this is easy to prepare. First, install the latest Ubuntu LTS server (I&#8217;m still using 8.04 &#8220;Hardy Heron&#8221;) on /dev/sda, using / and /var partitions as above. It is possible to configure LVM through the installer UI, but I&#8217;m not going to cover that here.</p>
<p>Once the base OS is installed, login via SSH and prepare the LVM setup. LVM is discussed in excellent detail elsewhere.  I strongly urge you to read <a href="http://www.howtoforge.com/linux_lvm">this How-To</a> and play with LVM a little before building the final system.</p>
<p>All commands are run as root.  Use sudo if you prefer.</p>
<ol>
<li>Create one partition of type 8e (Linux LVM) on the RAID disk.<br />
<code>fdisk /dev/sdb</code></p>
<pre>Command (m for help): o
Building a new DOS disklabel with disk identifier 0xf2704d76.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-243147, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-243147, default 243147):
Using default value 243147

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 1999.9 GB, 1999957393408 bytes
255 heads, 63 sectors/track, 243147 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x92cf8945

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1          1      243147  1953078277   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Syncing disks.</pre>
</li>
<li>Prepare the physical volume and volume group.<br />
<code>pvcreate /dev/sdb1<br />
vgcreate volgroup /dev/sdb1</code></li>
<li>Create a logical volume which is 75% of the available space. We&#8217;ll reserve the remaining space for the snapshot.<br />
<code>lvcreate -l '75%VG' -n backuppc volgroup</code></li>
<li>Create a filesystem on the logical volume. Some prefer XFS, but I&#8217;m happy with ext3 (with an eye to upgrading to ext4 later).<br />
<code>mkfs.ext3 /dev/volgroup/backuppc</code></p>
<li>Add the new logical volume to /etc/fstab.<br />
<code>vi /etc/fstab</code><br />
Add a new line. We mount with the most efficient options since BackupPC doesn&#8217;t need them.</p>
<pre>/dev/volgroup/backuppc /var/lib/backuppc ext3 noatime 0 2</pre>
</li>
<li>Now mount it for the first time.<br />
<code>mkdir /var/lib/backuppc<br />
mount /var/lib/backuppc</code></li>
<li>Finally, install BackupPC. This will also install Apache2, Perl, and a mail server.<br />
<code>apt-get install backuppc</code></li>
</ol>
<p>You now have a working BackupPC system using LVM for storage. Now we create an LVM snapshot.</p>
<p>Why use LVM <a href="http://en.wikipedia.org/wiki/Snapshot_%28computer_storage%29">snapshots</a>?  Because we must take a copy of the filesystem as it exists at one moment in time. If we install directly on /dev/sdb1 and then try to copy the filesystem while it is mounted, the copy will be inconsistent.  Some data blocks will represent the time we started copying, others the time we ended, or anything in between. There is a disk performance penalty to using snapshots, as this creates a copy-on-write fork of the filesystem from the moment the snapshot is taken. The best practice is to create the snapshot when the server is idle, copy it to the secondary server, and then remove it immediately after.</p>
<p>Create the snapshot using all remaining free space.<br />
<code>lvcreate -l '100%free' -s -n backuppcsnapshot /dev/volgroup/backuppc</code></p>
<p>If you are curious, you can now mount the logical volume /dev/volgroup/backuppcsnapshot and compare the difference between it and the original filesystem. But we don&#8217;t need to do that. We just need to copy it to our secondary server.</p>
<p>The secondary server should be configured exactly like the first. At minimum, it must have a partition or logical volume that is the same size or greater than /dev/volgroup/backuppc on the primary server. To copy it, we&#8217;ll use <code>dd</code> and SSH.</p>
<p>I previously recommended using <a href="http://www.cyberciti.biz/tips/howto-copy-compressed-drive-image-over-network.html">netcat</a> to perform this step. However, I&#8217;ve had a lot of difficulty getting cron, SSH, dd, and netcat to behave together when starting the listener on the destination server. I&#8217;ve also found that SSH is just as fast as using netcat, which is surprising given that encryption should be slower than transmitting the data in the clear.</p>
<p>Now we copy the data from primary to secondary via SSH. On the primary:<br />
<code>dd if=/dev/volgroup/backuppcsnapshot | ssh root@192.168.0.2 "dd of=/dev/volgroup/backuppc"</code></p>
<p>This reads the logical volume block for block and sends it to the secondary server on 192.168.0.2, via SSH.  The secondary server receives and writes it to the logical volume.</p>
<p>One advantage of using <code>dd</code> is that you can easily check progress:</p>
<pre>root@backuppc:~# ps -ef | grep dd
root      4958  4495  0 18:39 pts/0    00:00:03 dd if=/dev/volgroup/backuppcsnapshot
root@backuppc:~# kill -USR1 4958</pre>
<p>On the terminal where <code>dd</code> is running, you&#8217;ll see this.</p>
<pre>126689+0 records in
126689+0 records out
64864768 bytes (65 MB) copied, 9.97271 s, 6.5 MB/s</pre>
<p>You may wish to use <code>bzip</code> to compress the data after the first <code>dd</code> operation and decompress it before the second, or use <code>ssh -C</code>. Using compression will save bandwidth at the cost of CPU usage. In my tests, a raw copy gave sustained speeds of 200 mbit over gigabit Ethernet. Using bzip2, throughput was reduced to 20 mbit. Therefore I do not recommend using compression if copying over your own gigabit LAN.</p>
<p>As a last step, archive the BackupPC configuration whenever you clone the storage pool.  Since you don&#8217;t want the secondary to start running backups, put it in a safe place.  On the secondary:</p>
<p><code>mkdir /etc/backuppc/backup/</code></p>
<p>On the primary, after copying the snapshot:</p>
<p><code>rsync -av --delete /etc/backuppc/ root@192.168.0.2:/etc/backuppc/backup/</code></p>
<p>We now have a complete BackupPC server with LVM storage and a means of completely backing up to a secondary server, over the network, without interrupting the operation of the primary.  But what if you have an existing BackupPC pool directly on disk partition? You&#8217;ll need to migrate it to LVM without losing the data. I&#8217;ll discuss how to do that in my next post.</p>
<p><em>Updated 2010-09-17: removed directions for netcat and recommended SSH method.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tolaris.com/2010/04/23/using-lvm-to-make-a-live-copy-of-a-backuppc-pool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moving your Linux root partition to software RAID</title>
		<link>http://www.tolaris.com/2008/10/01/moving-your-linux-root-partition-to-raid/</link>
		<comments>http://www.tolaris.com/2008/10/01/moving-your-linux-root-partition-to-raid/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 19:32:24 +0000</pubDate>
		<dc:creator>Tyler Wagner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[raid]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.tolaris.com/blog/?p=13</guid>
		<description><![CDATA[Update 2012-01-18: This guide has been updated for recent changes, and is safe to use on current Ubuntu and Debian releases. One of the reasons I started this blog is to write about problems I&#8217;ve solved that I can&#8217;t find answers to already on the web. Today, let&#8217;s talk about moving your linux install to [...]]]></description>
			<content:encoded><![CDATA[<p><em>Update 2012-01-18: This guide has been updated for recent changes, and is safe to use on current Ubuntu and Debian releases.</em></p>
<p>One of the reasons I started this blog is to write about problems I&#8217;ve solved that I can&#8217;t find answers to already on the web.  Today, let&#8217;s talk about moving your linux install to linux software raid (md raid / mdadm).  This post assumes you are running Ubuntu Linux 8.04, but any Debian-based distro from the past two years, or most other distros, will have similar commands.</p>
<p>We start with an  install on a single 80 GB SATA drive, partitioned as follows:</p>
<p><code>/dev/sda1 as /, 10GB, ext3, bootable<br />
/dev/sda2 as swap, 1GB<br />
/dev/sda3 as /home, 69GB, ext3</code></p>
<p>We want to add a second 80GB SATA drive and move the entire install to use RAID1 between the two drives.  So the final configuration will appear:</p>
<p><code>/dev/md0 as /, 10GB, ext3<br />
/dev/md1 as swap, 1GB<br />
/dev/md2 as /home, 69GB, ext3</code></p>
<p>Where the raid arrays are:</p>
<p><code>md0 : active raid1 sda1[0] sdb1[1]<br />
md1 : active raid1 sda2[0] sdb2[1]<br />
md2 : active raid1 sda3[0] sdb3[1]</code></p>
<p>Here there be dragons.  As always, back up your data first.  If you don&#8217;t know how to use rsync, now is an excellent time to learn.</p>
<p><span id="more-13"></span></p>
<p>The general plan is:</p>
<ol>
<li>Partition the new drive</li>
<li>Create RAID arrays and filesystems on the new drive</li>
<li>Copy the data from drive 1 to the new RAID arrays on drive 2</li>
<li>Install grub on drive 2</li>
<li>Configure fstab and mdadm.conf, and rebuild initramfs images</li>
<li>Reboot on the RAID arrays on drive 2</li>
<li>Repartition drive 1 and add it to RAID</li>
</ol>
<p>All commands are run as root.  Use sudo if you prefer.</p>
<p><strong>Step 1: Partition the new drive</strong></p>
<p>Assuming you want to partition the second drive the same way as the first, this is easy.  Just clone the partitions from /dev/sda to /dev/sdb:</p>
<p><code>sfdisk -d /dev/sda | sfdisk /dev/sdb</code></p>
<p>You may want to format the new disk first to clear it of old data, especially if it previously had software RAID partitions on it.  You may get unusual results if it has a similar partition structure or RAID setup as the original disk.</p>
<p>Now use parted to mark the partitions for software RAID, with the first partition to boot:</p>
<p><code>parted /dev/sdb<br />
(parted) toggle 1 raid<br />
(parted) toggle 2 raid<br />
(parted) toggle 3 raid<br />
(parted) toggle 1 boot<br />
(parted) print</code></p>
<pre>Disk /dev/sdb: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      0.51kB  10.0GB  10.0GB  primary  ext3         boot, raid
 2      10.0GB  11.0GB  2000MB  primary  linux-swap   raid
 3      11.0GB  80.0GB  69.0GB  primary  ext3         raid
(parted) quit</pre>
<p>Parted will show you a file system in each partition, but the reality is that they will be plain linux software raid partitions (type 0xfd):</p>
<p><code>fdisk -l /dev/sdb</code></p>
<pre>Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa3181e57

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        1216     9765625   fd  Linux RAID autodetect
/dev/sdb2            1216        1338      976562+  fd  Linux RAID autodetect
/dev/sdb3            1338        9730    67408556   fd  Linux RAID autodetect</pre>
<p><strong>Step 2: Create RAID arrays and filesystems on the new drive</strong></p>
<p>Now we create RAID 1 arrays on each partition.  These arrays will have just one member each when we create them, which isn&#8217;t normal for RAID 1.  So we&#8217;ll have to force mdadm to let us:</p>
<p><code>apt-get install mdadm<br />
mdadm --create /dev/md0 --level=1 --force --raid-devices=1 /dev/sdb1<br />
mdadm --create /dev/md1 --level=1 --force --raid-devices=1 /dev/sdb2<br />
mdadm --create /dev/md2 --level=1 --force --raid-devices=1 /dev/sdb3</code></p>
<p>Next, you&#8217;ll need to create filesystems on the new RAID devices.  Assuming the same formats as your first partition:</p>
<p><code>mkfs.ext3 /dev/md0<br />
mkswap /dev/md1<br />
mkfs.ext3 /dev/md2</code></p>
<p><strong>Step 3: Copy the data from drive 1 to the new raid arrays on drive 2</strong></p>
<p>This is a job for rsync.  First, there are some directories on a running Linux system that we do not want to copy, like /dev and /proc.  We also want to ignore tempfs directories, like /var/run.  The best way to avoid these is to make an excludes file.  Create a file, /root/rsync-filter, with the following content:</p>
<p><code>- /dev/<br />
- /lib/modules/*/volatile/<br />
- /mnt/<br />
- /proc/<br />
- /sys/<br />
- /var/lock/<br />
- /var/run/</code></p>
<p>These lines define directories we will not copy over.  You may wish to add /tmp, apt&#8217;s cache, etc, but if you do you must manually create the directories themselves on the new filesystem.</p>
<p>Mount the new RAID array:</p>
<p><code>mount /dev/md0 /mnt<br />
mkdir /mnt/home<br />
mount /dev/md2 /mnt/home</code></p>
<p>If you are using a different mount structure, just be sure to recreate it and mount it in the right places in the new filesystem under /mnt/.</p>
<p>And start the rsync copy:</p>
<p><code>rsync -avx --delete -n --exclude-from /root/rsync-filter / /mnt/<br />
rsync -avx --delete -n /home/ /mnt/home/</code></p>
<p>You will see a list of files that will be changed, but nothing actually happens.  This is the job of the -n argument, which performs a dry-run.  Always do this before actually starting a copy.  You WILL make a painful mistake with rsync some day, so learn to be cautious.  Repeat the above commands without the -n when you are sure all is well.</p>
<p>The -x argument ensures that you will not cross filesystem boundaries, which is why you must copy /home separately, and any other mounted filesystems.  If you omit this you only need one command.  But make sure you have a good rsync filter file, and that you have nothing mounted like /media/cdrom that you don&#8217;t want an archive of.</p>
<p>Finally, create the directories that you skipped with your filter:</p>
<p><code>cd /mnt/<br />
mkdir -p dev/ mnt/ proc/ sys/ var/lock/ var/run/<br />
for i in /lib/modules/*/volatile ; do mkdir -p /mnt/$i ; done</code></p>
<p><strong>Step 4: Install grub on drive 2</strong></p>
<p>OK, we almost have a working RAID install on the second drive.  But it won&#8217;t boot yet.  Let&#8217;s use chroot to switch into it.</p>
<p><code>mount --rbind /dev /mnt/dev<br />
mount --rbind /proc /mnt/proc<br />
chroot /mnt</code></p>
<p>Now we have a working /dev and /proc inside the new RAID array, and by using chroot we are effectively in the root of the new array.  Be absolutely sure you are in the chroot, and not the real root of drive 1.  Here&#8217;s an easy trick: make sure nothing is in /sys:</p>
<p>ls /sys</p>
<p>If not, you&#8217;re in the new chroot.</p>
<p>Now we need to update grub to point to the UUID of the new filesystem on the RAID array. Get the UUID of /dev/md0&#8242;s filesystem:</p>
<p><code>tune2fs -l /dev/md0 | grep UUID</code></p>
<pre>Filesystem UUID:          8f4fe480-c7ab-404e-ade8-2012333855a6</pre>
<p>We need to tell grub to use this new UUID. How to do this depends on which version of grub you are using.</p>
<p><strong>Step 4.1: If you are using GRUB 2, which is the default on Ubuntu since 9.10 Karmic Koala:</strong></p>
<p>Edit /boot/grub/grub.cfg and replace all references to the old UUID with the new. Find all the lines like this:</p>
<pre>search --no-floppy --fs-uuid --set 9e299378-de65-459e-b8b5-036637b7ba93</pre>
<p>And replace them with the new UUID for /dev/md0:</p>
<pre>search --no-floppy --fs-uuid --set 8f4fe480-c7ab-404e-ade8-2012333855a6</pre>
<p>Do not run <code>grub-mkconfig</code>, as this will undo your changes. Install grub on the second drive.</p>
<p><code>grub-install /dev/sdb</code></p>
<p>Go on to step 5 below.</p>
<p><strong>Step 4.2: If you are using GRUB 1 (Legacy), which is the default on Ubuntu before 9.10 Karmic Koala:</strong></p>
<p>Edit grub&#8217;s device.map and menu.list files.  Edit /boot/grub/device.map and make sure both drives are listed:</p>
<pre>(hd0)   /dev/sda
(hd1)   /dev/sdb</pre>
<p>Edit /boot/grub/menu.list and find the line like this:</p>
<pre># kopt=root=UUID=9e299378-de65-459e-b8b5-036637b7ba93 ro</pre>
<p>Replace the UUID with the one you just found.  Leave the line commented, and save the file.  Now rebuild menu.lst to use the new UUID:</p>
<p><code>update-grub</code></p>
<p>Double-check that each boot option at the bottom of menu.lst is using the right UUID.  If not, edit them too. Finally, install grub on the second drive.</p>
<p><code>grub-install /dev/sdb</code></p>
<p><strong>Step 5: Configure fstab and mdadm.conf, and rebuild initramfs images</strong></p>
<p>We&#8217;re almost ready to reboot.  But first, we need to build an initramfs that is capable of booting from a RAID array.  Otherwise your boot process will hang at mounting the root partition.  Still in the chroot, edit /etc/fstab and change the partition entries to the new filesystems or devices.</p>
<p>If your /etc/fstab has &#8220;UUID=&#8221; entries like the following, change them to the new entries:</p>
<pre>proc            /proc           proc    defaults        0       0
UUID=8f4fe480-c7ab-404e-ade8-2012333855a6 /               ext3    relatime,errors=remount-ro 0       1
UUID=c1255394-4c42-430a-b9cc-aaddfb024445 none            swap    sw              0       0
UUID=94f0d5db-c525-4f52-bdce-1f93652bc0b1 /var/           ext3    relatime 0       1
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0</pre>
<p>In the above example, the first UUID cooresponds to /dev/md0, the second to /dev/md1, and so on.  Find the UUIDs with:</p>
<p><code>/lib/udev/vol_id /dev/md0</code></p>
<p>If your distribution uses a newer udev, you may not have the vol_id command. Use:</p>
<p><code>/sbin/blkid /dev/md0</code></p>
<p>If your /etc/fstab has &#8220;/dev/sda1&#8243; entries like it&#8217;s a bit easier.  Just change them to /dev/md0 and so on:</p>
<pre>proc            /proc           proc    defaults        0       0
/dev/md0        /               ext3    relatime,errors=remount-ro 0     1
/dev/md1        none            swap    sw              0       0
/dev/md2        /var/           ext3    relatime        0       1
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0</pre>
<p>Now, while still in the chroot, edit /etc/mdadm/mdadm.conf to list each RAID array:</p>
<pre>DEVICE partitions
ARRAY /dev/md0 UUID=126a552f:57b18c5b:65241b86:4f9faf62
ARRAY /dev/md1 UUID=ca493308:7b075f97:08347266:5b696c99
ARRAY /dev/md2 UUID=a983a59d:181b32c1:bcbb2b25:39e64cfd
MAILADDR root</pre>
<p>Find the UUID of each RAID array, which is not the same as the UUID of the filesystem on it (!), using mdadm:</p>
<p><code>mdadm --detail /dev/md0 | grep UUID</code></p>
<p>Now, rebuild your current kernel&#8217;s initramfs image:</p>
<p><code>update-initramfs -u</code></p>
<p>Or all of them:</p>
<p><code>update-initramfs -u -k all</code></p>
<p><strong>Step 6: Reboot on the RAID arrays on drive 2</strong></p>
<p>Now we&#8217;re ready to reboot.  First, exit the chroot and power off the machine cleanly.  You have three options:</p>
<ol>
<li>If your BIOS allows you to select which drive to boot from, elect to boot from drive 2.</li>
<li>Swap drives 1 and 2 so drive 2 becomes /dev/sda, and restart</li>
<li>Use a USB recovery stick to boot from drive 2</li>
</ol>
<p>When the system restarts, you should reboot on the new RAID drive.  Make sure:</p>
<p><code>df -h</code></p>
<pre>Filesystem            Size  Used Avail Use% Mounted on
/dev/md0              9.2G  1.9G  6.9G  21% /
varrun                498M   56K  498M   1% /var/run
varlock               498M     0  498M   0% /var/lock
udev                  498M   68K  498M   1% /dev
devshm                498M     0  498M   0% /dev/shm
lrm                   498M   39M  459M   8% /lib/modules/2.6.24-19-generic/volatile
/dev/md2               63G  130M   60G   1% /home</pre>
<p><strong>Step 7: Repartition drive 1 and add it to RAID</strong></p>
<p>Finally, we add the old drive into the array.  Assuming you chose option 1 and didn&#8217;t swap the drive&#8217;s cables:</p>
<p><code>sfdisk -d /dev/sdb | sfdisk --force /dev/sda</code></p>
<p>If you receive a warning message here, reboot now.</p>
<pre>Re-reading the partition table ...
BLKRRPART: Device or resource busy
The command to re-read the partition table failed
Reboot your system now, before using mkfs</pre>
<p>If not, continue on:</p>
<p><code>mdadm /dev/md0 --grow -n 2<br />
mdadm /dev/md1 --grow -n 2<br />
mdadm /dev/md2 --grow -n 2<br />
mdadm /dev/md0 --add /dev/sda1<br />
mdadm /dev/md1 --add /dev/sda2<br />
mdadm /dev/md2 --add /dev/sda3</code></p>
<p>If you chose option 2 and your drives now have a different ordering, swap &#8220;/dev/sda&#8221; and &#8220;/dev/sdb&#8221; everywhere above.</p>
<p>The RAID array will now rebuild.  To check its progress:</p>
<p><code>cat /proc/mdstat</code></p>
<pre>Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[1] sda1[0]
      9767424 blocks [2/2] [UU]

md1 : active raid1 sdb1[1] sda1[0]
      1951808 blocks [2/2] [UU]

md2 : active raid1 sdb2[2] sda2[0]
      68693824 blocks [2/1] [U_]
      [&gt;....................]  recovery =  0.4% (16320/68693824) finish=22.4min speed=8160K/sec

unused devices:</pre>
<p>Once the array is finished rebuilding, reinstall grub on the new drive.  We&#8217;ll do both, for good measure.</p>
<p><code>grub-install /dev/sda<br />
grub-install /dev/sdb</code></p>
<p>You should now be able to reboot without either drive, and your system will come up cleanly.  If you ever need to replace a failed drive, remove it, use step 7 above to clone the partition scheme to the new drive and add it to the array.</p>
<p><strong>Gotchas:</strong></p>
<p>If you are having issues with your RAID setup, especially if you have an older RAID setup or older release already, you might need these packages:</p>
<p><code>apt-get install lvm2 evms dmsetup</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tolaris.com/2008/10/01/moving-your-linux-root-partition-to-raid/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

