Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
VMware image: Copy guest to a larger disk?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
1clue
Veteran
Veteran


Joined: 05 Feb 2006
Posts: 1401

PostPosted: Tue May 27, 2014 9:05 pm    Post subject: VMware image: Copy guest to a larger disk? Reply with quote

Hi.

Long story short, I have a Linux guest which was installed onto too small a disk on VMware esxi. The free version.

I've resized in VMware but long story short the partition table is still messed up, so rather than risk losing data I need to move my installation.

I've created a new disk, and partitioned it, and mounted the partitions.

I want to do something like:
Code:

cd /
cp -rax . /mnt/


I also need to make sure that device files and such come over, so what I think is that I treat it like a gentoo install, mount everything and then chroot? Maybe from a system rescue cd?

I'd like to have verification of the copy parameters too.

Thanks.
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 392

PostPosted: Tue May 27, 2014 10:22 pm    Post subject: Reply with quote

I had similar problem recently, when my 6GB root ran out of inodes during `emerge -uDN world` and... well, here we go:

1) if you have root on partition (not on lvm volume) you can't resize it online. You must boot from another medium and then carry on.
2) you need some free space after partition you want to extend. If it's virtual image it's probably the only partition there, so this should not be a problem
3) do the job: Run fdisk , or whatever partitioner you like. If your partition doesn't start from the first possible block, write down where it starts. Delete partition you want to expand. Create new partition. It must start exacly at the same spot deleted one used to. When you're done with fdisk, expand filesystem to match the size of new partition and boot it.

In case of LVM it's much easier: simply resize volume and then resize filesystem. Many filesystems can be resized while mounted
Ofcourse, it's easy to make a mistake when deletinig and re-creating partition, so either make a copy of image or make sure nothing interrupts you and focus.


Last edited by szatox on Tue May 27, 2014 10:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
1clue
Veteran
Veteran


Joined: 05 Feb 2006
Posts: 1401

PostPosted: Tue May 27, 2014 10:27 pm    Post subject: Reply with quote

It's got an MBR partition, /boot is /dev/sda1, swap is /dev/sda2 and / is /dev/sda5.

I don't know why the guy put / on an extended partition.

I really would rather change disks and have something rational. Keeping this one would mean resizing the extended partition and then resizing the partition inside it. Too much chance of something going horribly wrong IMO.

Is it really that much of a problem to do a copy on mounted partitions?

Ideally, I would make a new disk with GPT partition table, set up LVM and copy partitions over afterward, but I think this is just too many things to go wrong.

Thanks.
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 392

PostPosted: Tue May 27, 2014 10:47 pm    Post subject: Reply with quote

you can copy it onto LVM volume, it seems to be a good idea when facing such a mess. I don't know what's the point of GPT under LVM as it's LVM that does the hard job anyway.
You can mount root readonly and copy the whole partition onto LVM (And then resize it). If you want to change filesystem too, it would still be a better idea to boot from external medium and run for example `rsync -a` . With cp I'm not always sure what I get.
Back to top
View user's profile Send private message
1clue
Veteran
Veteran


Joined: 05 Feb 2006
Posts: 1401

PostPosted: Tue May 27, 2014 10:55 pm    Post subject: Reply with quote

GPT is because MBR is antique and I don't use it anymore if at all possible.

OK that rsync -a is what I'm after. Will device files be a problem? IMO anything kernel-provided would be absent if I boot off a CD, so /proc and all that would not be an issue.

I'm incredibly uneasy about copying the filesystem. If everything were to remain identical then it wouldn't be a big deal. If I mount the filesystems and copy/rsync then I have an automatic backup.

I think I'll give it a shot.
Back to top
View user's profile Send private message
1clue
Veteran
Veteran


Joined: 05 Feb 2006
Posts: 1401

PostPosted: Wed May 28, 2014 2:02 am    Post subject: Reply with quote

One more question:

If I copy an MBR partition to an LVM2 logical volume with something like dd, would that work? Is there a formatting difference or is "bytes is bytes"?

Let's say I format my new disk with mostly LVM2 space.

Can I do something like this?

[/code]

dd if=/dev/sda5 of=/dev/hddvg1/myvm_root bs=4096

[/code]

Or is it going to be different bytes in there?
Back to top
View user's profile Send private message
chrisyu
Apprentice
Apprentice


Joined: 10 Apr 2003
Posts: 197
Location: China

PostPosted: Wed May 28, 2014 3:43 am    Post subject: Reply with quote

I think if you resized the vmware disk, you could boot from System Rescue CD iso.

Then startx, run gparted to resize the partition.

Of course, backup first.
Back to top
View user's profile Send private message
szatox
Guru
Guru


Joined: 27 Aug 2013
Posts: 392

PostPosted: Wed May 28, 2014 11:42 am    Post subject: Reply with quote

If you boot from external medium, there will be nothing mounted on top of directory tree you want to copy, so you can easyly copy it with either rsync or cp or whatever you like most.
Now, since both, /dev/mapper/* and /sd*N are an interface/abstraction layer for block devices containing filesystem, whateer is behind it should not matter. You can even dump your partition to file and use the result with your VM telling it it's a raw image. This means
dd if=/dev/sda5 of=/dev/hddvg1/myvm_root bs=4096
should do the job just fine as long as there are no writes to /dev/sda5 until it completes. Unmount filesystem if possible, mount readonly if not. Anything mounted on top of this readonly filesystem is not a part of cloned fileesystem so will not be read.
Oh, it's probably a better idea to use block size close to hdd disk cache, as it tells dd how much data you want to move in a single shot rather than what kind of disk you have.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum