Summarization of several methods of Linux mounted hard disk expansion

Source: Internet
Author: User
Tags deprecated reserved vps hex code


The hard drive is full, plus the hard disk expansion, whether it is a stand-alone server, or cloud space to buy a new hard disk, the same way of expansion. The following to Ali VPS for example, in detail, mounted hard disk expansion of the 2 ways.
Ali VPs, personally feel that there are the following two areas need to improve
1, the default is not LVM, so the system disk/DEV/XVDA1 can not be expanded, so if there are large data things, at the beginning to consider the problem of expansion. The greater the amount of data, the greater the operational risk.
2, can not achieve seamless expansion, that is, in the background expansion, do not login to the VPS, to adjust. Non-professionals, difficulty in expanding
First, do not use LVM, directly mount the hard drive to the directory

1, view the hard disk partition situation





[Root@iz94zz3wqciz ~]# DF


FileSystem 1k-blocks Used Available use% mounted on


/DEV/XVDA1 20641404 14778400 4814480 76%/


Tmpfs 509300 0 509300 0%/dev/shm





[Root@iz94zz3wqciz ~]# Fdisk-l





disk/dev/xvda:21.5 GB, 21474836480 bytes


255 heads, Sectors/track, 2610 cylinders


Units = Cylinders of 16065 * 8225280 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x00078f9c





Device Boot Start End Blocks Id System


/DEV/XVDA1 * 1 2611 20970496 Linux//id is 83, non-LVM





disk/dev/xvdb:23.6 GB, 23622320128 bytes//newly purchased hard drive


255 heads, Sectors/track, 3230 cylinders


Units = Cylinders of 14280 * 7311360 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x27cc1f5a





2, the hard disk partition and view the partition situation





[Root@iz94zz3wqciz ~]# fdisk-s 56/dev/xvdb//partition





Warning:dos-compatible mode is deprecated. It ' s strongly recommended to


Switch off "mode" (Command ' C ') and change display units to


Sectors (Command ' u ').





Command (M for help): N//input n


Command Action


E Extended


P primary partition (1-4)


P//Primary partition


Partition number (1-4): 1/min Area code 1


The cylinder (1-3230, default 1):


Using Default value 1


Last cylinder, +cylinders or +size{k,m,g} (1-3230, default 3230):


Using Default Value 3230





Command (M for help): Wq//Save and exit


The partition table has been altered!





[Root@iz94zz3wqciz ~]# Fdisk-l





disk/dev/xvda:21.5 GB, 21474836480 bytes


255 heads, Sectors/track, 2610 cylinders


Units = Cylinders of 16065 * 8225280 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x00078f9c





Device Boot Start End Blocks Id System


/DEV/XVDA1 * 1 2611 20970496 Linux





disk/dev/xvdb:23.6 GB, 23622320128 bytes


255 heads, Sectors/track, 3230 cylinders


Units = Cylinders of 14280 * 7311360 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x27cc1f5a





Device Boot Start End Blocks Id System


/DEV/XVDB1 1 3230 23062172 after Linux//partition




3, format the new partition XVDB1





[Root@iz94zz3wqciz ~]# MKFS.EXT4/DEV/XVDB1//format partition


MKE2FS 1.41.12 (17-may-2010)


FileSystem label=


OS Type:linux


Block size=4096 (log=2)


Fragment size=4096 (log=2)


Stride=0 blocks, stripe width=0 blocks


1441792 inodes, 5765543 blocks


288277 blocks (5.00%) reserved for the Super user


The Data block=0


Maximum filesystem blocks=4294967296


176 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





Writing Inode Tables:done


Creating journal (32768 blocks): Done


Writing superblocks and filesystem accounting Information:done





This filesystem would be automatically checked every mounts or


180 days, whichever comes. Use Tune2fs-c or-i to override.





4, create the directory and mount the partition





[Root@iz94zz3wqciz ~]# Mkdir/mnt/fastdfs//Mount Directory


[Root@iz94zz3wqciz ~]# echo "/dev/xvdb1/mnt/fastdfs ext4 defaults 0 0" >>/etc/fstab//reboot will mount automatically


[Root@iz94zz3wqciz ~]# mount-a//Mount all catalogs





[Root@iz94zz3wqciz ~]# DF


FileSystem 1k-blocks Used Available use% mounted on


/DEV/XVDA1 20641404 14778404 4814476 76%/


Tmpfs 509300 0 509300 0%/dev/shm


/DEV/XVDB1 22694396 176064 21365516 1%/mnt/fastdfs//new partitions are mounted


Here, a separate hard drive is added to the system. This type of expansion is simple to operate, but not very scalable, it is not recommended this mode of expansion.

Second, the use of LVM way, the hard disk expansion (recommended)

