{"id":537,"date":"2018-12-18T02:40:47","date_gmt":"2018-12-18T02:40:47","guid":{"rendered":"http:\/\/www.asianux.org.vn\/?p=537"},"modified":"2018-12-18T02:40:48","modified_gmt":"2018-12-18T02:40:48","slug":"add-more-disk-using-lvm","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2018\/12\/18\/add-more-disk-using-lvm\/","title":{"rendered":"Add more disk using LVM"},"content":{"rendered":"\n<p>Step 1: Check disk<\/p>\n\n\n\n<p>Ch\u00fang ta c\u1ea7n ki\u1ec3m tra ch\u1eafc ch\u1eafn r\u1eb1ng partition c\u1ee7a ch\u00fang ta \u0111ang thao t\u00e1c l\u00e0 Linux LVM<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fdisk -l\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/viblo.asia\/uploads\/1d0c01d3-9fa1-49a3-98eb-b6a8fdf257bb.png\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>Nh\u01b0 b\u1ea1n c\u00f3 th\u1ec3 th\u1ea5y l\u00e0 \/dev\/sda5 \u1edf tr\u00ean l\u00e0 Linux LVM v\u00e0 n\u00f3 c\u00f3 ID l\u00e0 8e. 8e l\u00e0 m\u00e3 hex \u0111\u1ec3 th\u1ec3 hi\u1ec7n n\u00f3 l\u00e0 type ki\u1ec3u Linux LVM. Nh\u01b0 v\u1eady ch\u00fang ta \u0111\u00e3 ki\u1ec3m tra \u0111\u01b0\u1ee3c \u0111ang l\u00e0m vi\u1ec7c tr\u00ean Linux LVM r\u1ed3i.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/viblo.asia\/uploads\/9e2bf538-4587-42c3-837a-8104c36c6dcc.png\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>Nh\u01b0 th\u00f4ng tin trong \u1ea3nh b\u00ean d\u01b0\u1edbi th\u00ec \u1ed5 c\u1ee9ng hi\u1ec7n t\u1ea1i l\u00e0 20GB v\u00e0 n\u00f3 \u0111ang \u0111\u01b0\u1ee3c \u0111\u1eb7t trong logical v\u1edbi t\u00ean l\u00e0 \/dev\/mapper\/Mega-root n\u01a1i m\u00e0 ch\u00fang ta s\u1ebd m\u1edf r\u1ed9ng \u1ed5 c\u1ee9ng m\u1edbi.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"_2-increasing-the-virtual-hard-disk-5\">2. Increasing the virtual hard disk<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/viblo.asia\/uploads\/ab3bc955-7381-4064-8f3e-451be0660860.png\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>Ti\u1ebfp theo ch\u00fang ta c\u1ea7n thay \u0111\u1ed5i \u1ed5 c\u1ee9ng c\u1ee7a m\u00e1y \u1ea3o t\u1eeb 20GB th\u00e0nh 30GB b\u1eb1ng c\u00e1ch thay \u0111\u1ed5i setting c\u1ee7a VMWare.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"_3-detect-the-new-disk-space-6\">3. Detect the new disk space<\/h3>\n\n\n\n<p>Nh\u01b0 v\u1eady l\u00e0 ch\u00fang ta \u0111\u00e3 t\u0103ng \u0111\u01b0\u1ee3c \u1ed5 c\u1ee9ng \u1edf t\u1ea7ng hardware r\u1ed3i, ti\u1ebfp theo ch\u00fang ta s\u1ebd t\u1ea1o partition m\u1edbi d\u1ef1a tr\u00ean \u1ed5 c\u1ee9ng n\u00e0y.<\/p>\n\n\n\n<p>Tr\u01b0\u1edbc khi ch\u00fang ta c\u00f3 th\u1ec3 l\u00e0m \u0111\u01b0\u1ee3c \u0111i\u1ec1u n\u00e0y th\u00ec c\u1ea7n ph\u1ea3i check \u0111\u01b0\u1ee3c &#8220;unallocated disk&#8221; \u0111\u00e3 \u0111\u01b0\u1ee3c ph\u00e1t hi\u1ec7n \u1edf server ch\u01b0a. B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng l\u1ec7nh &#8220;fdisk -l&#8221; \u0111\u1ec3 xem danh s\u00e1ch primay disk. Tuy nhi\u00ean b\u1ea1n c\u00f3 th\u1ec3 s\u1ebd nh\u00ecn th\u1ea5y list gi\u1ed1ng nh\u01b0 tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u, \u1edf th\u1eddi \u0111i\u1ec3m n\u00e0y b\u1ea1n kh\u00f4ng c\u1ea7n ph\u1ea3i restart server m\u00e0 v\u1eabn c\u00f3 th\u1ec3 check \u0111\u01b0\u1ee3c thay \u0111\u1ed5i b\u1eb1ng command d\u01b0\u1edbi \u0111\u00e2y.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"- - -\" > \/sys\/class\/scsi_host\/host0\/scan\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/viblo.asia\/uploads\/f57dec51-e69a-40d2-a292-bdd2668198db.png\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>THeo nh\u01b0 h\u00ecnh \u1ea3nh b\u00ean d\u01b0\u1edbi th\u00ec ch\u00fang ta c\u00f3 th\u1ec3 x\u00e1c nh\u1eadn \u0111\u01b0\u1ee3c l\u00e0 \u0111\u00e3 hi\u1ec3n th\u1ecb bao g\u1ed3m c\u1ea3 \u1ed5 c\u1ee9ng m\u1edbi.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"_4-partition-the-new-disk-space-7\">4. Partition the new disk space<\/h3>\n\n\n\n<p>Nh\u01b0 b\u1ea1n \u0111\u00e3 th\u1ea5y ch\u00fang ta \u0111ang l\u00e0m vi\u1ec7c v\u1edbi \/dev\/sda v\u00e0 ch\u00fang ta s\u1ebd t\u1ea1o primary partition m\u1edbi b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng fdisk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fdisk \/dev\/sda\n<\/code><\/pre>\n\n\n\n<p>Ch\u00fang ta s\u1ebd l\u00e0m theo h\u01b0\u1edbng d\u1eabn nh\u01b0 b\u00ean d\u01b0\u1edbi v\u00e0 nh\u1eadp theo k\u00ed t\u1ef1 in \u0111\u1eadm. Ch\u00fa \u00fd ch\u1ecdn&nbsp;<code>m<\/code>&nbsp;\u0111\u1ec3 c\u00f3 th\u1ec3 get t\u1ea5t c\u1ea3 commands li\u00ean quan \u0111\u1ebfn fdisk<\/p>\n\n\n\n<p>\u2018n\u2019 l\u00e0 \u0111\u1ec3 th\u00eam partition m\u1edbi<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WARNING: DOS-compatible mode is deprecated. It's strongly recommended to\n         switch off the mode (command 'c') and change display units to\n         sectors (command 'u').\n\nCommand (m for help): n\n<\/code><\/pre>\n\n\n\n<p>\u2018p\u2019 l\u00e0 \u0111\u1ec3 t\u1ea1o primary partition<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command action\n   l   logical (5 or over)\n   p   primary partition (1-4)\np\n<\/code><\/pre>\n\n\n\n<p>Ch\u00fang ta \u0111\u00e3 c\u00f3 \/dev\/sda1 v\u00e0 \/dev\/sda2 nh\u01b0 tr\u00ean v\u00ec v\u1eady s\u1eed d\u1ee5ng&nbsp;<code>3<\/code>&nbsp;\u0111\u1ec3 t\u1ea1o \/dev\/sda3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Partition number (1-4): 3\n<\/code><\/pre>\n\n\n\n<p>Ti\u1ebfp theo enter 2 l\u1ea7n \u0111\u1ec3 nh\u1eadn default cylinders \u0111\u1ea7u v\u00e0 cu\u1ed1i<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>First cylinder (2611-3916, default 2611): \"enter\"\nUsing default value 2611\nLast cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916): \"enter\"\nUsing default value 3916\n<\/code><\/pre>\n\n\n\n<p>\u2018t\u2019 l\u00e0 \u0111\u1ec3 thay \u0111\u1ed5i system ID c\u1ee7a partition, trong tr\u01b0\u1eddng h\u1ee3p n\u00e0y s\u1ebd thay \u0111\u1ed5i v\u1ec1&nbsp;<code>3<\/code>&nbsp;v\u1eeba \u0111\u01b0\u1ee3c t\u1ea1o \u1edf tr\u00ean.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command (m for help): t\nPartition number (1-5): 3\n<\/code><\/pre>\n\n\n\n<p>M\u00e3 code hex&nbsp;<code>8e<\/code>&nbsp;l\u00e0 code cho Linux LVM<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Hex code (type L to list codes): 8e\nChanged system type of partition 3 to 8e (Linux LVM)\n<\/code><\/pre>\n\n\n\n<p>\u2018w\u2019 l\u00e0 \u0111\u1ec3 ghi v\u00e0o b\u1ea3ng c\u00e1c disk v\u00e0 exit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\n\nWARNING: Re-reading the partition table failed with error 16: Device or resource busy.\nThe kernel still uses the old table. The new table will be used at\nthe next reboot or after you run partprobe(8) or kpartx(8)\nSyncing disks.\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/viblo.asia\/uploads\/3f462365-9057-4b25-be0a-87c794bca268.png\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>B\u1ea1n c\u00f3 th\u1ec3 th\u1ea5y c\u1ea3nh b\u00e1o c\u1ea7n reboot l\u1ea1i nh\u01b0ng n\u1ebfu b\u1ea1n ko th\u1ea5y partition m\u1edbi b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng &#8220;fdisk -l&#8221; th\u00ec c\u00f3 th\u1ec3 ch\u1ea1y &#8220;partprobe -s&#8221; \u0111\u1ec3 qu\u00e9t l\u1ea1i b\u1ea3ng partition.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"_5-increasing-the-logical-volume-8\">5. Increasing the logical volume<\/h3>\n\n\n\n<p>S\u1eed d\u1ee5ng l\u1ec7nh pvcreate \u0111\u1ec3 t\u1ea1o physical volume s\u1eed d\u1ee5ng LVM.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  Device \/dev\/sda3 not found (or ignored by filtering).\n<\/code><\/pre>\n\n\n\n<p>\u0111\u1ec3 kh\u00f4ng ph\u1ea3i reboot l\u1ea1i th\u00ec b\u1ea1n ph\u1ea3i s\u1eed d\u1ee5ng partprobe\/partx sau \u0111\u00f3 th\u1ef1c hi\u1ec7n l\u1ea1i l\u1ec7nh pvcreate.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# pvcreate \/dev\/sda3\n  Physical volume \"\/dev\/sda3\" successfully created\n<\/code><\/pre>\n\n\n\n<p>Ti\u1ebfp theo ki\u1ec3m tra xem t\u00ean hi\u1ec7n t\u1ea1i c\u1ee7a volume group b\u1eb1ng l\u1ec7nh vgdisplay.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# vgdisplay\n  --- Volume group ---\n  VG Name               Mega\n...\nVG Size               19.76 GiB\n<\/code><\/pre>\n\n\n\n<p>B\u00e2y gi\u1edd m\u1edf r\u1ed9ng &#8220;Mega&#8221; b\u1eb1ng c\u00e1ch add th\u00eam physical volume \/dev\/sda3 b\u1eb1ng l\u1ec7nh pvcreate<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# vgextend Mega \/dev\/sda3\n  Volume group \"Mega\" successfully extended\n<\/code><\/pre>\n\n\n\n<p>S\u1eed d\u1ee5ng l\u1ec7nh pvscan \u0111\u1ec3 scan t\u1ea5t c\u1ea3 disk cho physical volumes. N\u00f3 s\u1ebd bao g\u1ed3m \/dev\/sda5 ban \u0111\u1ea7u v\u00e0 physical volume v\u1eeba th\u00eam \/dev\/sda3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# pvscan\n  PV \/dev\/sda5   VG Mega   lvm2 [19.76 GiB \/ 0    free]\n  PV \/dev\/sda3   VG Mega   lvm2 [10.00 GiB \/ 10.00 GiB free]\n  Total: 2 [29.75 GiB] \/ in use: 2 [29.75 GiB] \/ in no VG: 0 [0   ]\n<\/code><\/pre>\n\n\n\n<p>Ti\u1ebfp theo l\u00e0 t\u0103ng logical volume \u0110\u1ea7u ti\u00ean ki\u1ec3m tra \u0111\u01b0\u1eddng d\u1eabn c\u1ee7a logical volume s\u1eed d\u1ee5ng lvdisplay<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# lvdisplay\n  --- Logical volume ---\n  LV Path                \/dev\/Mega\/root\n<\/code><\/pre>\n\n\n\n<p>Extend logical volume s\u1eed d\u1ee5ng<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Mega:~# lvextend \/dev\/Mega\/root \/dev\/sda3\n Extending logical volume root to 28.90 GiB\n Logical volume root successfully resized\n<\/code><\/pre>\n\n\n\n<p>B\u01b0\u1edbc cu\u1ed1i c\u00f9ng l\u00e0 resize l\u1ea1i file system s\u1eed d\u1ee5ng resize2fs<\/p>\n\n\n\n<p>Step 2:\u00a0xfs_growfs \/dev\/Mega\/root<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Check disk Ch\u00fang ta c\u1ea7n ki\u1ec3m tra ch\u1eafc ch\u1eafn r\u1eb1ng partition c\u1ee7a ch\u00fang ta \u0111ang thao t\u00e1c l\u00e0 Linux LVM Nh\u01b0 b\u1ea1n c\u00f3 th\u1ec3 th\u1ea5y l\u00e0 \/dev\/sda5 \u1edf tr\u00ean l\u00e0 Linux LVM v\u00e0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-537","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=537"}],"version-history":[{"count":1,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/537\/revisions"}],"predecessor-version":[{"id":538,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/537\/revisions\/538"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}