Asus A6TC
Network
Server basics
Linky kámošov
Linky školy
Linky in-line
Na pobavenie
LVM with EXT3 fs
Good news everyone! In next how-to is explained good technique, how to resize you partition when you are not sure about their size. LVM is the best tool for managining you partition resizeable. In my example I have set up not system partition, but data storege on CentOs box, because there is allways problem that disk can get broken a need for buing new one. I have set up two EXT3 fs partition on this disk using LVM. They are /data and /var/www. Size of this fs can be changed, so you do not need to worry, when you do not estimate size for fs. Disk is 250GB and at the end of this how-to is shown, how to resize the fs. The disk is already prepared using fdisk utility and it is devided to one primary partition with Linux LVM type, which containes whole capacity. This partiotion is used for LVM.
[root@virus roleta]# fdisk -l
Disk /dev/hdb: 20.0 GB, 20020396032 bytes
255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 * 1 65 522081 83 Linux
/dev/hdb2 66 830 6144862+ 83 Linux
/dev/hdb3 831 1595 6144862+ 83 Linux
/dev/hdb4 1596 2434 6739267+ 5 Extended
/dev/hdb5 1596 1977 3068383+ 83 Linux
/dev/hdb6 1978 2232 2048256 83 Linux
/dev/hdb7 2233 2297 522081 82 Linux swap / Solaris
/dev/hdb8 2298 2434 1100421 83 Linux
Disk /dev/hdd: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hdd1 1 30515 245111737 8e Linux LVM
[root@virus roleta]# pvcreate /dev/hdd1
Physical volume "/dev/hdd1" successfully created
[root@virus roleta]# vgcreate storage /dev/hdd1
Volume group "storage" successfully created
[root@virus roleta]# vgdisplay
--- Volume group ---
VG Name storage
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 233.75 GB
PE Size 4.00 MB
Total PE 59841
Alloc PE / Size 0 / 0
Free PE / Size 59841 / 233.75 GB
VG UUID UUTi0n-8XQh-at8Y-AmUJ-G6lo-yLdd-LM2UsQ
[root@virus roleta]#
On disk was volume group created. It is physical abstraction of the disk. On this volume group can be created logical volume, whitch is abstraction for creating of new fs.
[root@virus roleta]# lvcreate -L40G -nweb storage
Logical volume "web" created
[root@virus roleta]# lvcreate -L185G -ndata storage
Logical volume "data" created
[root@virus www]# lvdisplay
--- Logical volume ---
LV Name /dev/storage/web
VG Name storage
LV UUID Tjr8Wq-UDxO-YOhG-KLT6-27U0-Md9B-XpdqFZ
LV Write Access read/write
LV Status available
# open 0
LV Size 40.00 GB
Current LE 10240
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/storage/data
VG Name storage
LV UUID 3H90hO-BEi3-ADXH-ARF8-MicF-fzk7-D0O4wz
LV Write Access read/write
LV Status available
# open 0
LV Size 185.00 GB
Current LE 47360
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@virus www]#
On available logical volume can be created filesystems.
[root@virus roleta]# mke2fs -j /dev/storage/web
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
5242880 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
320 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@virus roleta]# mke2fs -j /dev/storage/data
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
24248320 inodes, 48496640 blocks
2424832 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1480 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@virus roleta]#
Mounting created fs. After this step new fs can be used. Enjoy.
[root@virus roleta]# cat /etc/fstab
LABEL=/1 / ext3 defaults 1 1
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/var /var ext3 defaults 1 2
LABEL=/home /home ext3 defaults 1 2
/dev/hdb2 /backup ext3 defaults 1 2
/dev/storage/web /var/www ext3 defaults 1 2
/dev/storage/data /data ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-hdb7 swap swap defaults 0 0
[root@virus roleta]# mount -a
[root@virus roleta]#
Resizing EXT3 fs on LVM
Bad news everyone! CentOs is not supported reiserfs or xfs by default, so I have to use EXT3 fs. It is because I am lazy to modify kernel for abbility to use these fs's. No, ofcourse not, real excuse is that i do not have physical access to this machine and I really worry that something get wrong while upgrading kernel (It won't happend while using Ubuntu!!!!. It has this support by default and upgrade of kernel is without any trouble!).
It is not so bad news at all. The only one difference when using EXT3 fs ist that you have to umount it first. I have read some article that ext3 can be extend even on-line, but I am paranoid that I can possible lost some data. For extending fs please always be sure that you have enought "Free PE" using vgdisplay command. While shring fs be sure that you are able to shrink it to required size.
[root@virus roleta]# df /var/www
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/storage-web
36124288 180248 34109032 1% /var/www
[root@virus roleta]# umount /var/www
[root@virus roleta]# e2fsck -f /dev/storage/web
e2fsck 1.39 (29-May-2006)
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/storage/web: 12/4587520 files (8.3% non-contiguous), 189030/9175040 blocks
[root@virus roleta]# resize2fs /dev/storage/web 32G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/storage/web to 8388608 (4k) blocks.
The filesystem on /dev/storage/web is now 8388608 blocks long.
[root@virus roleta]# lvreduce -L 32G /dev/storage/web
WARNING: Reducing active logical volume to 32.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce web? [y/n]: y
Reducing logical volume web to 32.00 GB
Logical volume web successfully resized
[root@virus roleta]# mount -a
[root@virus roleta]# df /var/www
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/storage-web
33027952 180296 31169936 1% /var/www
[root@virus roleta]#
[root@virus roleta]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-data
192G 253M 182G 1% /data
[root@virus roleta]# umount /data
[root@virus roleta]# e2fsck -f /dev/storage/data
e2fsck 1.39 (29-May-2006)
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/storage/data: 30/25559040 files (3.3% non-contiguous), 866668/51118080 blocks
[root@virus roleta]# lvextend -L 198G /dev/storage/data
Extending logical volume data to 198.00 GB
Logical volume data successfully resized
[root@virus roleta]# resize2fs /dev/storage/data
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/storage/data to 51904512 (4k) blocks.
The filesystem on /dev/storage/data is now 51904512 blocks long.
[root@virus roleta]# mount -a
[root@virus roleta]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/storage-data
195G 253M 185G 1% /data
[root@virus roleta]#