Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Misc
Reload this Page Moving root to a logical volume
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Misc Any questions or Linux discussion that does not fit in any of the other technical areas.

Reply
 
Thread Tools Display Modes
Old 05-02-2008   #1 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
Moving root to a logical volume

Long story short: I want to move my root partition to an empty logical volume. I have /boot mounted on a regular partition, so there won't be any worries about the machine not booting. What I want to know is if the following scheme sounds reasonable.

Long story: I have four 250 GB drives (sda - sdd).
Sda is split into four partitions:
sda1 == /boot
sda2 == swap
sda3 == /
sda4 == part of a logical volume that includes all of sdb (/dev/mapper/Main-MainVolume)
Sdc and sdd are all one logical volume -- /dev/mapper/Backup-BackupVolume

The volume Backup-BackupVolume is (surprise surprise) where I keep some of my backups and won't be touched. I want to move all the information currently mounted on sda3 on to Main-MainVolume.

My thoughts on how to complete the process are as follows,
  1. sudo cp -upr / /mnt/fakeroot # Main-MainVolume is mounted at /mnt/fakeroot
  2. sudo rm -rf /mnt/fakeroot/boot
  3. Edit fstab to mount Main-MainVolume at /
  4. Remove fstab line that mounts sda3 at /
  5. Reboot

So, do you think that will work, or will I be left with an unbootable mess?
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
smolloy is offline   Reply With Quote
Old 05-02-2008   #2 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
So does anyone see any errors in the little 5 point process in my previous post, or do you think it will work?

I'm mostly worried about the first point, since I'm not sure if "cp -upr" will be an accurate enough copy for the machine to boot.
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
smolloy is offline   Reply With Quote
Old 05-02-2008   #3 (permalink)
Jonathan183
Linux Engineer
 
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,459
Hi smolley
This is probably a dumb question but ... are you trying to copy an active operating system with the first command? I would have thought you need to boot from another OS for example a live CD to do the copy.

Ed: maybe I'm taking the list a bit too literally but I don't think step 2 is required since you will mount your boot partition to your new /boot and I'd just # out fstab entries which are no longer required. btw I have never used LVM ... but that may be obvious from my post.
Jonathan183 is offline   Reply With Quote
Old 05-02-2008   #4 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
Quote:
Originally Posted by Jonathan183 View Post
Hi smolley
This is probably a dumb question but ... are you trying to copy an active operating system with the first command? I would have thought you need to boot from another OS for example a live CD to do the copy.
Thanks for the reply.

Yes, I'm trying to copy an active OS, and you bring up a good point. Maybe I should be doing this from a liveCD in order to prevent complications. Thanks for the tip.

Quote:
Originally Posted by Jonathan183 View Post
Ed: maybe I'm taking the list a bit too literally but I don't think step 2 is required since you will mount your boot partition to your new /boot and I'd just # out fstab entries which are no longer required. btw I have never used LVM ... but that may be obvious from my post.
Step 2 isn't strictly necessary since I'll be mounting sda1 onto /boot, but it will save a small amount of space on the LVM, and seems like the correct thing to do. The reason I need to keep /boot on a regular partition is that I don't think the machine can boot from a logical volume.

I need to be careful to execute step two in such a way that I only delete the contents of /mnt/fakeroot/boot and not the directory itself, since I will be mounting sda1 there after all's said and done.

Thanks for you comments.
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
smolloy is offline   Reply With Quote
Old 05-02-2008   #5 (permalink)
Jonathan183
Linux Engineer
 
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,459
As you said ... I don't think you will be able to boot the system unless you retain the separate boot partition you have at present.

I guess as long as you have a live CD you should be able to put fstab back as it was if it all goes pear shaped. I'm working on the basis sda3 contains all root info at present and you are just copying it to your fake-root lvm. I'd use cp but leave the rm bit until after you prove the system boots.

I'm not sure how cp will cope with links etc. I've only used it to cp home rather than root partitions in the past. As I said I have not used lvm so partition copying and dd have been available to me.

btw why are you using the u option in the cp command?
Jonathan183 is offline   Reply With Quote
Old 05-02-2008   #6 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
Quote:
Originally Posted by Jonathan183 View Post
I guess as long as you have a live CD you should be able to put fstab back as it was if it all goes pear shaped. I'm working on the basis sda3 contains all root info at present and you are just copying it to your fake-root lvm. I'd use cp but leave the rm bit until after you prove the system boots.
Yeah, sda3 contains everything from root except for /boot, and I want an exact copy on Main-MainVolume (which will be temporarily mounted at /mnt/fakeroot).

Quote:
Originally Posted by Jonathan183 View Post
I'm not sure how cp will cope with links etc. I've only used it to cp home rather than root partitions in the past. As I said I have not used lvm so partition copying and dd have been available to me.
I'll let you know how well cp goes after I try it (sometime tomorrow).

Quote:
Originally Posted by Jonathan183 View Post
btw why are you using the u option in the cp command?
Force of habit!!! I only really need -pr to recursively copy and preserve permissions. The -u is only there cos my fingers instinctively type it after typing cp

Cheers for the advice.
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
smolloy is offline   Reply With Quote
Old 05-03-2008   #7 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
OK, done the copying, but, luckily, I've also done a bit of thinking.

