Linux磁盘扩容
-
#>
fdisk -l
【查看磁盘分区信息】Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003f0c9 Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2358 18631680 83 Linux /dev/sda3 2358 2611 2031616 82 Linux swap / Solaris Disk /dev/sdb: 20 MB, 20971520 bytes 64 heads, 32 sectors/track, 20 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2fb9f21b Device Boot Start End Blocks Id System /dev/sdb1 1 20 20464 83 Linux
-
扩容磁盘【必须在root用户下】
-
【虚拟机】–>【设置】–>【添加】–>【硬盘】–>【设置硬盘大小】–>【重启生效设置】
-
#>
fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003f0c9 Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2358 18631680 83 Linux /dev/sda3 2358 2611 2031616 82 Linux swap / Solaris Disk /dev/sdb: 20 MB, 20971520 bytes 64 heads, 32 sectors/track, 20 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 【表示有两个硬盘接入该主机,但第二块硬盘sdb并没有初始化及挂载】
-
#>
fdisk /dev/sdb
【对sdb硬盘进行分区】Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x7e8a79c7. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help):
-
#>
m
【显示帮助页面】Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help):
-
#>
n
【新建分区】Command action e extended p primary partition (1-4)【p是主分区】
-
Partition number (1-4):
1
【选择标识1】First cylinder (1-20, default 1): 【直接回车,默认选择】 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-20, default 20): 【直接回车,默认选择】 Using default value 20
-
Command (m for help):
w
【写入磁盘】The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
-
-
-
#>
fdisk -l
【验证分区是否成功】Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003f0c9 Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 2358 18631680 83 Linux /dev/sda3 2358 2611 2031616 82 Linux swap / Solaris Disk /dev/sdb: 20 MB, 20971520 bytes 64 heads, 32 sectors/track, 20 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x79f61b29 Device Boot Start End Blocks Id System /dev/sdb1 1 20 20464 83 Linux 【disk identifier:不再是0,且出现sdb1详细信息,则分区成功】
-
#>
mkfs -t ext4 /dev/sdb1
【格式化分区】【或者#>mkfs.ext4 /dev/sdb1一样效果】mke2fs 1.41.12 (17-May-2010) 文件系统标签=<br/>操作系统:Linux 块大小=1024 (log=0) 分块大小=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 5136 inodes, 20464 blocks 1023 blocks (5.00%) reserved for the super user 第一个数据块=1 Maximum filesystem blocks=20971520 3 block groups 8192 blocks per group, 8192 fragments per group 1712 inodes per group Superblock backups stored on blocks: 8193 正在写入inode表: 完成 Creating journal (1024 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 【格式化成功】
-
【创建一个文件夹,用于给新硬盘挂载】
-
#>
cd /
-
#>
mkdir /bigdata
-
-
#>
mount /dev/sdb1 /bigdata
【临时挂载】 -
在【/etc/fstab】文件中设置如下:
/dev/sdb1 /bigdata ext4 defaults 0 0 UUID=d007ccc8-2cda-402a-92e4-f43f278e1b8e / ext4 defaults 1 1 UUID=c38b2816-6ba3-44e1-91d8-a84a3668cf55 /boot ext4 defaults 1 2 UUID=b71f194a-bc89-4500-bff6-a18daff11e23 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 【将sdb1硬盘的信息添加至首行,完成永久挂载硬盘】
-
第8步还可以如下设置:
-
#>
blkid
/dev/sda1: UUID="c38b2816-6ba3-44e1-91d8-a84a3668cf55" TYPE="ext4" /dev/sda2: UUID="d007ccc8-2cda-402a-92e4-f43f278e1b8e" TYPE="ext4" /dev/sda3: UUID="b71f194a-bc89-4500-bff6-a18daff11e23" TYPE="swap" /dev/sdb1: UUID="1406f0d3-49c5-4c3f-b579-126e12573a52" TYPE="ext4" 【将UUID填入,这两种意思一样】
UUID=1406f0d3-49c5-4c3f-b579-126e12573a52 /bigdata ext4 defaults 0 0 UUID=d007ccc8-2cda-402a-92e4-f43f278e1b8e / ext4 defaults 1 1 UUID=c38b2816-6ba3-44e1-91d8-a84a3668cf55 /boot ext4 defaults 1 2 UUID=b71f194a-bc89-4500-bff6-a18daff11e23 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 【将sdb1硬盘的信息添加至首行,完成永久挂载硬盘】
-
-
-