1 查看centos设备信息
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 65.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part └─centos-root 253:0 0 65.1G 0 lvm / sr0 11:0 1 4.2G 0 rom NAME : 这是块设备名。 MAJ:MIN : 显示主要和次要设备号。 RM : 显示设备是否可移动设备。sr0的RM值等于1,这说明他们是可移动设备。 SIZE : 列出设备的容量大小信息。例如50G表明该设备大小为50G,而1K表明该设备大小为1KB。 RO : 该项表明设备是否为只读。在本案例中,所有设备的RO值为0,表明他们不是只读的。 TYPE :显示块设备是否是磁盘或磁盘上的一个分区。在本例中,sda和sdb是磁盘,而sr0是只读存储(rom)。 MOUNTPOINT : 指出设备挂载的挂载点。
2 虚拟机,扩展根目录,使用lvm
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 46G 3.1G 43G 7% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.0M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 178M 837M 18% /boot tmpfs 380M 8.0K 380M 1% /run/user/42 tmpfs 380M 0 380M 0% /run/user/1000 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 45.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom
1 添加多块磁盘(vm上添加2块50g磁盘),扩展根目录
[root@zabbix ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 46G 12G 34G 27% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.1M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 178M 837M 18% /boot tmpfs 380M 8.0K 380M 1% /run/user/42 tmpfs 380M 0 380M 0% /run/user/0 tmpfs 380M 0 380M 0% /run/user/1000 ##lsblk查看新插入硬盘情况,如果未显示新添加的磁盘,需用 echo "- - -" > /sys/class/scsi_host/host0/scan,此命令进行激活,激活后即可查看到新加的磁盘。 [root@zabbix ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 45.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk sdc 8:32 0 50G 0 disk sr0 11:0 1 4.2G 0 rom [root@zabbix ~]# ll /dev/sdb /dev/sdc brw-rw---- 1 root disk 8, 16 Sep 11 09:00 /dev/sdb brw-rw---- 1 root disk 8, 32 Sep 11 09:00 /dev/sdc
[root@zabbix ~]# fdisk /dev/sdb ##选择新增硬盘 Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xb0001f51. Command (m for help): p ##查看已分区数量 Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xb0001f51 Device Boot Start End Blocks Id System Command (m for help): n ##新增加一个分区 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p ##分区类型选择为主分区 Partition number (1-4, default 1): 1 ##分区号选1,由于扩容盘所以只只设置一个分区 First sector (2048-104857599, default 2048): ##回车 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): #默认 回车 Using default value 104857599 Partition 1 of type Linux and of size 50 GiB is set Command (m for help): p Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xb0001f51 ##增加分区,会发现多了一个分区 Device Boot Start End Blocks Id System /dev/sdb1 2048 104857599 52427776 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 1 WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation. Changed type of partition 'Linux' to 'FAT12' Command (m for help): t ## Selected partition 1 Hex code (type L to list all codes): 8e ##修改分区类型,把linux修改为'Linux LVM' WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation. Changed type of partition 'FAT12' to 'Linux LVM' Command (m for help): p ##再次查看分区情况确认是否修改成功 Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0xb0001f51 Device Boot Start End Blocks Id System /dev/sdb1 2048 104857599 52427776 8e Linux LVM ##此次修改成功 Command (m for help): w ##最后写入分区表,保存并退出即可 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.