- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
环境:
模拟新加一块磁盘,并分区,挂载,永久挂载,然后写入数据,然后对分区扩容,测试扩容后分区里面的内容是否丢失。
查看所有分区:
[root@backup ~]# fdisk -l 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: 0x00040b96 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 1070 8388608 82 Linux swap / Solaris /dev/sda3 1070 13055 96263168 83 Linux Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0x00000000 |
开始分区:
[root@backup ~]# fdisk /dev/sdb 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): p #p是打印当前磁盘所有分区Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0xc6e44e94 Device Boot Start End Blocks Id System Command (m for help): n #n是新建分区Command action e extended p primary partition (1-4)p #新建主分区 |
查看刚刚分区的信息:/dev/sdb1
[root@backup ~]# fdisk -l 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: 0x00040b96 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 1070 8388608 82 Linux swap / Solaris /dev/sda3 1070 13055 96263168 83 Linux Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0xc6e44e94 Device Boot Start End Blocks Id System /dev/sdb1 1 130541 1048570551 83 Linux |
格式化分区:mkfs.ext4 /dev/sdb1
[root@backup ~]# mkfs.ext4 /dev/sdb1 Block size=4096 (log=2) 13107131 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 8000 block groups32768 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. |
挂载分区:
[root@backup backup]# mkdir /backup tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 ext4 190M 38M 142M 21% /boot /dev/sdb1 ext4 985G 72M 935G 1% /backup |
挂载磁盘:(永久挂载)
通过vi编辑器编辑/etc/fstab文件,内容如下,(最后一行是刚添加上去的):
[root@backup ~]# cat /etc/fstab # /etc/fstab # Created by anaconda on Mon May 14 02:01:11 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info #UUID=7d223255-1b77-4f58-bd72-262928547fcf / ext4 defaults 1 1 UUID=284d6b31-8723-497b-bc7b-3c12ede23ee6 /boot ext4 defaults 1 2UUID=5d36c1b3-df6e-480d-80ca-72befc66f5e9 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 /dev/sdb1 /backup ext4 defaults 0 0 |
第四列挂载参数:通过查看man mount 来查看
第五列是否要备份:(0为不备份,1为要备份,一般情况下不用做备份)
第六列自检程序 (0为不自检,1或2为要自检,如果是根分区要设置1,其它分区只能是2)
[root@backup ~]# echo backup >/backup/backup.txt |
此时机器不关机,用vmware vspere client扩容磁盘大小。
[root@backup ~]# fdisk -l /dev/sdb Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 cylindersUnits = 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: 0xc6e44e94 Device Boot Start End Blocks Id System /dev/sdb1 1 130541 1048570551 83 Linux |
此时发现扩容的磁盘容量看不到,所以还是重启一下吧,建议关机时候再扩容。
[root@backup ~]# umount /dev/sdb1 #取消挂载 [root@backup ~]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units tosectors (command 'u'). Command (m for help): p Disk /dev/sdb: 1181.1 GB, 1181116006400 bytes 255 heads, 63 sectors/track, 143595 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: 0xc6e44e94 Device Boot Start End Blocks Id System /dev/sdb1 1 130541 1048570551 83 Linux Command (m for help): d #因为此磁盘只有一个分区sdb1,所以按d删除时候默认不会让选择要删除的分区,如果有多个分区会提示要删除的分区。Selected partition 1 Command (m for help): p #打印当前分区,发现分区已删除Disk /dev/sdb: 1181.1 GB, 1181116006400 bytes 255 heads, 63 sectors/track, 143595 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: 0xc6e44e94 Device Boot Start End Blocks Id System Command (m for help): n #新建分区Command action e extended p primary partition (1-4)p #新建主分区 Partition number (1-4): 1 #和扩容前的分区标号必须一样 First cylinder (1-143595, default 1): #默认是1,比如要和扩容前的分区其实点一样,扩容前的分区起始也是1,这个是扩容的重点地方。 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-143595, default 143595): #终止的位置是默认是硬盘柱体的尾部,即使最大值,这个是要扩容的点,回车。Using default value 143595Command (m for help): w #w报错,并退出。 The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks. |
3、调整分区
e2fsck -f /dev/sdb1 #检查分区信息
resize2fs /dev/sdb1 #调整分区大小
[root@backup ~]# e2fsck -f /dev/sdb1 #由于磁盘容量很大,数据多的情况下需要等待一段时间 e2fsck 1.41.12 (17-May-2010)Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structurePass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdb1: 12/65536000 files (0.0% non-contiguous), 4164250/262142637 blocks [root@backup ~]# resize2fs /dev/sdb1 #由于磁盘容量很大,数据多的情况下需要等待一段时间 resize2fs 1.41.12 (17-May-2010)Resizing the filesystem on /dev/sdb1 to 288356701 (4k) blocks. The filesystem on /dev/sdb1 is now 288356701 blocks long. [root@backup ~]# mount /dev/sdb1 /backup/ [root@backup ~]# cat /backup/backup.txt lost+found/ [root@backup ~]# cat /backup/backup.txt backup |
发现扩容成功,扩容前的内容没有丢失。
售前咨询
售后咨询
备案咨询
二维码
TOP