[root@centos6 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xc06ac594. 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'). #新建一个分区作为BOOT分区 Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +1G #新建一个分区作为/分区 Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (133-2610, default 133): Using default value 133 Last cylinder, +cylinders or +size{K,M,G} (133-2610, default 2610): +10G #新建一个分区作为swap分区 Command (m forhelp): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1439-2610, default 1439): Using default value 1439 Last cylinder, +cylinders or +size{K,M,G} (1439-2610, default 2610): +2G #更改SWAP分区标签 Command (m forhelp): t Partition number (1-4): 3 Hex code (type L to list codes): 82 Changed system type of partition 3 to 82 (Linux swap / Solaris) #查看下所创建的分区是否正确 Command (m forhelp): p
Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 83 Linux /dev/sdb2 133 1438 10490445 83 Linux /dev/sdb3 1439 1700 2104515 82 Linux swap / Solaris #确认无误写入磁盘 Command (m forhelp): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
[root@centos6 ~]# mkfs.ext4 /dev/sdb1 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 66384 inodes, 265064 blocks 13253 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=272629760 9 block groups 32768 blocks per group, 32768 fragments per group 7376 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376
[root@centos6 ~]# mkfs.ext4 /dev/sdb2 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 655776 inodes, 2622611 blocks 131130 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
3.sdb3使用swap系统
1 2 3
[root@centos6 ~]# mkswap /dev/sdb3 Setting up swapspace version 1, size = 2104508 KiB no label, UUID=2ae55ed1-8e5c-4d45-853d-1a4c94badfc2
四、对分区进行挂载
把sdb1挂载在/mnt/boot下,sdb2挂载在/mnt/sysroot下
1 2 3 4
[root@centos6 /]# mkdir /mnt/boot [root@centos6 /]# mount /dev/sdb1 /mnt/boot [root@centos6 /]# mkdir /mnt/sysroot [root@centos6 /]# mount /dev/sdb2 /mnt/sysroot
五、在/mnt/sysroot下创建相应的根文件系统目录
1 2 3 4 5 6
[root@centos6 sysroot]# cd /mnt/sysroot/ [root@centos6 sysroot]# for i in `ls /`;do mkdir $i;done [root@centos6 sysroot]# ls bin data etc lib lost+found misc net proc sbin srv tmp var boot dev home lib64 media mnt opt root selinux sys usr [root@centos6 sysroot]#
[root@centos6 boot]# grub-install --root-directory=/mnt /dev/sdb Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /mnt/boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) /dev/fd0 (hd0) /dev/sda (hd1) /dev/sdb [root@centos6 boot]# ls /mnt/boot grub initramfs-2.6.32-754.el6.x86_64.img vmlinuz-2.6.32-754.el6.x86_64
[root@centos6 ~]# bash +x cpcmd.sh please input a cmd: cp please input a cmd: ls please input a cmd: vim please input a cmd: cat please input a cmd: ping please input a cmd: ifconfig please input a cmd: modprobe please input a cmd: insmod please input a cmd: rm please input a cmd: lsblk please input a cmd: blkid please input a cmd: mount please input a cmd: swapon please input a cmd: df please input a cmd: hostname please input a cmd: exit
[root@centos6 ~]# cp /lib/modules//2.6.32-754.el6.x86_64//kernel//drivers/net/e1000/e1000.ko /mnt/sysroot/lib [root@centos6 ~]# ls /mnt/sysroot/lib e1000.ko
十、切根测试
1 2 3 4 5 6
[root@centos6 ~]# chroot /mnt/sysroot/ bash-4.1# ls bin data etc lib lost+found misc net proc sbin srv tmp var boot dev home lib64 media mnt opt root selinux sys usr bash-4.1# hostname centos6.localdomain