Weasel disk partition plan

From Finninday
Revision as of 20:21, 6 July 2008 by Rday (Talk | contribs)

Jump to: navigation, search

Currently I have two partitions, root and big. They are both managed by lvm and look like this:

root@weasel:/boot# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/Ubuntu-root
                      224G  107G  106G  51% /
/dev/mapper/vg00-big  230G  187G   32G  86% /big

It would be much more reasonable to have a small root partition that is easily backed up and separate partitions for /home, /store, and /big.

/store is a shared network-accessible space. /big is used for automatic backups of root, /home, and /store.

Partition Size
root 4G
store 99G
home 3.4G
var 1.2G
big 187G
Total 300G

root is 107G (root + home + var + store), so if I would split them apart, root could be as small as 4G.

It would be handy if the root partition could be kept small enough to be backed up on a DVD.

So the new scheme would have 4 physical volumes:

Device Size Use
/dev/hda 250G root, store, home, var
/dev/hdb 250G backup root, store, home, var
/dev/hdc 500G big
/dev/hdd 500G big, network backup

The main idea is to partition disk failures, so I don't want to bunch all the disks together into a single volume group. When one disk goes bad, I don't want to lose access to part of another disk just because it is in the same volume group. I'm assuming that a volume group will fail when any physical volume in that group fails.

The logical volumes should be divided into primary and backup volumes and the sizes of the two volumes should match.

There should be a primary root, store, home, var, big. And there should be an equivalent backup root, store, home, var, big.

There should also be sufficient unformatted space in the primary volume group for a snapshot of the root partition so that an image can be taken and stored offline. But if root is small, that shouldn't be a problem.

So I'll need to move big (sdb1 vg00) to a 500G drive.

The big plan

Physical volumes sda (250G) sdb (250G) sdc (500G) sdd (500G)
Volume groups Ubuntu vg00 rootback netstore netback
Logical volumes root,var,home,store,swap big rootback netstore,store netback
Percent free 57% 57% 62% 62%

Currently lvscan looks like this:

 ACTIVE            '/dev/vg00/big' [232.88 GB] inherit
 ACTIVE            '/dev/Ubuntu/root' [226.77 GB] inherit
 ACTIVE            '/dev/Ubuntu/swap_1' [5.88 GB] inherit

bring sdc and sdd online

create volume group netstore on sdc

pvcreate /dev/sdc
vgcreate netstore /dev/sdc

{create logical volume netstore}

mkfs -t ext3 /dev/netstore/netstore

create volume group netback on sdd

pvcreate /dev/sdd
vgcreate netback /dev/sdd

create logical volume netback on sdd

Determine the number of physical extents on the volume group.

root@weasel:~# vgdisplay netback | grep "Total PE"
 Total PE              119234

Use that number to create a logical volume that consumes the disk.

root@weasel:~# lvcreate -l 119234 netback -n netback
 Logical volume "netback" created
root@weasel:~# lvscan
 ACTIVE            '/dev/netback/netback' [465.76 GB] inherit
 ACTIVE            '/dev/netstore/netstore' [465.76 GB] inherit
 ACTIVE            '/dev/vg00/big' [232.88 GB] inherit
 ACTIVE            '/dev/Ubuntu/root' [226.77 GB] inherit
 ACTIVE            '/dev/Ubuntu/swap_1' [5.88 GB] inherit
root@weasel:~# mkfs -t ext3 /dev/netback/netback

move big from sdb to sdc

mount /dev/netstore/netstore /big2
rsync -av /big/share /big2
rsync -av /big/weasel /big2
vol_id -u /dev/netstore/netstore
cd /dev/disk/by-uuid
ln -s ../../mapper/netstore-netstore 91fdcaaa-1ff7-4644-9976-10bda5f4919e

edit /etc/fstab to associate /big with the UUID for netstore

umount /big2 
umount /big
mount /big

create logical volume store on volume group netstore

Root is on sda5, volume group Ubuntu.

root@weasel:/# pvscan
 PV /dev/sdd    VG netback    lvm2 [465.76 GB / 0    free]
 PV /dev/sdc    VG netstore   lvm2 [465.76 GB / 0    free]
 PV /dev/sdb1   VG vg00       lvm2 [232.88 GB / 0    free]
 PV /dev/sda5   VG Ubuntu     lvm2 [232.64 GB / 0    free]
 Total: 4 [1.36 TB] / in use: 4 [1.36 TB] / in no VG: 0 [0   ]

