1. Swap partition SWAPThe swap partition generally specifies the size of virtual memory to be 1 to 1.5 times the actual memory. If the actual memory exceeds 8GB, you can directly allocate 16GB to the virtual memory. If the virtual memory is not enough, you must add a virtual disk. Since you cannot repartition the original disk, you can choose to create a new one. 1.1 Create swapfile[root@clq0917 ~]# dd if=/dev/zero of=/opt/www bs=1M count=1024 Recorded 1024+0 reads Recorded 1024+0 writes 1073741824 bytes (1.1 GB) copied, 10.7409 seconds, 100 MB/sec [root@clq0917 ~]# 1.2 Format the swap partition[root@clq0917 ~]# mkswap -f /opt/www Setting up swap space version 1, size = 1048572 KiB No label, UUID=9928fe54-9639-4dd9-90ef-82d3f69e94fe [root@clq0917 ~]# 1.3 Check the current swap partition status[root@clq0917 ~]# free -m total used free shared buffers cached Mem: 1840 1304 535 8 1 1115 -/+ buffers/cache: 188 1652 Swap: 2047 0 2047 [root@clq0917 ~]# 1.4 Open the newly created SWAP partition[root@clq0917 ~]# swapon /opt/www swapon: /opt/www: Insecure permissions 0644, 0600 is recommended. //Use permission command [root@clq0917 ~]# chown 600 /opt/www [root@clq0917 ~]# free -m total used free shared buffers cached Mem: 1840 1305 535 8 1 1115 -/+ buffers/cache: 188 1651 Swap: 3071 0 3071 // 1G more in the swap partition 1.5 Close the newly created swap partition[root@clq0917 ~]# swapoff /opt/www [root@clq0917 ~]# free -m total used free shared buffers cached Mem: 1840 1304 535 8 1 1115 -/+ buffers/cache: 188 1652 Swap: 2047 0 2047 //Restore to the state without adding virtual disk 1.6 Add a swap partition to the new area1.[root@clq0917 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes/512 bytes I/O size (minimum/optimal): 512 bytes/512 bytes Disk label type: dos Disk identifier: 0x1f8fccca DeviceBoot Start End Blocks Id System /dev/sdb1 2048 393215 195584 83 Linux /dev/sdb2 393216 41943039 20774912 5 Extended /dev/sdb5 395264 589823 97280 82 Linux swap ~ Prepare this area as a swap partition 2. Change the partition type to 82 Command (type m for help): l 0 Empty 24 NEC DOS 81 Minix / Old Linux bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux Swap/So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 Hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux Extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS Volume Set da Non-file system data 6 FAT16 42 SFS 87 NTFS Volume Set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux Plain Text de Dell Tools 8 AIX 4e QNX4.x Part 2 8e Linux LVM df BootIt 9 AIX Bootable 4f QNX4.x Part 3 93 Amoeba e1 DOS Accessa OS/2 Boot Manager 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Extended (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor Command (type m for help): t Partition number (1, 2, 5, default 5): 5 Hex code (type L to list all codes): 82 Changed the type of partition "Linux" to "Linux swap / Solaris" Command (type m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes/512 bytes I/O size (minimum/optimal): 512 bytes/512 bytes Disk label type: dos Disk identifier: 0x1f8fccca DeviceBoot Start End Blocks Id System /dev/sdb1 2048 393215 195584 83 Linux /dev/sdb2 393216 41943039 20774912 5 Extended /dev/sdb5 395264 589823 97280 82 Linux swap / Solaris Command (type m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Synchronizing disks. 3. Update [root@clq0917 ~]# partprobe /dev/sdb5 4. Use sdb5 as a swap partition [root@clq0917 ~]# mkswap /dev/sdb5 Setting up swap space version 1, size = 97276 KiB No label, UUID=d146ac2b-6d08-4b9b-b18d-0b1fc0f3896e 5. Start the swap partition [root@clq0917 ~]# swapon /dev/sdb5 View [root@clq0917 ~]# swapon -s File name Type Size Used Permissions /dev/dm-1 partition 2097148 0 -1 /dev/sdb5 partition 97276 0 -2 6. Use [root@clq0917 ~]# blkid /dev/sdb5 to save partitions permanently /dev/sdb5: UUID="d146ac2b-6d08-4b9b-b18d-0b1fc0f3896e" TYPE="swap" [root@clq0917 ~]# vi /etc/fstab /dev/mapper/rhel-swap swap swap defaults 0 0 UUID="00e35670-d6c9-44d1-8e8c-f52bd71edf59" /mnt xfs defaults 0 0 UUID="d146ac2b-6d08-4b9b-b18d-0b1fc0f3896e" swap swap defaults 0 0 ~ 2. LVM managementStep lvm 1. Add physical disk and create physical volume 1. Prepare the physical disk (refer to the previous blog for adding a disk)Previous articleLinkLinux Operation and Maintenance Basic System Disk Management Tutorial [root@clq0917 ~]# lsblk |grep "sd[cd]" sdc 8:32 0 20G 0 disk sdd 8:48 0 20G 0 disk Check the pv creation status [root@clq0917 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- 19.51g 0 /dev/sdc lvm2 a-- 20.00g 20.00g 2. Create a volume group named hongmao [root@clq0917 ~]# vgcreate hongmao /dev/sdc Volume group "hongmao" successfully created Check volume group [root@clq0917 ~]# vgs VG #PV #LV #SN Attr VSize VFree hongmao 1 0 0 wz--n- 20.00g 20.00g rhel 1 2 0 wz--n- 19.51g 0 3. Create a logical volume, assign a name and size, and create a volume group [root@clq0917 ~]# lvcreate -L 1000M -n lv1 hongmao Logical volume "lv1" created Check the logical volume [root@clq0917 ~]# lvs lvs lvscan [root@clq0917 ~]# lvscan ACTIVE '/dev/hongmao/lv1' [1000.00 MiB] inherit ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit ACTIVE '/dev/rhel/root' [17.51 GiB] inherit 4. Format the file system [root@clq0917 ~]# mkfs.xfs /dev/hongmao/lv1 meta-data=/dev/hongmao/lv1 isize=256 agcount=4, agsize=64000 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=256000, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 5. Temporary mount [root@clq0917 ~]# mkdir /lv1 [root@clq0917 ~]# mount /dev/hongmao/lv1 /lv1/ [root@clq0917 ~]# df -h File system capacity used available used% Mount point /dev/mapper/rhel-root 18G 1.8G 16G 11% / devtmpfs 915M 0 915M 0% /dev tmpfs 921M 0 921M 0% /dev/shm tmpfs 921M 8.6M 912M 1% /run tmpfs 921M 0 921M 0% /sys/fs/cgroup /dev/sdb1 188M 9.8M 178M 6% /mnt /dev/sda1 497M 96M 401M 20% /boot /dev/mapper/hongmao-lv1 997M 33M 965M 4% /lv1 3. Volume Group ManagementExpand the volume group and add the new disk to the volume group1. Add new disk to pv [root@clq0917 ~]# pvcreate /dev/sdd Physical volume "/dev/sdd" successfully created 2. Use vgextend to extend [root@clq0917 ~]# vgextend hongmao /dev/sdd Volume group "hongmao" successfully extended ***3 Delete the specified disk from the volume group (usually not deleted) bgreduce hongmao /dev/sdd 4. Data migration volume group, the same disk can be migrated online Check the usage of pv in the current logical volume vg [root@clq0917 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- 19.51g 0 /dev/sdc hongmao lvm2 a-- 20.00g 19.02g /dev/sdd hongmao lvm2 a-- 20.00g 20.00g pvmove online data migration to other pv [root@clq0917 ~]# pvmove /dev/sdc /dev/sdc: Moved: 27.6% /dev/sdc: Moved: 100.0% [root@clq0917 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 rhel lvm2 a-- 19.51g 0 /dev/sdc hongmao lvm2 a-- 20.00g 20.00g /dev/sdd hongmao lvm2 a-- 20.00g 19.02g 4. Logical Volume ManagementThe capacity of the logical volume extension cannot exceed the capacity of the volume group1. Add 999M to the logical volume (999 + 999 is not the same) [root@clq0917 ~]# lvextend -L +999M /dev/hongmao/lv1 Rounding size to boundary between physical extents: 1000.00 MiB Extending logical volume lv1 to 1.95 GiB Logical volume lv1 successfully resized What percentage of the disk pool is allocated to the logical volume (50% is approximately equal to 499) [root@clq0917 ~]# lvextend -l +50%free /dev/hongmao/lv1 Extending logical volume lv1 to 20.97 GiB Logical volume lv1 successfully resized ***File system extension xfs--->xfs_growfs /dev/hongmao/lv1 ext--->resize2fs /dev/hongmao/lv1 Crop the capacity of the logical volume of the ext4 file systemFirst, create a 1G logical volume as the object of cropping
1. If it is already mounted, you must uninstall it first
2. To reduce capacity, you must first detect the file system
3. After the adjustment is completed, cut the logical volume capacity
4. It is strongly recommended to check the file system again after cropping.
5. Mounting testIf it can be mounted, it generally means that the cropping is successful and the file system is not damaged.
The above is the detailed content of the Linux operation and maintenance basic swap partition and lvm management tutorial. For more information about Linux operation and maintenance management, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
>>: Detailed graphic explanation of sqlmap injection
Because we were going to build a website, in addi...
CSS: Copy code The code is as follows: html,body{ ...
mysql gets all dates or months in a time period 1...
Copy data When copying data remotely, we usually ...
mycli MyCLI is a command line interface for MySQL...
Table of contents Case scenario Solving the probl...
Grid is a two-dimensional grid layout system. Wit...
This article example shares the specific code of ...
Table of contents MySQL multi-version concurrency...
The “Cancel” button is not part of the necessary ...
Table of contents 1. Install Docker 2. Install Gi...
Install ssh tool 1. Open the terminal and type th...
The four property values of position are: 1.rel...
Table of contents Mind Map Simple understanding E...
Table of contents Error message Cause Error demon...