My little five point plan will not work, and here's why. Altering fstab to mount my LVM at / is all well and good, but how does the machine know to look in the LVM for /etc/fstab rather than sda3 as previously? Some sort of mystical sixth sense?

No.

It knows where to mount the root filesystem because that information is in /boot/grub/menu.lst
Code:
title           Ubuntu 8.04, kernel 2.6.24-16-generic
root            (hd0,0)
kernel          /vmlinuz-2.6.24-16-generic root=UUID=8ae29e85-952a-4e9e-88f4-45367f59d5fa ro quiet splash
initrd          /initrd.img-2.6.24-16-generic
All that "root=UUID=8ae29..." stuff is telling it on which drive to mount /. In this case it should mount it on the drive with that UUID, which can be found in /etc/fstab (sda3 as I said earlier)
Code:
# /dev/sda3
UUID=8ae29e85-952a-4e9e-88f4-45367f59d5fa /               ext3    relatime,errors=remount-ro 0       1
So now I need to think carefully. I obviously can't just change the fstab, cos then god knows what sort of mess it would get itself into when it tried to boot. I'll need to edit menu.lst to let it know that root=/dev/mapper/Main-MainVolume. Also, I'll probably need to add a couple of lines to /boot/grub/device.map to define Main-MainVolume as a drive that grub can access.

Some careful thinking, and a little googling, is required before I continue.

Any advice is welcome
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
smolloy is offline   Reply With Quote
Old 05-03-2008   #8 (permalink)
Jonathan183
Linux Engineer
 
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,459
Yes it helps if you update grub boot options how could I miss that! You should find you can refer to the volume ... example off the forums
Code:
title Fedora (2.6.24.5-85.fc
root (hd0,2)
kernel /vmlinuz-2.6.24.5-85.fc8 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.24.5-85.fc8.img
I'm not sure you need to update device.map as I think this is only used during the grub install process.

Has google turned up the solution yet?

Ed: I'm not sure if you will be able to use
Code:
sudo vol_id /dev/sda1
replaceing /dev/sda1 with your volume info to determine UUID and use that to identify root in both fstab and the grub menu.lst file.
Jonathan183 is offline   Reply With Quote
Old 05-03-2008   #9 (permalink)
smolloy
Linux Guru
 
smolloy's Avatar
 
Join Date: Apr 2005
Location: San Francisco, CA, but from Belfast, N.Ireland.
Posts: 1,821
So I didn't resort to google in the end. Just a lot of thought, a look at the configuration of another machine I have access to, and a few bottles of beer.

After using a liveCD to copy the contents of sda3 onto Main-MainVolume, I booted back into Ubuntu (with / still on sda3). I then mounted Main-MainVolume at /mnt/fakeroot, and edited /mnt/fakeroot/etc/fstab to look like the following, (EDIT: In case it's not clear, I changed the mount point of root by editing the line with "/dev/mapper/Main-MainVolume")
Code:
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sda3
/dev/mapper/Main-MainVolume /               ext3    relatime,errors=remount-ro 0       1
# /dev/sda1
UUID=10882051-4902-40f4-98b6-f0062a589e51 /boot           ext3    relatime        0       2
# /dev/sda2
UUID=89a269ef-c107-4d86-88b3-77b413971a18 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
/dev/mapper/Backup-BackupVolume  /mnt/backupdisk  ext3  defaults   0   2
Then I opened up /boot/grub/menu.lst, and added an extra entry, as follows,
Code:
title           Ubuntu 8.04, kernel 2.6.24-16-generic
root            (hd0,0)
kernel          /vmlinuz-2.6.24-16-generic root=UUID=8ae29e85-952a-4e9e-88f4-45367f59d5fa ro quiet splash
initrd          /initrd.img-2.6.24-16-generic
quiet

title           Ubuntu 8.04, kernel 2.6.24-16-generic (recovery mode)
root            (hd0,0)
kernel          /vmlinuz-2.6.24-16-generic root=UUID=8ae29e85-952a-4e9e-88f4-45367f59d5fa ro single
initrd          /initrd.img-2.6.24-16-generic

title           Ubuntu 8.04, memtest86+
root            (hd0,0)
kernel          /memtest86+.bin
quiet

title           Ubuntu 8.04, kernel 2.6.24-16-generic (new mount point)
root            (hd0,0)
kernel          /vmlinuz-2.6.24-16-generic root=/dev/mapper/Main-MainVolume ro quiet splash
initrd          /initrd.img-2.6.24-16-generic
quiet
From looking at my work computer (which has / mounted on an LVM), I could see that no change was needed to device.map. As you said, it was probably just an installation file for grub.

After making those changes, I rebooted, chose the last entry from grub, and crossed my fingers......


.......And here I am, logged in to the new system!

Turned out it was pretty easy in the end, but it was important that I took it slowly, and thought about every step. If I had have charged ahead with my original "5 point plan", I might have screwed my system quite badly (although maybe not unrecoverably). Instead, a bit of thought and a few beers resulted in a pain-free transition!

Thanks for your tips along the way Jonathan183.
__________________
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 7300 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII

Last edited by smolloy; 05-03-2008 at 05:15 PM. Reason: Make things a little clearer
smolloy is offline   Reply With Quote
Old 05-03-2008   #10 (permalink)
Jonathan183
Linux Engineer
 
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,459
Glad it worked ... and the method is clear for others to follow if they have a similar issue ... including the beer!
Jonathan183 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 06:57 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0