1, cancel the mount of the previous test and delete the partition

[Root@iz94zz3wqciz ~]# umount-a        // Suppress Mount  
 
[Root@iz94zz3wqciz ~]# fdisk/dev/xvdb  //partition  
 
Warning:dos-co Mpatible mode is deprecated. It ' s strongly recommended to
         switch off the mode (command ' C ') and C Hange display units to
         sectors (Command ' u ') . 
 
Command (m for help): d      //delete partition  
Selected partition 1 
 
Command (m for help): wq    //Save  
The partition table has been altered! 

2, installing LVM

[Root@iz94zz3wqciz nginx]# uname-a//view kernel information
Linux Iz94zz3wqciz 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu 17:20:51 UTC 2014 x86_64 x86_64 x86_64 gnu/linux

[Root@iz94zz3wqciz ~]# yum Install lvm2 device-mapper//Installation lvm2,2.6.9 later versions are not installed Device-mapper

[Root@iz94zz3wqciz nginx]# Lsmod | grep dm_mod//Whether the Dm_mod is loaded
Dm_mod 84337 5 Dm_mirror,dm_log
LVM installation, first load Device-mapper module, starting from the Linux kernel 2.6.9, Device-mapper module is already included, so you just load it. Load Mapper module: Modprobe dm_mod.

3, creating an LVM partition





[Root@iz94zz3wqciz ~]# fdisk/dev/xvdb//partition





Warning:dos-compatible mode is deprecated. It ' s strongly recommended to


Switch off "mode" (Command ' C ') and change display units to


Sectors (Command ' u ').





Command (M for help): l





0 Empty NEC DOS bayi minix/old Lin BF Solaris


