{"id":3129,"date":"2014-06-12T22:43:06","date_gmt":"2014-06-12T14:43:06","guid":{"rendered":"http:\/\/rmohan.com\/?p=3129"},"modified":"2014-06-12T22:43:06","modified_gmt":"2014-06-12T14:43:06","slug":"e2label-fdisk-etcfstab-mount-linux-rescue-rescue-disk-centos","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3129","title":{"rendered":"e2label, fdisk, \/etc\/fstab, mount, linux rescue, rescue disk, CentOS"},"content":{"rendered":"<table style=\"color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-style: normal; word-spacing: 0px; background-color: #ffffff; -webkit-text-stroke-width: 0px;\" border=\"0\" width=\"570\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td class=\"maintext\" width=\"75%\"><b>Tutorial: e2label, fdisk, \/etc\/fstab, mount, linux rescue, rescue disk, CentOS<\/b><\/td>\n<\/tr>\n<tr>\n<td class=\"maintext\" colspan=\"2\">\nLet&#8217;s run through an example of a fresh disk, that needs to be configured, going through partitioning with fdisk, make filesystem, filesystem labelled using e2label, \/etc\/fstab edited, and mounted using mount. This is relevent for CentOS 3.x, 4.x 5.x; YMMV for other flavours.<\/p>\n<p>First, a run through of each command, with usage examples.<\/p>\n<p><span style=\"text-decoration: underline;\"><b>fdisk<\/b><\/span><\/p>\n<p>if the partitioning of the drive is unknown, fdisk -l can be used to list the partition table of the drive. eg. fdisk -l \/dev\/sdb<\/p>\n<p>following is an example of a disk without a partition table<\/p>\n<p># fdisk -l \/dev\/sdb<\/p>\n<p>Disk \/dev\/sdb: 74.3 GB, 74355769344 bytes<br \/>\n255 heads, 63 sectors\/track, 9039 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<p>Disk \/dev\/sdb doesn&#8217;t contain a valid partition table<\/p>\n<p>and here&#8217;s an example of a disk with valid partition table<\/p>\n<p># fdisk -l \/dev\/sda<\/p>\n<p>Disk \/dev\/sda: 299.9 GB, 299974524928 bytes<br \/>\n255 heads, 63 sectors\/track, 36469 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<table style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-style: normal;\" border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n<tbody>\n<tr>\n<td><b>Device<\/b><\/td>\n<td><b>Boot<\/b><\/td>\n<td><b>Start<\/b><\/td>\n<td><b>End<\/b><\/td>\n<td><b>Blocks<\/b><\/td>\n<td><b>Id<\/b><\/td>\n<td><b>System<\/b><\/td>\n<\/tr>\n<tr>\n<td>\/dev\/sda1<\/td>\n<td>*<\/td>\n<td>1<\/td>\n<td>13<\/td>\n<td>104391<\/td>\n<td>83<\/td>\n<td>Linux<\/td>\n<\/tr>\n<tr>\n<td>\/dev\/sda2<\/td>\n<td><\/td>\n<td>14<\/td>\n<td>268<\/td>\n<td>2048287+<\/td>\n<td>82<\/td>\n<td>Linux swap<\/td>\n<\/tr>\n<tr>\n<td>\/dev\/sda3<\/td>\n<td><\/td>\n<td>269<\/td>\n<td>36469<\/td>\n<td>290784532+<\/td>\n<td>83<\/td>\n<td>Linux<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>to change the partitions on a drive without partition table, such as a new drive, use fdisk<span class=\"Apple-converted-space\">\u00a0<\/span><br \/>\neg. fdisk \/dev\/sdb<\/p>\n<p># fdisk \/dev\/sdb<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel. Changes will remain in memory only,<br \/>\nuntil you decide to write them. After that, of course, the previous<br \/>\ncontent won&#8217;t be recoverable.<\/p>\n<p>The number of cylinders for this disk is set to 9039.<br \/>\nThere is nothing wrong with that, but this is larger than 1024,<br \/>\nand could in certain setups cause problems with:<br \/>\n1) software that runs at boot time (e.g., old versions of LILO)<br \/>\n2) booting and partitioning software from other OSs<br \/>\n(e.g., DOS FDISK, OS\/2 FDISK)<\/p>\n<p>Command (m for help):<\/p>\n<p>m will list the options available.<br \/>\neg. p will print the partition table, n is for adding new partition table;<span class=\"Apple-converted-space\">\u00a0<\/span><br \/>\nand after the changes are done, w will commit the changes, and exit the program.<\/p>\n<p><b><span style=\"text-decoration: underline;\">e2label<\/span><\/b><\/p>\n<p>Usage of e2label is simple. manpage for e2label shows following command line options,<\/p>\n<p>e2label device [ new-label ]<\/p>\n<p>device can be the entire drive or a partition.<br \/>\neg.<br \/>\n\/dev\/sda is the entire drive<br \/>\n\/dev\/sda1 is the first partition of device \/dev\/sda<br \/>\n\/dev\/sda2 is the second partition of device \/dev\/sda<\/p>\n<p>eg. to show the label of \/dev\/sda1 and \/dev\/sda3<\/p>\n<p># e2label \/dev\/sda1<br \/>\n\/boot<\/p>\n<p># e2label \/dev\/sda3<br \/>\n\/<\/p>\n<p>To change the label for \/dev\/sda3, do as follows,<br \/>\n# e2label \/dev\/sda3 changed-label<\/p>\n<p>and to confirm the change was done sucessfully,<br \/>\n# e2label \/dev\/sda3<br \/>\nchanged-label<\/p>\n<p>if you want a \/ in front of the label,<\/p>\n<p># e2label \/dev\/sda3 \/changed-label<\/p>\n<p>to verify that the change was done,<\/p>\n<p># e2label \/dev\/sda3<br \/>\n\/changed-label<\/p>\n<p>if you want the server to be able to boot next time round, ensure changes are made to \/etc\/fstab as well. Otherwise, on the next boot, you may be prompted with errors, eg.<\/p>\n<p>fsck.ext3: Unable to resolve &#8216;LABEL=\/boot&#8217;<br \/>\nfsck.ext3: Unable to resolve &#8216;LABEL=\/&#8217;<\/p>\n<p>in which case, you can boot up with a rescue disk, eg. CentOS installation disk, enter &#8220;linux rescue&#8221; at prompt; chroot \/mnt\/sysimage and edit \/etc\/fstab accordingly. Alternatively, if you are prompted for root password, and gets a shell, you may be able to edit \/etc\/fstab. If the filesystem is readonly, remount the filesytem readwrite. eg. mount -o remount,rw \/<\/p>\n<p><b><span style=\"text-decoration: underline;\">mount, umount<\/span><\/b><\/p>\n<p># mount \/dev\/sdb5 \/tmp\/mnt<\/p>\n<p>will mount \/dev\/sdb5 on the \/tmp\/mnt directory<br \/>\nif \/tmp\/mnt does not exist, it needs to be created, using mkdir<\/p>\n<p>to unmount the device, use umount \/dev\/sdb5 or umount \/tmp\/mnt<\/p>\n<p><b><span style=\"text-decoration: underline;\">Example of partitioning, formatting and labelling of a new drive<\/span><\/b><\/p>\n<p>2 partitions to be created<br \/>\n100MB and rest of the drive<\/p>\n<p># fdisk \/dev\/sdb<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel. Changes will remain in memory only,<br \/>\nuntil you decide to write them. After that, of course, the previous content won&#8217;t be recoverable.<\/p>\n<p>The number of cylinders for this disk is set to 9039.<br \/>\nThere is nothing wrong with that, but this is larger than 1024,<br \/>\nand could in certain setups cause problems with:<br \/>\n1) software that runs at boot time (e.g., old versions of LILO)<br \/>\n2) booting and partitioning software from other OSs<br \/>\n(e.g., DOS FDISK, OS\/2 FDISK)<\/p>\n<p>Command (m for help): n<br \/>\nCommand action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 1<br \/>\nFirst cylinder (1-9039, default 1):<br \/>\nUsing default value 1<br \/>\nLast cylinder or +size or +sizeM or +sizeK (1-9039, default 9039): +100M<\/p>\n<p>Command (m for help): n<br \/>\nCommand action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 2<br \/>\nFirst cylinder (14-9039, default 14):<br \/>\nUsing default value 14<br \/>\nLast cylinder or +size or +sizeM or +sizeK (14-9039, default 9039):<br \/>\nUsing default value 9039<\/p>\n<p>Command (m for help): p<\/p>\n<p>Disk \/dev\/sdb: 74.3 GB, 74355769344 bytes<br \/>\n255 heads, 63 sectors\/track, 9039 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<\/p>\n<table style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-style: normal;\" border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n<tbody>\n<tr>\n<td><b>Device<\/b><\/td>\n<td><b>Boot<\/b><\/td>\n<td><b>Start<\/b><\/td>\n<td><b>End<\/b><\/td>\n<td><b>Blocks<\/b><\/td>\n<td><b>Id<\/b><\/td>\n<td><b>System<\/b><\/td>\n<\/tr>\n<tr>\n<td>\/dev\/sda1<\/td>\n<td><\/td>\n<td>1<\/td>\n<td>13<\/td>\n<td>104391<\/td>\n<td>83<\/td>\n<td>Linux<\/td>\n<\/tr>\n<tr>\n<td>\/dev\/sda2<\/td>\n<td><\/td>\n<td>14<\/td>\n<td>9039<\/td>\n<td>72501345<\/td>\n<td>83<\/td>\n<td>Linux<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Command (m for help): w<br \/>\nThe partition table has been altered!<\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<\/p>\n<p>Next: format both partitions as ext3 filesystems<\/p>\n<p># mkfs.ext3 \/dev\/sdb1<br \/>\nmke2fs 1.39 (29-May-2006)<br \/>\nFilesystem label=<br \/>\nOS type: Linux<br \/>\nBlock size=1024 (log=0)<br \/>\nFragment size=1024 (log=0)<br \/>\n26104 inodes, 104388 blocks<br \/>\n5219 blocks (5.00%) reserved for the super user<br \/>\nFirst data block=1<br \/>\nMaximum filesystem blocks=67371008<br \/>\n13 block groups<br \/>\n8192 blocks per group, 8192 fragments per group<br \/>\n2008 inodes per group<br \/>\nSuperblock backups stored on blocks:<br \/>\n8193, 24577, 40961, 57345, 73729<\/p>\n<p>Writing inode tables: done<br \/>\nCreating journal (4096 blocks): done<br \/>\nWriting superblocks and filesystem accounting information: done<\/p>\n<p>This filesystem will be automatically checked every 22 mounts or<br \/>\n180 days, whichever comes first. Use tune2fs -c or -i to override.<\/p>\n<p># mkfs.ext3 \/dev\/sdb2<br \/>\nmke2fs 1.39 (29-May-2006)<br \/>\nFilesystem label=<br \/>\nOS type: Linux<br \/>\nBlock size=4096 (log=2)<br \/>\nFragment size=4096 (log=2)<br \/>\n9076736 inodes, 18125336 blocks<br \/>\n906266 blocks (5.00%) reserved for the super user<br \/>\nFirst data block=0<br \/>\nMaximum filesystem blocks=4294967296<br \/>\n554 block groups<br \/>\n32768 blocks per group, 32768 fragments per group<br \/>\n16384 inodes per group<br \/>\nSuperblock backups stored on blocks:<br \/>\n32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424<\/p>\n<p>Writing inode tables: done<br \/>\nCreating journal (32768 blocks): done<br \/>\nWriting superblocks and filesystem accounting information: done<\/p>\n<p>This filesystem will be automatically checked every 33 mounts or<br \/>\n180 days, whichever comes first. Use tune2fs -c or -i to override.<\/p>\n<p>next: use e2label to label the volumes. Although both mkfs3.ext and<span class=\"Apple-converted-space\">\u00a0<\/span><br \/>\ntune2fs is capable of labelling, with the -L option, I am deliberately<span class=\"Apple-converted-space\">\u00a0<\/span><br \/>\nusing e2label in this example to demonstrate the use of e2label.<\/p>\n<p># e2label \/dev\/sdb1 \/drive2-100MB<\/p>\n<p>confirm its done.<\/p>\n<p># e2label \/dev\/sdb1<br \/>\n\/drive2-100MB<\/p>\n<p>label sdb2 next,<\/p>\n<p># e2label \/dev\/sdb2 \/drive2-restofdrive<br \/>\nWarning: label too long, truncating.<br \/>\n# e2label \/dev\/sdb2<br \/>\n\/drive2-restofdr<\/p>\n<p>the description used was too long, and got truncated. maximum for label is 16 characters.<\/p>\n<p>next, we try to mount and unmount the 2 filesystems created,<\/p>\n<p>mount shows what has already been mounted. in addition, the -l option shows the filesystem label<\/p>\n<p># mount -l<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\nproc on \/proc type proc (rw)<br \/>\nsysfs on \/sys type sysfs (rw)<br \/>\ndevpts on \/dev\/pts type devpts (rw,gid=5,mode=620)<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<br \/>\ntmpfs on \/dev\/shm type tmpfs (rw)<br \/>\nnone on \/proc\/sys\/fs\/binfmt_misc type binfmt_misc (rw)<br \/>\nsunrpc on \/var\/lib\/nfs\/rpc_pipefs type rpc_pipefs (rw)<\/p>\n<p>We are mainly concerned with the drives, so let&#8217;s grep for the relevent entries<\/p>\n<p>#mount -l | grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<\/p>\n<p>We need mount points; the following mount points are created,<br \/>\n# mkdir \/mountpt1<br \/>\n# mkdir \/mountpt2<\/p>\n<p>to manually mount the drives,<br \/>\n# mount \/dev\/sdb1 \/mountpt1<\/p>\n<p>check that it is mounted,<br \/>\n# mount -l|grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<br \/>\n\/dev\/sdb1 on \/mountpt1 type ext3 (rw) [\/drive2-100MB]<\/p>\n<p># mount \/dev\/sdb2 \/mountpt2<br \/>\n# mount -l|grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<br \/>\n\/dev\/sdb1 on \/mountpt1 type ext3 (rw) [\/drive2-100MB]<br \/>\n\/dev\/sdb2 on \/mountpt2 type ext3 (rw) [\/drive2-restofdr]<\/p>\n<p>to unmount, use umount<br \/>\n# umount \/dev\/sdb1<br \/>\n# umount \/dev\/sdb2<br \/>\n# mount -l|grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<\/p>\n<p>we can also mount the filesystems using the filesystem labels,<br \/>\n# mount -L \/drive2-100MB \/mountpt1\/<br \/>\n# mount -L \/drive2-restofdr \/mountpt2\/<br \/>\n# mount -l |grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<br \/>\n\/dev\/sdb1 on \/mountpt1 type ext3 (rw) [\/drive2-100MB]<br \/>\n\/dev\/sdb2 on \/mountpt2 type ext3 (rw) [\/drive2-restofdr]<\/p>\n<p>unmount can also use the mount point instead of the device, eg.<\/p>\n<p># umount \/mountpt1<br \/>\n# umount \/mountpt2<br \/>\n# mount -l |grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<\/p>\n<p>next: edit \/etc\/fstab, add in entries for the new drive if we want it to be mounted at boot up.<\/p>\n<p>following is existing \/etc\/fstab for the server, which was installed for purpose of this tutorial,<\/p>\n<table style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-style: normal;\" border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n<tbody>\n<tr>\n<td>LABEL=\/<\/td>\n<td>\/<\/td>\n<td>ext3<\/td>\n<td>defaults<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>LABEL=\/boot<\/td>\n<td>\/boot<\/td>\n<td>ext3<\/td>\n<td>defaults<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>tmpfs<\/td>\n<td>\/dev\/shm<\/td>\n<td>tmpfs<\/td>\n<td>defaults<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>devpts<\/td>\n<td>\/dev\/pts<\/td>\n<td>devpts<\/td>\n<td>gid=5,mode=620<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>sysfs<\/td>\n<td>\/sys<\/td>\n<td>sysfs<\/td>\n<td>defaults<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>proc<\/td>\n<td>\/proc<\/td>\n<td>proc<\/td>\n<td>defaults<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>LABEL=SWAP-sda2<\/td>\n<td>swap<\/td>\n<td>swap<\/td>\n<td>defaults<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>add the following entries,<\/p>\n<table style=\"color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-style: normal;\" border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"2\" align=\"center\">\n<tbody>\n<tr>\n<td>LABEL=\/drive2-100MB<\/td>\n<td>\/mountpt1<\/td>\n<td>ext3<\/td>\n<td>defaults<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>LABEL=\/drive2-restofdr<\/td>\n<td>\/mountpt2<\/td>\n<td>ext3<\/td>\n<td>defaults<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>mount has a -a option which reads \/etc\/fstab and mounts all filesystems mentioned in the file,<\/p>\n<p># mount -a<br \/>\n# mount -l |grep \/dev\/sd<br \/>\n\/dev\/sda3 on \/ type ext3 (rw) [\/]<br \/>\n\/dev\/sda1 on \/boot type ext3 (rw) [\/boot]<br \/>\n\/dev\/sdb1 on \/mountpt1 type ext3 (rw) [\/drive2-100MB]<br \/>\n\/dev\/sdb2 on \/mountpt2 type ext3 (rw) [\/drive2-restofdr]<\/p>\n<p>next, reboot, and ensure the new drive is mounted automatically, and accessible via the mount points, \/mountpt1, \/mountpt2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p> Tutorial: e2label, fdisk, \/etc\/fstab, mount, linux rescue, rescue disk, CentOS Let&#8217;s run through an example of a fresh disk, that needs to be configured, going through partitioning with fdisk, make filesystem, filesystem labelled using e2label, \/etc\/fstab edited, and mounted using mount. This is relevent for CentOS 3.x, 4.x 5.x; YMMV for other flavours.<\/p>\n<p>First, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3129"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3129"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3129\/revisions"}],"predecessor-version":[{"id":3131,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3129\/revisions\/3131"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}