[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shrinking encrypted LVM partition



On Wed, Jul 13, 2011 at 11:41:49PM +1200, Aidan Gauland wrote:
> I have to make room on my hard drive for another operating system on my
> hard disk.  I currently have /boot on sda1, encrypted LVM on sda5
> (which, I think, an extended partition); this was set up by the
> installer.  I just want to install the other OS on a primary partition,
> instead of trying to get it set up with LVM.  What is the easiest way to
> rearrange my disk to make room for a primary partition?  As far as I
> know, it is not possible to resize a partition encrypted with the method
> used by Debian, so I will have to backup the data on the LVM partition,
> shrink sda5, and then reformat it and restore the LVM logical volumes.
>
> I'm hoping there is a simpler way.  Is there?

You can do it. It's not too terribly difficult. However, I have a couple
questions:

I have gathered that /dev/sda1 is mounted on /boot, and /dev/sda5 is a
physical volume. With that, how many logical volumes do you have from that
volume group, and where are they mounted? Are you using LUKS for your
encrypted volumes?

The general order of the steps you will be taking is this:

    0) BACKUP ALL DATA
    1) Find the logical volume(s) with the most space you can give up
    2) Reduce the filesystem of each logical volume to the desired size
       with resize2fs(8) (assuming it's an ext-based filesystem)
    3) Reduce each logical volume with lvreduce(8)
    4) Reduce each encrypted filesystem with cryptsetup(8) (assuming you're
       using LUKS)

At this point, all your logical volumes will be the size you want, and
you'll have all this free space in your volume group. Unfortunately, you
only have one device in your volume group, and vgreduce(8) requires
removing a device from the group, which you can't do. So, you'll have to
rezize the physical volume /dev/sda5:

    5) Shrink the physical volume with pvresize(8)
    6) Shrink the partition of /dev/sda5 using fdisk(8) or parted(8)
    7) Create a new partition from the new space
    8) Format the new partition as necessary
    9) Install the operating system to the new parition
   10) Update the MBR to allow booting into the new OS.

Depending on the sizes of the volumes, and the amount of data you have
stored on each, this may take a substantial amount of time if the tools
have to physically move data on the platters to make the new space
available. Some utilites, such as gparted(8) might be able to do all of
this in one swoop, but you'll need to boot from another medium, such as a
live CD to do so.

--
. o .   o . o   . . o   o . .   . o .
. . o   . o o   o . o   . o o   . . o
o o o   . o .   . o o   o o .   o o o

Attachment: signature.asc
Description: Digital signature


Reply to: