Trying out LVM2 on Ubuntu

來源:互聯網
上載者:User
文章目錄
  • Extras:

Environment:

Ubuntu 8.04 server LTS in VMware

Partitioned with installation guide, whole with LVM

Extra empty virtual disk 8GB added as second SCSI device

 

Steps:

 

1. Partition the new disk:

fdisk /dev/sdb

create 4 partitions. don't format.

 

2. create Physical Volumns for new partitions

pvcreate /dev/sdb1

pvcreate /dev/sdb2

...

Find out sizes for each PVs, in the unit "Physical Extends" (PEs)

$ pvdisplay /dev/sdb1 | grep 'Total PE'

Total PE:         490

Remember the value, say $TPE .

 

3. Find out Volumn group new PVs to be added in

vgdisplay

say we are adding to VG "ubuntu".

If there is NO VG AVAILABLE IN SYSTEM, create one:

vgcreate ubuntu /dev/sdb1

 The second arg is a pvcreate-ed physical volumn.

4. Add new PV to VG

vgextend /dev/sdb1 ubuntu

to remove, use vgreduce

vgreduce ubuntu /dev/sdb4

5. Find Logic Volumn new space to be added into. LVs are the "actual partitions" to be mounted in the system.

lvdisplay

To create one, 

lvcreate $VGNAME -l$TPE -n new_lv_name

Say the Volume Group name is /dev/ubuntu/, as $VGNAME

new_lv_name will be the name of new volume, e.g. /dev/ubuntu/new_lv_name

-l$TPE could be specified instead as -L size, e.g. -L 40G

 

6. Extend the target LV

lvextend -l+$TPE $LVNAME

where $TPE is found in step 2 and $LVNAME is found in step 5.

 

7. Resize filesystem accordingly.

resize2fs /dev/ubuntu/root

resize2fs will automatically resize the filesystem to fit the total size of underlying device (here the LV /dev/ubuntu/root). For ext3 / reiserfs, online resize can be performed where ext2 requires offline (umount first) resize.

 

Now you can df to see the new size.

 

Enjoy

 

Reference:

http://tldp.org/HOWTO/LVM-HOWTO/commontask.html

 

Extras:

 

1. Use large regular file as part of LVM PVs

Via loopback device / losetup

losetup /dev/loop0 $LARGEFILE   ; associate $LARGEFILE with /dev/loop0

pvcreate /dev/loop0                     ; use /dev/loop0 a.k.a. $LARGEFILE as a PV

; other normal PV / VG / LV operations

2. Remove an PV from VG

pvmove $PV

Move all PE (data blocks) on $PV to other free PEs in the $VG. See vgdisplay for "Free PE" and pvdisplay for "Total PE" - there must be more "Free PE" in vg than "Total PE" in target PV. If not, add a new PV to VG (don't assign to LVs). pvmove is supposed
to move all data blocks around is supposed to be slow.

vgreduce $VG $PV

removes target $PV from $VG.

pvremove $PV

optionally removes the PV.

3. Running system deployment tests with fresh Ubuntu on LVM2

Sample setup: Ubuntu 10.10 fresh on VG srv20, root fs /dev/srv20/root

Mount script:

#!/bin/bash[ -z "$LV" ] && LV=mspmasterexport LV./umount.shlvremove /dev/srv20/$LVlvcreate -s -L 40G -n $LV /dev/srv20/root || exit 1[ -d /mnt/$LV ] || mkdir /mnt/$LVmount /dev/srv20/$LV /mnt/$LVpushd /mnt/$LVecho "srv20-$LV" > ./etc/hostnamesed -i "s/srv20/srv20-$LV/g" ./etc/hostsrm ./base-systemtouch ./$LVmount --bind /dev/pts /mnt/$LV/dev/ptsmount --bind /proc /mnt/$LV/procmount --bind /sys /mnt/$LV/sys

Then one may chroot into /mnt/$LV and use the system. By modifying ~/.bashrc, change "\h" in $PS1 to `cat /etc/hostname` and one can identify which level of dream he is in.

Umount script:

#!/bin/bash[ -z "$LV" ] && LV=mspmasterumount /mnt/$LV/dev/ptsumount /mnt/$LV/procumount /mnt/$LV/sysumount /mnt/$LVrm -rf /mnt/$LV

 

Reference:

http://tldp.org/HOWTO/LVM-HOWTO/removeadisk.html

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.