
《hpr3727 :: Expanding your filesystem with LVM》 - 免费有声读物
作者:
语言:English
类型:
1 / 1hpr3727
- 1. hpr3727
关于
Summary: Rho`n describes adding a new hard drive to his work computer and expanding its filesystem
Source: [http://hackerpublicradio.org/eps.php?id=3727](http://hackerpublicradio.org/eps.php?id=3727)
Original audio: [https://archive.org/download/hpr3727/hpr3727\_source.flac](https://archive.org/download/hpr3727/hpr3727\_source.flac)
Synopis
=======
I installed a new 1TB Crucial MX500 SSD into my work computer. While we are mostly a Windows based business, as the IT guy I do get a bit of discretion when updating my own machine (i.e. I get to solve all the problems I create). Last year, I decided to run the Pop!_OS distribution of Linux on my work computer and run Windows in a VM on it. Recently the Windows image had grown and was causing disk space notifications. This prompted the additional hard drive.
During the initial installation of Pop!_OS, I remember deciding not to bother with installing Linux Volume Management (LVM). I have used it in the past, but I am still much more comfortable with the old style device mapping and mounting disk partitions to directories. I even rationalized that if I needed to add more space, I will just add a new disk with one big partition and map it to the home directory.
Now a year later I am adding a new HD and thinking, I really hate all the space that is most likely going to be wasted once I move the Windows image to the new drive. Ok, I guess I should figure out how to install LVM, and use it to manage the space on both drives. Luckily there a number of good blogs to be found on adding LVM to an existing system. The following are the steps and commands I used to accomplish my goal.
Commands
========
Most of the following commands need to be run as root. I decided to change to root user instead of typing sudo before every command. The basic steps to creating a single filesystem sharing the storage space between two physical disk partitions are:
Let LVM know about the new disk.
In my case, create a volume group and add the new disk and its full storage space to it.
Copy the disk partition with the root filesystem from the origin disk to the new volume group
Expand the root filesystem on the volume group to the full size of the volume group.
Update system configuration to boot with the root filesystem on the new volume group.
Let LVM know about the old root disk partition.
Add the old root partition to the volume group.
Expand the root filesystem on the volume group to include the new space in the volume group.
root@work# pvcreate /dev/sdbroot@work# pvdisplay "/dev/sdb" is a new physical volume of "931.51 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 931.51 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID wRBz38-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxroot@work# vgcreate workvg /dev/dsb No device found for /dev/dsb.root@work# vgcreate workvg /dev/sdb Volume group "workvg" successfully createdroot@work# vgdisplay --- Volume group --- VG Name workvg 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 931.51 GiB PE Size 4.00 MiB Total PE 238467 Alloc PE / Size 0 / 0 Free PE / Size 238467 / 931.51 GiB VG UUID 67DSwP-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxroot@work# pvdisplay --- Physical volume --- PV Name /dev/sdb VG Name workvg PV Size 931.51 GiB / not usable 1.71 MiB Allocatable yes PE Size 4.00 MiB Total PE 238467 Free PE 238467 Allocated PE 0 PV UUID wRBz38-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxroot@work# lvcreate -n root -L 931.51 workvg Rounding up size to full physical extent 932.00 MiB Logical volume "root" created.root@work# cat /dev/sda3 >/dev/mapper/workvg-rootcat: write error: No space left on device
Hmmm why can't it copy the smaller disk onto a larger one?
root@work# pvdisplay --- Physical volume --- PV Name /dev/sdb VG Name workvg PV Size 931.51 GiB / not usable 1.71 MiB Allocatable yes PE Size 4.00 MiB Total PE 238467 Free PE 238234 Allocated PE 233 PV UUID wRBz38-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxroot@work# lvdisplay --- Logical volume --- LV Path /dev/workvg/root LV Name root VG Name workvg LV UUID srXpUd-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx LV Write Access read/write LV Creation host, time work.example.com, 2022-10-18 08:46:34 -0400 LV Status available # open 0 LV Size 932.00 MiB Current LE 233 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
Whoops, the default unit for the lvcreate is MB, and I forgot to add G to my size. A good reason to always include units in whatever you do :) Also, pay attention to any reports printed at the end of a successful command. When I scrolled back I realized it told me the size it created.
root@work# lvextend -l +100%FREE /dev/workvg/root Size of logical volume workvg/root changed from 932.00 MiB (233 extents) to 931.51 GiB (238467 extents). Logical volume workvg/root successfully resized.root@work# lvdisplay --- Logical volume --- LV Path /dev/workvg/root LV Name root VG Name workvg LV UUID srXpUd-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx LV Write Access read/write LV Creation host, time work.example.com, 2022-10-18 08:46:34 -0400 LV Status available # open 0 LV Size 931.51 GiB Current LE 238467 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1root@work# cat /dev/sda3 >/dev/mapper/workvg-rootroot@work# mkdir /media/new-rootroot@work# mount /dev/mapper/workvg-root /media/new-rootroot@work# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 450G 421G 5.6G 99% //dev/sda1 497M 373M 125M 76% /boot/efi/dev/sda2 4.0G 3.4G 692M 84% /recovery/dev/mapper/workvg-root 450G 421G 5.7G 99% /media/new-root
Ok, the LV volume is resized but the filesystem now needs to expanded to use the new disk space
root@work# umount /media/new-root/root@work# resize2fs /dev/mapper/workvg-rootresize2fs 1.46.5 (30-Dec-2021)Please run 'e2fsck -f /dev/mapper/workvg-root' first.root@work# e2fsck -f /dev/mapper/workvg-roote2fsck 1.46.5 (30-Dec-2021)Pass 1: Checking inodes, blocks, and sizesInode 7210086 extent tree (at level 2) could be narrower. Optimize
Much better. Now we need to get the computer to boot using LVM and the new drive. Need to make sure /etc/fstab
is updated to point to the new root filesystem.
Make some in-memory filesystems available under the new root:
root@work# mount --rbind /dev /media/new-root/devroot@work# mount --bind /proc /media/new-root/procroot@work# mount --bind /sys /media/new-root/sysroot@work# mount --bind /run /media/new-root/runroot@work# chroot /media/new-rootroot@work# cat /etc/fstab# /etc/fstab: static file system information.## Use 'blkid' to print the universally unique identifier for a# device; this may be used with UUID= as a more robust way to name devices# that works even if disks are added and removed. See fstab(5).##
ok, moment of truth, can i reboot into the new root filesystem
root@it05:/# shutdown -r nowRunning in chroot, ignoring request.root@it05:/# exitroot@work# shutdown -r now
Whoot! Success. Booted right back up, and can verify running from new LV
rhorning@icon-n.com@it05:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/workvg-root 916G 421G 449G 49% //dev/sda1 497M 373M 125M 76% /boot/efi
Next step, add the original root partition (/dev/sda3) to the volume group so there is 1.5Gb available to the filesystem
root@work# pvcreate /dev/sda3WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sda3. Physical volume "/dev/sda3" successfully created.root@work# vgextend workvg /dev/sda3 Volume group "workvg" successfully extendedroot@work# vgdisplay --- Volume group --- VG Name workvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size <1.36 TiB PE Size 4.00 MiB Total PE 355528 Alloc PE / Size 238467 / 931.51 GiB Free PE / Size 117061 / <457.27 GiB VG UUID 67DSwP-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxxroot@work# lvdisplay --- Logical volume --- LV Path /dev/workvg/root LV Name root VG Name workvg LV UUID srXpUd-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx LV Write Access read/write LV Creation host, time work.example.com, 2022-10-18 08:46:34 -0400 LV Status available # open 1 LV Size 931.51 GiB Current LE 238467 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0root@work# lvextend -l +100%FREE /dev/workvg/root Size of logical volume workvg/root changed from 931.51 GiB (238467 extents) to <1.36 TiB (355528 extents). Logical volume workvg/root successfully resized.root@work# lvdisplay --- Logical volume --- LV Path /dev/workvg/root LV Name root VG Name workvg LV UUID srXpUd-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx LV Write Access read/write LV Creation host, time work.example.com, 2022-10-18 08:46:34 -0400 LV Status available # open 1 LV Size <1.36 TiB Current LE 355528 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0root@work# df -hFilesystem Size Used Avail Use% Mounted ontmpfs 1.6G 2.4M 1.6G 1% /run/dev/mapper/workvg-root 916G 421G 449G 49% /tmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/lock/dev/sda1 497M 373M 125M 76% /boot/efi/dev/sda2 4.0G 3.4G 692M 84% /recoverytmpfs 7.8G 0 7.8G 0% /run/qemutmpfs 1.6G 1.7M 1.6G 1% /run/user/1202401106root@work# resize2fs /dev/mapper/workvg-rootresize2fs 1.46.5 (30-Dec-2021)Filesystem at /dev/mapper/workvg-root is mounted on /; on-line resizing requiredold_desc_blocks = 117, new_desc_blocks = 174The filesystem on /dev/mapper/workvg-root is now 364060672 (4k) blocks long.root@work# df -hFilesystem Size Used Avail Use% Mounted ontmpfs 1.6G 2.4M 1.6G 1% /run/dev/mapper/workvg-root 1.4T 421G 881G 33% /tmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/lock/dev/sda1 497M 373M 125M 76% /boot/efi/dev/sda2 4.0G 3.4G 692M 84% /recoverytmpfs 7.8G 0 7.8G 0% /run/qemutmpfs 1.6G 1.7M 1.6G 1% /run/user/1202401106
References
==========
Move data from regular partition to lvm; Viewed on 2022-10-18
How to Create LVM Partition in Linux – LVM Tutorial; Viewed on 2022-10-18
'lvextend -l 100%FREE' resizing to the number of free extents rather than adding them to the current size in RHEL; Viewed on 2022-10-18
Best Practice for Mounting an LVM Logical Volume with /etc/fstab; Viewed on 2022-10-18
Can't update kernel and initramfs; Viewed on 2022-1018
Crucial MX500 1TB 3D NAND SATA 2.5-inch; Viewed on 2022-10-18
Corsair Dual SSD Mounting Bracket (3.5” Internal Drive Bay to 2.5", Easy Installation) ; Viewed on 2022-10-18
评论
成为第一个评论的人
此内容还没有任何评论。开始对话吧!
标签: hpr3727 :: Expanding your filesystem with LVM audio, hpr3727 :: Expanding your filesystem with LVM - Rho`n audio, free audiobook, free audio book, audioaz