Redhat Linux - Logical Volumn Manager (lvm) - Resize volume size of home partition and Swap Size.
-- Change Swap Size on LV ---
-- turn off the swapping first
[root@MYLINUX2 ~]# swapoff -a
-- the swapping is located on a Logical Volume. Therefore, we need to reduce the size of the Logical Volume first. Now I want to reduce the size by 96G and the result is 32G
[root@MYLINUX2 ~]# lvresize -L -96G /dev/mapper/vg_MYLINUX2-lv_swap
WARNING: Reducing active and open logical volume to 32.14 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_swap? [y/n]: y
Reducing logical volume lv_swap to 32.14 GiB
Logical volume lv_swap successfully resized
-- re-enable the swap on the Logical Volume lv_swap.
[root@MYLINUX1 ~]# mkswap /dev/mapper/vg_MYLINUX1-lv_swap
mkswap: /dev/mapper/vg_MYLINUX1-lv_swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 33701884 KiB
no label, UUID=ffffffff-ffff-ffff-ffff-ffffffffffff
-- turn on swapping again
[root@MYLINUX1 ~]# swapon -a
-- show the current swapping status. Now we can see the new swap size is 32G.
[root@MYLINUX1 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 33701880 0 -1
-- The usage of /home partition is also low. I want to reduce the size as well.
-- Check the disk free status by 4K block
[root@MYLINUX3 ~]# df -B 4k
Filesystem 4K-blocks Used Available Use% Mounted on
/dev/mapper/vg_MYLINUX3-lv_root
12901535 627681 11618494 6% /
tmpfs 16514979 22 16514957 1% /dev/shm
/dev/sda1 123961 9394 108168 8% /boot
/dev/mapper/vg_MYLINUX3-lv_home
170222526 50450 161525267 1% /home
-- Check the disk free status by human readable format
[root@MYLINUX3 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_MYLINUX3-lv_root
50G 2.4G 45G 6% /
tmpfs 63G 88K 63G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/vg_MYLINUX3-lv_home
650G 198M 617G 1% /home
-- double check mount status of /home
[root@MYLINUX1 ~]# mount
/dev/mapper/vg_MYLINUX1-lv_home on /home type ext4 (rw)
-- only mount status of /home is shown here
-- unmount /home first
[root@MYLINUX1 ~]# umount /home
-- check the file system to ensure no error inside.
[root@MYLINUX1 ~]# fsck -n /dev/mapper/vg_MYLINUX1-lv_home
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_MYLINUX1-lv_home: clean, 11/43237376 files, 2764116/172936192 blocks
-- enable partprobe
[root@MYLINUX1 ~]# sudo partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
-- before resize the volume, journal must be disabled.
[root@MYLINUX1 ~]# tune2fs -O ^has_journal /dev/mapper/vg_MYLINUX1-lv_home
tune2fs 1.41.12 (17-May-2010)
-- Check the file system again after journal is disabled.
[root@MYLINUX1 ~]# e2fsck -f /dev/mapper/vg_MYLINUX1-lv_home
e2fsck 1.41.12 (17-May-2010)
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/vg_MYLINUX1-lv_home: 11/43237376 files (0.0% non-contiguous), 2731348/172936192 blocks
-- Reduce the file system size to 1G (Too agressive. This size is too small and not succeed).
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 1000M
resize2fs 1.41.12 (17-May-2010)
resize2fs: New size smaller than minimum (355108)
-- try again. First, reduce the /home volume to 2G.
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 2000M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_MYLINUX2-lv_home to 512000 (4k) blocks.
The filesystem on /dev/mapper/vg_MYLINUX2-lv_home is now 512000 blocks long.
-- Then reduce the /home volume to 1G.
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 1000M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_MYLINUX2-lv_home to 256000 (4k) blocks.
The filesystem on /dev/mapper/vg_MYLINUX2-lv_home is now 256000 blocks long.
-- After we have reduced the size of the file system, we can reduce the size of logical volume. Reduce the lv_home by 657.5G and the result size is 2.2G
[root@MYLINUX1 ~]# lvresize -L -657.5G /dev/vg_MYLINUX1/lv_home
WARNING: Reducing active logical volume to 2.20 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 2.20 GiB
Logical volume lv_home successfully resized
-- perform a filesystem check again.
[root@MYLINUX1 ~]# fsck -n /dev/vg_MYLINUX1/lv_home
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_MYLINUX1-lv_home: clean, 11/65536 files, 9243/256000 blocks
-- remember we have disable journal? Now we have to enable journal again.
[root@MYLINUX1 ~]# tune2fs -j /dev/vg_MYLINUX1/lv_home
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every -1 mounts or
0 days, whichever comes first. Use tune2fs -c or -i to override.
-- now mount the /home partition and keep finger cross.
[root@MYLINUX1 ~]# mount /home
-- Check free PE (physical extent) and size after two logical volumes (lv_swap and lv_home) have been reduced.
[root@MYLINUX1 ~]# vgdisplay
--- Volume group ---
VG Name vg_MYLINUX1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 837.84 GiB
PE Size 4.00 MiB
Total PE 214487
Alloc PE / Size 21591 / 84.34 GiB
Free PE / Size 192896 / 753.50 GiB
VG UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx
-- Now I have 753G free space for my use
-- I will create a new logical volume lv_hadoop with this free space
[root@MYLINUX1 ~]# lvcreate -L 753G -n lv_hadoop vg_MYLINUX1
Logical volume "lv_hadoop" created
-- make a mount point
[root@MYLINUX1 ~]# mkdir /hadoop
-- Check the new config again.
[root@MYLINUX1 ~]#lvdisplay
-- (only information of lv_hadoop is displayed here for cleanliness of this guide)
--- Logical volume ---
LV Name /dev/vg_MYLINUX1/lv_hadoop
VG Name vg_MYLINUX1
LV UUID yyyyyy-yyyy-yyyy-yyyy-yyyy-yyyy-yyyyyy
LV Write Access read/write
LV Status available
# open 0
LV Size 753.00 GiB
Current LE 192768
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
-- create a file system inside this new logical volume
[root@MYLINUX1 ~]# mkfs -t ext4 /dev/vg_MYLINUX1/lv_hadoop
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=64 blocks
49348608 inodes, 197394432 blocks
9869721 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
6024 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
-- update the /etc/fstab so that the new volume will be mounted automatically
[root@MYLINUX1 ~]# nano /etc/fstab
/dev/mapper/vg_MYLINUX1-lv_hadoop /hadoop ext4 defaults 1 2
-- mount the new lv_hadoop with mount point /hadoop
[root@MYLINUX1 ~]# mount /hadoop
-- check disk free size again.
[root@MYLINUX1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_MYLINUX1-lv_root
50G 2.4G 45G 6% /
tmpfs 63G 88K 63G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/vg_MYLINUX1-lv_home
984M 37M 898M 4% /home
/dev/mapper/vg_MYLINUX1-lv_hadoop
742G 197M 704G 1% /hadoop
-- update the DNS server IP address
[root@MYLINUX1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.116
nameserver 192.168.1.117
-- turn off the swapping first
[root@MYLINUX2 ~]# swapoff -a
-- the swapping is located on a Logical Volume. Therefore, we need to reduce the size of the Logical Volume first. Now I want to reduce the size by 96G and the result is 32G
[root@MYLINUX2 ~]# lvresize -L -96G /dev/mapper/vg_MYLINUX2-lv_swap
WARNING: Reducing active and open logical volume to 32.14 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_swap? [y/n]: y
Reducing logical volume lv_swap to 32.14 GiB
Logical volume lv_swap successfully resized
-- re-enable the swap on the Logical Volume lv_swap.
[root@MYLINUX1 ~]# mkswap /dev/mapper/vg_MYLINUX1-lv_swap
mkswap: /dev/mapper/vg_MYLINUX1-lv_swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 33701884 KiB
no label, UUID=ffffffff-ffff-ffff-ffff-ffffffffffff
-- turn on swapping again
[root@MYLINUX1 ~]# swapon -a
-- show the current swapping status. Now we can see the new swap size is 32G.
[root@MYLINUX1 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 33701880 0 -1
-- The usage of /home partition is also low. I want to reduce the size as well.
-- Check the disk free status by 4K block
[root@MYLINUX3 ~]# df -B 4k
Filesystem 4K-blocks Used Available Use% Mounted on
/dev/mapper/vg_MYLINUX3-lv_root
12901535 627681 11618494 6% /
tmpfs 16514979 22 16514957 1% /dev/shm
/dev/sda1 123961 9394 108168 8% /boot
/dev/mapper/vg_MYLINUX3-lv_home
170222526 50450 161525267 1% /home
-- Check the disk free status by human readable format
[root@MYLINUX3 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_MYLINUX3-lv_root
50G 2.4G 45G 6% /
tmpfs 63G 88K 63G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/vg_MYLINUX3-lv_home
650G 198M 617G 1% /home
-- double check mount status of /home
[root@MYLINUX1 ~]# mount
/dev/mapper/vg_MYLINUX1-lv_home on /home type ext4 (rw)
-- only mount status of /home is shown here
-- unmount /home first
[root@MYLINUX1 ~]# umount /home
-- check the file system to ensure no error inside.
[root@MYLINUX1 ~]# fsck -n /dev/mapper/vg_MYLINUX1-lv_home
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_MYLINUX1-lv_home: clean, 11/43237376 files, 2764116/172936192 blocks
-- enable partprobe
[root@MYLINUX1 ~]# sudo partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
-- before resize the volume, journal must be disabled.
[root@MYLINUX1 ~]# tune2fs -O ^has_journal /dev/mapper/vg_MYLINUX1-lv_home
tune2fs 1.41.12 (17-May-2010)
-- Check the file system again after journal is disabled.
[root@MYLINUX1 ~]# e2fsck -f /dev/mapper/vg_MYLINUX1-lv_home
e2fsck 1.41.12 (17-May-2010)
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/vg_MYLINUX1-lv_home: 11/43237376 files (0.0% non-contiguous), 2731348/172936192 blocks
-- Reduce the file system size to 1G (Too agressive. This size is too small and not succeed).
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 1000M
resize2fs 1.41.12 (17-May-2010)
resize2fs: New size smaller than minimum (355108)
-- try again. First, reduce the /home volume to 2G.
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 2000M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_MYLINUX2-lv_home to 512000 (4k) blocks.
The filesystem on /dev/mapper/vg_MYLINUX2-lv_home is now 512000 blocks long.
-- Then reduce the /home volume to 1G.
[root@MYLINUX2 ~]# resize2fs /dev/mapper/vg_MYLINUX2-lv_home 1000M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_MYLINUX2-lv_home to 256000 (4k) blocks.
The filesystem on /dev/mapper/vg_MYLINUX2-lv_home is now 256000 blocks long.
-- After we have reduced the size of the file system, we can reduce the size of logical volume. Reduce the lv_home by 657.5G and the result size is 2.2G
[root@MYLINUX1 ~]# lvresize -L -657.5G /dev/vg_MYLINUX1/lv_home
WARNING: Reducing active logical volume to 2.20 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 2.20 GiB
Logical volume lv_home successfully resized
-- perform a filesystem check again.
[root@MYLINUX1 ~]# fsck -n /dev/vg_MYLINUX1/lv_home
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_MYLINUX1-lv_home: clean, 11/65536 files, 9243/256000 blocks
-- remember we have disable journal? Now we have to enable journal again.
[root@MYLINUX1 ~]# tune2fs -j /dev/vg_MYLINUX1/lv_home
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every -1 mounts or
0 days, whichever comes first. Use tune2fs -c or -i to override.
-- now mount the /home partition and keep finger cross.
[root@MYLINUX1 ~]# mount /home
-- Check free PE (physical extent) and size after two logical volumes (lv_swap and lv_home) have been reduced.
[root@MYLINUX1 ~]# vgdisplay
--- Volume group ---
VG Name vg_MYLINUX1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 837.84 GiB
PE Size 4.00 MiB
Total PE 214487
Alloc PE / Size 21591 / 84.34 GiB
Free PE / Size 192896 / 753.50 GiB
VG UUID xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx
-- Now I have 753G free space for my use
-- I will create a new logical volume lv_hadoop with this free space
[root@MYLINUX1 ~]# lvcreate -L 753G -n lv_hadoop vg_MYLINUX1
Logical volume "lv_hadoop" created
-- make a mount point
[root@MYLINUX1 ~]# mkdir /hadoop
-- Check the new config again.
[root@MYLINUX1 ~]#lvdisplay
-- (only information of lv_hadoop is displayed here for cleanliness of this guide)
--- Logical volume ---
LV Name /dev/vg_MYLINUX1/lv_hadoop
VG Name vg_MYLINUX1
LV UUID yyyyyy-yyyy-yyyy-yyyy-yyyy-yyyy-yyyyyy
LV Write Access read/write
LV Status available
# open 0
LV Size 753.00 GiB
Current LE 192768
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
-- create a file system inside this new logical volume
[root@MYLINUX1 ~]# mkfs -t ext4 /dev/vg_MYLINUX1/lv_hadoop
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=64 blocks
49348608 inodes, 197394432 blocks
9869721 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
6024 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
-- update the /etc/fstab so that the new volume will be mounted automatically
[root@MYLINUX1 ~]# nano /etc/fstab
/dev/mapper/vg_MYLINUX1-lv_hadoop /hadoop ext4 defaults 1 2
-- mount the new lv_hadoop with mount point /hadoop
[root@MYLINUX1 ~]# mount /hadoop
-- check disk free size again.
[root@MYLINUX1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_MYLINUX1-lv_root
50G 2.4G 45G 6% /
tmpfs 63G 88K 63G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/vg_MYLINUX1-lv_home
984M 37M 898M 4% /home
/dev/mapper/vg_MYLINUX1-lv_hadoop
742G 197M 704G 1% /hadoop
-- update the DNS server IP address
[root@MYLINUX1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.116
nameserver 192.168.1.117
Comments