Ubuntu does not have any free space to create a new logical volume, much less 3 new logical volumes. The first command that pops to mind is lvreduce, but according to the man page, I have to shrink the filesystem first:

DESCRIPTION
      lvreduce  allows  you  to reduce the size of a logical volume.  Be careful when reducing a
      logical volume’s size, because data in the reduced part is lost!!!
      You should therefore ensure that any filesystem on the volume is  resized  before  running
      lvreduce so that the extents that are to be removed are not in use.

According to "man -k ext3", this looks like what I need:

resize2fs (8)        - ext2/ext3 file system resizer

So I'll need to unmount root, resize the filesystem, and use lvreduce to create some space for new logical volumes for /home, /store, /var.

Root is a 224G device with 107G in use and 106G available. /store is about 100GB. It doesn't really belong on root. If I moved it to /big where it belongs, then root would be a total of about 10G. Then moving /home and /var should be much easier.

reduce netstore

So, to make room for /store on the netstore volume group, I unmounted /big and tried to reduce the filesystem size to 250G from 463G:

root@weasel:~# umount /big
root@weasel:~# resize2fs -p /dev/mapper/netstore-netstore 250G
resize2fs 1.40.8 (13-Mar-2008)
Please run 'e2fsck -f /dev/mapper/netstore-netstore' first.

OK, I can do that.

root@weasel:~# e2fsck -f /dev/mapper/netstore-netstore
e2fsck 1.40.8 (13-Mar-2008)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/netstore-netstore: 829/30531584 files (27.6% non-contiguous), 20540088/122095616 blocks
root@weasel:~# resize2fs -p /dev/mapper/netstore-netstore 250G
resize2fs 1.40.8 (13-Mar-2008)
Resizing the filesystem on /dev/mapper/netstore-netstore to 65536000 (4k) blocks.
Begin pass 2 (max = 718383)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 3727)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 37)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/netstore-netstore is now 65536000 blocks long.
root@weasel:~# lvreduce -L 251G netstore/netstore
File descriptor 4 left open
File descriptor 5 left open
File descriptor 7 left open
File descriptor 8 left open
  WARNING: Reducing active logical volume to 251.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce netstore? [y/n]: y
  Reducing logical volume netstore to 251.00 GB
  Logical volume netstore successfully resized
root@weasel:~# mount /big
root@weasel:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/Ubuntu-root
                      224G  107G  106G  51% /
varrun                1.5G  448K  1.5G   1% /var/run
varlock               1.5G     0  1.5G   0% /var/lock
udev                  1.5G   80K  1.5G   1% /dev
devshm                1.5G     0  1.5G   0% /dev/shm
/dev/mapper/vg00-big  230G  125G   94G  58% /rootback
tmpfs                 1.5G   43M  1.5G   3% /lib/modules/2.6.24-19-generic/volatile
/dev/mapper/netback-netback
                      463G   75G  365G  18% /bigback
/dev/mapper/netstore-netstore
                      249G   75G  164G  32% /big

create logical volume store on volume group netstore

Determine number of extents available and use that to create store:

root@weasel:~# vgdisplay netstore
File descriptor 4 left open
File descriptor 5 left open
File descriptor 7 left open
File descriptor 8 left open
  --- Volume group ---
  VG Name               netstore
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               465.76 GB
  PE Size               4.00 MB
  Total PE              119234
  Alloc PE / Size       64256 / 251.00 GB
  Free  PE / Size       54978 / 214.76 GB
  VG UUID               H7XaHj-lksL-9X0j-J5y8-ggUk-zqZc-zls3VV
   
root@weasel:~# lvcreate -l 54978 netstore -n store
File descriptor 4 left open
File descriptor 5 left open
File descriptor 7 left open
File descriptor 8 left open
  Logical volume "store" created

root@weasel:~# mkfs -t ext3 /dev/netstore/store

root@weasel:~# mkdir /store2
root@weasel:~# mount /dev/mapper/netstore-store /store2
root@weasel:/# rsync -av /store/* /store2

move those directories from root and mount them

When done, lvscan should look like this:

/dev/Ubuntu/root
/dev/Ubuntu/swap_1
/dev/Ubuntu/var
/dev/Ubuntu/home
/dev/netstore/store
/dev/rootback/rootback
/dev/netstore/netstore
/dev/netback/netback