背景
當前市面上大部分的雲服務器產品,在購買Linux服務器並啓動後,通常只幫我們掛載了系統盤到/目錄。我們所購買的數據盤並沒有幫我們掛載到系統。查看內存配置,一般swap也爲0。
這裏我們可以利用購買的數據盤來創建swap分區與數據分區,並將他們掛載到系統中去。
操作
1,查看當前的磁盤,如下,/dev/vda爲系統盤,/dev/vdb爲數據盤:
# fdisk -l Disk /dev/vda: 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: 0x0008e9bc Device Boot Start End Blocks Id System /dev/vda1 * 2048 2099199 1048576 83 Linux /dev/vda2 2099200 104857566 51379183+ 83 Linux Disk /dev/vdb: 429.5 GB, 429496729600 bytes, 838860800 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
2,對/dev/vdb進行分區操作,分割16G空間做swap,剩餘空間做數據盤。
# fdisk /dev/vdb 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 0xb07be21f. 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): First sector (2048-838860799, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-838860799, default 838860799): +16G Partition 1 of type Linux and of size 16 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (33556480-838860799, default 33556480): Using default value 33556480 Last sector, +sectors or +size{K,M,G} (33556480-838860799, default 838860799): Using default value 838860799 Partition 2 of type Linux and of size 384 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. # fdisk -l Disk /dev/vda: 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: 0x0008e9bc Device Boot Start End Blocks Id System /dev/vda1 * 2048 2099199 1048576 83 Linux /dev/vda2 2099200 104857566 51379183+ 83 Linux Disk /dev/vdb: 429.5 GB, 429496729600 bytes, 838860800 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: 0x53b4d701 Device Boot Start End Blocks Id System /dev/vdb1 2048 33556479 16777216 83 Linux /dev/vdb2 33556480 838860799 402652160 83 Linux
可以看到創建了2個分區/dev/vdb1,/dev/vdb2。
3,創建swap分區,並啓用:
# mkswap /dev/vdb1 # swapon /dev/vdb1
4,把/dev/vdb2格式化,並掛載到/data目錄下:(這裏格式成xfs文件系統)
# mkdir -p /data # mkfs.xfs /dev/vdb2 # mount /dev/vdb2 /data
5,檢查是否生效:
# df -kh Filesystem Size Used Avail Use% Mounted on /dev/vda2 49G 1.7G 45G 4% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 25M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/vda1 976M 146M 764M 16% /boot tmpfs 1.6G 0 1.6G 0% /run/user/0 /dev/vdb2 384G 33M 384G 1% /data # free -m total used free shared buff/cache available Mem: 15885 393 14628 24 863 15158
6,把磁盤掛載信息寫進fstab,使之開啓自動掛載:
# vi /etc/fstab /dev/vdb1 swap swap defaults 0 0 /dev/vdb2 /data xfs defaults 0 0