1 FAT12 9 swap/so Linux C1 drdos/sec (fat-


2 Xenix root 3c partitionmagic c4 drdos/sec (fat-


3 Xenix usr Venix 80286 os/2 hidden c:c6 drdos/sec (fat-


4 FAT16 <32m PPC PReP Boot Linux Extended C7 Syrinx


5 Extended SFS NTFS volume set da non-fs data


6 FAT16 4d qnx4.x NTFS Volume set db cp/m/CTOs/.


7 Hpfs/ntfs 4e qnx4.x 2nd part Linux plaintext de Dell Utility


8 AIX 4f qnx4.x 3rd part 8e Linux LVM DF bootit


9 AIX bootable Ontrack DM Amoeba E1 DOS Access


A os/2 Boot manag wuyi ontrack DM6 Aux Amoeba BBT e3 DOS r/o


b W95 FAT32 cp/m 9f bsd/os e4 speedstor


C W95 FAT32 (LBA) Ontrack DM6 Aux A0 IBM Thinkpad hi EB BeOS FS


E W95 FAT16 (LBA) OnTrackDM6 a5 FreeBSD ee GPT


F W95 Ext ' d (LBA) ez-drive a6 OpenBSD ef EFI (fat-12/16/


OPUS Golden Bow A7 NeXTSTEP f0 linux/pa-risc b


One Hidden FAT12 5c Priam edisk A8 Darwin UFS F1 SpeedStor


Compaq diagnost speedstor A9 NetBSD f4 SpeedStor


Hidden FAT16 <3 The GNU HURD or Sys ab Darwin boot F2 DOS Secondary


Hidden FAT16 Novell Netware af hfs/hfs+ fb VMware VMFS


Hidden hpfs/ntf Novell Netware b7 BSDI FS FC VMware Vmkcore


The AST smartsleep disksecure mult b8 bsdi swap fd Linux RAID auto


1b Hidden W95 FAT3 pc/ix bb Boot Wizard hid Fe lanstep


1c Hidden W95 FAT3 Minix be Solaris boot ff BBT


1e Hidden W95 FAT1





Command (M for help): N


Command Action


E Extended


P primary partition (1-4)


P


Partition number (1-4): 1


The cylinder (1-2871, default 1):


Using Default value 1


Last cylinder, +cylinders or +size{k,m,g} (1-2871, default 2871):


Using Default Value 2871





Command (M for help): P





disk/dev/xvdb:23.6 GB, 23622320128 bytes


255 heads, Sectors/track, 2871 cylinders


Units = Cylinders of 16065 * 8225280 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x27cc1f5a





Device Boot Start End Blocks Id System


/DEV/XVDB1 1 2871 23061276 Linux//not LVM partition format





Command (M for help): t//Conversion


Selected partition 1


Hex code (type L to list codes): 8e//8e


Changed system type of partition 1 to 8e (Linux LVM)





Command (M for help): P





disk/dev/xvdb:23.6 GB, 23622320128 bytes


255 heads, Sectors/track, 2871 cylinders


Units = Cylinders of 16065 * 8225280 bytes


Sector size (logical/physical): bytes/512 bytes


I/O size (minimum/optimal): bytes/512 bytes


Disk identifier:0x27cc1f5a





Device Boot Start End Blocks Id System


/DEV/XVDB1 1 2871 23061276 8e Linux LVM//now LVM partition format





Command (M for help): Wq


The partition table has been altered!





Calling IOCTL () to re-read partition table.


Syncing disks.

4, create logical volume groups, and logical volumes, etc.

[Root@iz94zz3wqciz ~]# PVCREATE/DEV/XVDB1//Create physical volumes
Physical volume "/DEV/XVDB1" successfully created

[Root@iz94zz3wqciz ~]# vgcreate MYFILES/DEV/XVDB1//Create Logical Volume group
Volume Group "Myfiles" successfully created

[Root@iz94zz3wqciz ~]# Vgchange-ay myfiles//Activate Logical Volume group
0 Logical Volume (s) in volume Group "myfiles" now active

[Root@iz94zz3wqciz ~]# Vgdisplay myfiles | grep "Total PE"//View all PE for this volume group
Total PE 5629

[Root@iz94zz3wqciz ~]# lvcreate-l 5629-n Fastdfs myfiles//Creating logical volumes
Logical volume "Fastdfs" created.




5, formatting logical volumes





[Root@iz94zz3wqciz ~]# MKFS.EXT4/DEV/MYFILES/FASTDFS//formatted logical volume


MKE2FS 1.41.12 (17-may-2010)


FileSystem label=


OS Type:linux


Block size=4096 (log=2)


Fragment size=4096 (log=2)


Stride=0 blocks, stripe width=0 blocks


1441792 inodes, 5764096 blocks


288204 blocks (5.00%) reserved for the Super user


The Data block=0


Maximum filesystem blocks=4294967296


176 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





Writing Inode Tables:done


Creating journal (32768 blocks): Done


Writing superblocks and filesystem accounting Information:done





This filesystem would be automatically checked every mounts or


180 days, whichever comes. Use Tune2fs-c or-i to override.




6, set up automatic mount, and view partition





[Root@iz94zz3wqciz ~]# Echo '/dev/myfiles/fastdfs/mnt/fastdfs ext4 defaults 0 0 ' >>/etc/f Stab//Automatic mount


[Root@iz94zz3wqciz ~]# mount-a//Manual mount


[Root@iz94zz3wqciz ~]# DF


FileSystem 1k-blocks Used Available use% mounted on


/DEV/XVDA1 20641404 14778608 4814272 76%/


Tmpfs 509300 0 509300 0%/dev/shm


/dev/mapper/myfiles-fastdfs


22694396 176064 21365516 1%/mnt/fastdfs logical volumes are mounted





[Root@iz94zz3wqciz ~]# reboot//finish the best reboot




7, and then the expansion of a hard drive to the existing logical volume





[Root@iz94zz3wqciz ~]# FDISK/DEV/XVDC//Detailed process IBID., no detailed description of





[Root@iz94zz3wqciz ~]# reboot





[Root@iz94zz3wqciz ~]# PVCREATE/DEV/XVDC1//Create physical volumes


Physical volume "/DEV/XVDC1" successfully created





[Root@iz94zz3wqciz ~]# Vgextend MYFILES/DEV/XVDC1//Add new hard drive to volume group


Volume Group "Myfiles" successfully extended





[Root@iz94zz3wqciz ~]# Vgdisplay myfiles | grep "Total PE"//View all PE


Total PE 6907





[Root@iz94zz3wqciz ~]# lvresize-l 6907/dev/myfiles/fastdfs//re-set size


The Size of logical volume MYFILES/FASTDFS changed from 21.99 GiB (5629 extents) to 26.98 GiB (6907 extents).


Logical Volume Fastdfs successfully resized





[Root@iz94zz3wqciz ~]# Resize2fs/dev/myfiles/fastdfs//re-regulation size


RESIZE2FS 1.41.12 (17-may-2010)


FileSystem At/dev/myfiles/fastdfs is mounted on/mnt/fastdfs; On-line resizing required


Old desc_blocks = 2, new_desc_blocks = 2


Performing a on-line resize Of/dev/myfiles/fastdfs to 7072768 (4k) blocks.


The filesystem On/dev/myfiles/fastdfs is now 7072768 blocks long.





[Root@iz94zz3wqciz ~]# Df-h


FileSystem Size Used Avail use% mounted on


/DEV/XVDA1 20G 15G 4.6G 76%/


Tmpfs 498M 0 498M 0%/dev/shm


/dev/mapper/myfiles-fastdfs


27G 172M 26G 1%/mnt/fastdfs//new 5G hard Drive added

If it is a frequent expansion of the hard drive, LVM is preferred, the expansion is really convenient.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.