{"id":4144,"date":"2015-01-27T19:10:06","date_gmt":"2015-01-27T11:10:06","guid":{"rendered":"http:\/\/rmohan.com\/?p=4144"},"modified":"2015-01-27T19:10:06","modified_gmt":"2015-01-27T11:10:06","slug":"how-to-resize-an-iscsi-lun-in-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4144","title":{"rendered":"How To Resize an iscsi LUN in Linux"},"content":{"rendered":"<p>Article ID: 83<br \/>\nby: Reese K.<br \/>\nPosted: 07 Jan, 2013<br \/>\nLast updated: 13 Mar, 2014<br \/>\nViews: 4849<\/p>\n<p>How To Resize an iscsi LUN in Linux<br \/>\nNetApp storage systems also allow you to resize a LUN dynamically; however, the iSCSI layer in Linux is not capable of detecting the change in the LUN size. To display the new size of the LUN you must restart the iSCSI service. But a restart of the iSCSI service fails if any iSCSI devices are mounted at that time. Because of this, even if the LUN on which the file system is located is resized, you must unmount the file system and then restart iSCSI and the multipathing service before Linux can detect the new size.<\/p>\n<p>Though this procedure below has been tested, it is always a good idea to back up your data before attempting resizing.<\/p>\n<p>Collect some information on the partition to be resized:<\/p>\n<p>For the purposes of this example, \/dev\/sdc1 is the iscsi lun partition to be resized.  Run through the following commands and set the information aside:<\/p>\n<p>~# df \/dev\/sdc1<br \/>\n~# df -h \/dev\/sdc1<br \/>\n~# fdisk -l \/dev\/sdc<br \/>\n~# fdisk -s \/dev\/sdc1<\/p>\n<p>The first two commands are to provide a &#8220;snapshot&#8221; look at the size of the partition before making any changes.  The third command contains useful information needed to successfully increase the partition in a later step.  Make note of the starting cylinder from the output.  For example:<br \/>\nPRODUCTION linux01 # fdisk -l \/dev\/sdc<\/p>\n<p>Disk \/dev\/sdc: 32.2 GB, 32212254720 bytes<br \/>\n64 heads, 32 sectors\/track, 30720 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<\/p>\n<p>   Device Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sdc1               1       30720    31457264   83  Linux<br \/>\nPRODUCTION linux01 #<br \/>\nNote the amount of cylinders and what the starting cylinder is.  In the example above, it is highlighted in yellow and the starting cylinder is 1.<\/p>\n<p>If the partition to be increased contains system\/OS files, you may need to boot off a rescue disk to perform the resize operation.  Otherwise, it the parition is a data partition, then it simply needs to be unmounted.<\/p>\n<p>Remember to increase the size of the LUN on the NetApp first before proceeding<br \/>\nnetapp> lun resize \/vol\/mylun +5g<\/p>\n<p>PRODUCTION linux01 # umount \/dev\/sdc1<br \/>\nPRODUCTION linux01 # fsck -n \/dev\/sdc1<br \/>\nPRODUCTION linux01 # \/etc\/init.d\/iscsid restart<br \/>\n * Unmounting iscsi partition&#8230; &#8230;<br \/>\n * Logging out of iSCSI targets<br \/>\n * Logging out of session [sid: 1, target: iqn.1992-08.com.netapp:sn.151753609, portal: 10.10.2.2,3260]<br \/>\n * Logout of [sid: 1, target: iqn.1992-08.com.netapp:sn.151753609, portal: 10.10.2.2,3260]: successful<br \/>\n * Stopping iSCSI initiator service &#8230;                                                                                               [ ok ]<br \/>\n * Removing iSCSI modules &#8230;                                                                                                         [ ok ]<br \/>\n * Loading iSCSI modules &#8230;                                                                                                          [ ok ]<br \/>\n * Starting iSCSI initiator service &#8230;                                                                                               [ ok ]<br \/>\n * Logging into iSCSI targets<br \/>\n * Logging in to [iface: default, target: iqn.1992-08.com.netapp:sn.151753609, portal: 10.10.2.2,3260]<br \/>\n * Login to [iface: default, target: iqn.1992-08.com.netapp:sn.151753609, portal: 10.10.2.2,3260]: successful<br \/>\n * Waiting for udev to process new devices<br \/>\n * Mounting iscsi partition&#8230; &#8230;<\/p>\n<p>Note: From the &#8216;fdisk -l&#8217; output below, the device changed from \/dev\/sdc to \/dev\/sdb.  This may happen due to udev during iscsi restart and is normal. You will also notice the amount of cylinders has changed (highlighted in blue) due to the lun size increase command performed on the netapp but the cylidner start\/end is the same as before.<\/p>\n<p>PRODUCTION linux01 # fdisk -l<br \/>\n<snip><\/p>\n<p>Disk \/dev\/sdb: 107.3 GB, 107374182400 bytes<br \/>\n64 heads, 32 sectors\/track, 102400 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<\/p>\n<p>   Device Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sdb1               1       30720    31457264   83  Linux<br \/>\nPRODUCTION linux01 #<\/p>\n<p>Run a file system check to ensure the file system is clean before attempting to change the layout of the partition.<\/p>\n<p>PRODUCTION linux01 # fsck -n \/dev\/sdb1<br \/>\nfsck 1.38 (30-Jun-2005)<br \/>\ne2fsck 1.38 (30-Jun-2005)<br \/>\n\/dev\/sdb1 has gone 701 days without being checked, check forced.<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\n\/lost+found not found.  Create? no<\/p>\n<p>Pass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<\/p>\n<p>\/dev\/sdb1: ********** WARNING: Filesystem still has errors **********<\/p>\n<p>\/dev\/sdb1: 16940\/3932160 files (0.3% non-contiguous), 7425413\/7864316 blocks<br \/>\nIt still has errors because lost+found directory is missing in MY example, but I opted not to create it in this step to avoid further changes to the file system.  Next, convert the file system into an ext2 file system if needed.  The reason is because depending on your kernel, resize2fs may only work on ext2 file systems.  Refer to your man page  In my cases, it doesn&#8217;t support ext3 so remove the journal, delete the current partition table, and recreate it with the new cylinder boundaries.<\/p>\n<p>PRODUCTION linux01 # tune2fs -O ^has_journal \/dev\/sdb1<br \/>\ntune2fs 1.38 (30-Jun-2005)<br \/>\nPRODUCTION linux01 # fdisk \/dev\/sdb<\/p>\n<p>The number of cylinders for this disk is set to 102400.<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  <\/p>\n<p>Disk \/dev\/sdb: 107.3 GB, 107374182400 bytes<br \/>\n64 heads, 32 sectors\/track, 102400 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<\/p>\n<p>   Device Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sdb1               1       30720    31457264   83  Linux<\/p>\n<p>Command (m for help):  d<br \/>\nSelected partition  1  <\/p>\n<p>Command (m for help):  p  <\/p>\n<p>Disk \/dev\/sdb: 107.3 GB, 107374182400 bytes<br \/>\n64 heads, 32 sectors\/track, 102400 cylinders<br \/>\nUnits = cylinders of 2048 * 512 = 1048576 bytes<\/p>\n<p>   Device Boot      Start         End      Blocks   Id  System<\/p>\n<p>Command (m for help):  n<br \/>\nCommand action<br \/>\n   e   extended<br \/>\n   p   primary partition (1-4)<br \/>\n p<br \/>\nPartition number (1-4):  1<br \/>\nFirst cylinder (1-102400, default 1):  1   <-taken from fdisk -l output in preliminary steps.  make sure start cylinder is same as it was before!!! If you get an error like \"Value out of range\", you may need to use parted instead of fdisk.  See footnotes below\nLast cylinder or +size or +sizeM or +sizeK (1-102400, default 102400):\nUsing default value 102400\n\nCommand (m for help):  p \n\nDisk \/dev\/sdb: 107.3 GB, 107374182400 bytes\n64 heads, 32 sectors\/track, 102400 cylinders\nUnits = cylinders of 2048 * 512 = 1048576 bytes\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sdb1               1      102400   104857584   83  Linux\n\nCommand (m for help):  w \nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\nSyncing disks.\n\nRun another file system check.  Note this time we use e2fsck because we're still an ext2 file system.  This time, I created the lost+found, resize the partition, and run another check to ensure it is clean.\n\n\nPRODUCTION linux01 # e2fsck -f \/dev\/sdb1\ne2fsck 1.38 (30-Jun-2005)\nPass 1: Checking inodes, blocks, and sizes\nPass 2: Checking directory structure\nPass 3: Checking directory connectivity\n\/lost+found not found.  Create<y>? yes<\/p>\n<p>Pass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<\/p>\n<p>\/dev\/sdb1: ***** FILE SYSTEM WAS MODIFIED *****<br \/>\n\/dev\/sdb1: 16941\/3932160 files (0.3% non-contiguous), 7392612\/7864316 blocks<br \/>\nPRODUCTION linux01 #<br \/>\nPRODUCTION linux01 # resize2fs \/dev\/sdb1<br \/>\nresize2fs 1.38 (30-Jun-2005)<br \/>\nResizing the filesystem on \/dev\/sdb1 to 26214396 (4k) blocks.<br \/>\nThe filesystem on \/dev\/sdb1 is now 26214396 blocks long.<\/p>\n<p>PRODUCTION linux01 # fsck -n \/dev\/sdb1<br \/>\nfsck 1.38 (30-Jun-2005)<br \/>\ne2fsck 1.38 (30-Jun-2005)<br \/>\n\/dev\/sdb1: clean, 16941\/13107200 files, 7680539\/26214396 blocks<\/p>\n<p>The resize operation is now complete.  Add an ext3 journal to the filesystem and remount the lun.  Enjoy the new size!<\/p>\n<p>PRODUCTION linux01 # tune2fs -j \/dev\/sdb1<br \/>\ntune2fs 1.38 (30-Jun-2005)<br \/>\nCreating journal inode: done<br \/>\nThis filesystem will be automatically checked every 25 mounts or<br \/>\n180 days, whichever comes first.  Use tune2fs -c or -i to override.<br \/>\nPRODUCTION linux01 #<br \/>\nPRODUCTION linux01 # mount \/dev\/sdb1  \/mnt<br \/>\nPRODUCTION linux01 # df -h \/dev\/sdb1<br \/>\nFilesystem            Size  Used Avail Use% Mounted on<br \/>\n\/dev\/sdb1              99G   28G   67G  30% \/var\/services\/db\/mysql<br \/>\nPRODUCTION linux01 #<br \/>\nPRODUCTION linux01 # ls -l \/mnt<br \/>\ntotal 28853216<br \/>\ndrwx&#8212;&#8212; 2 mysql mysql        4096 Jul 30 22:47 database22_100<br \/>\ndrwx&#8212;&#8212; 2 mysql mysql        4096 Jul 30 22:47 database22_101<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_102<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_103<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_104<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_105<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_106<br \/>\ndrwx&#8212;&#8212; 2 mysql users        4096 Jul 30 22:47 database22_107<br \/>\n&#8230;<br \/>\n&#8230;<br \/>\nFootnotes<\/p>\n<p>In this example, fdisk supplied an error &#8220;Value out of range&#8221; when trying to set a starting cyclinger to a value less than 2048.  I had an incident where a LUNs starting cyclinder was 63, and since I did not want to lose the data held between data 63 and 2048, I used parted to repartition the disk.  Having a starting cyclinder of 63 more than likely means not be aligned with the underlying storage, but that&#8217;s another topic.    There may be better ways to do this, but this is how I&#8217;ve worked it out and am documenting it until I have the opportunity to run through the process again.  If improvements can be made, I&#8217;ll update the doc or will review anyone who cares to comment.<\/p>\n<p>PRODUCTION linux101 ~ # parted \/dev\/sdb<br \/>\nGNU Parted 3.1<br \/>\nUsing \/dev\/sdb<br \/>\nWelcome to GNU Parted! Type &#8216;help&#8217; to view a list of commands.<br \/>\n(parted) print<br \/>\nModel: NETAPP LUN (scsi)<br \/>\nDisk \/dev\/sdb: 107GB<br \/>\nSector size (logical\/physical): 512B\/512B<br \/>\nPartition Table: msdos<br \/>\nDisk Flags:<br \/>\nNumber  Start   End    Size   Type     File system  Flags<br \/>\n1      1049kB  107GB  107GB  primary<br \/>\n(parted) unit cyl<br \/>\n(parted) print<br \/>\nModel: NETAPP LUN (scsi)<br \/>\nDisk \/dev\/sdb: 13055cyl<br \/>\nSector size (logical\/physical): 512B\/512B<br \/>\nBIOS cylinder,head,sector geometry: 13055,255,63.  Each cylinder is 8225kB.<br \/>\nPartition Table: msdos<br \/>\nDisk Flags:<br \/>\nNumber  Start  End       Size      Type     File system  Flags<br \/>\n1      0cyl   13054cyl  13054cyl  primary<br \/>\n(parted) unit s (you might have to type &#8216;unit <enter> s&#8217;)<br \/>\n(parted) print<br \/>\nModel: NETAPP LUN (scsi)<br \/>\nDisk \/dev\/sdb: 209743872s<br \/>\nSector size (logical\/physical): 512B\/512B<br \/>\nPartition Table: msdos<br \/>\nDisk Flags:<br \/>\nNumber  Start  End         Size        Type     File system  Flags<br \/>\n1      2048s  209717247s  209715200s  primary<br \/>\n(parted) rm 1<br \/>\n(parted) print<br \/>\nModel: NETAPP LUN (scsi)<br \/>\nDisk \/dev\/sdb: 209743872s<br \/>\nSector size (logical\/physical): 512B\/512B<br \/>\nPartition Table: msdos<br \/>\nDisk Flags:<br \/>\nNumber  Start  End  Size  Type  File system  Flags<br \/>\n(parted) mkpart<br \/>\nPartition type?  primary\/extended? primary<br \/>\nFile system type?  [ext2]? ext3<br \/>\nStart? 63s<br \/>\nEnd? 209717247s    <<< use value from output in print above in matching highlight (see footnote below)                                                       \nWarning: The resulting partition is not properly aligned for best performance.\nIgnore\/Cancel? Ignore                                                     \n(parted) print                                                            \nModel: NETAPP LUN (scsi)\nDisk \/dev\/sdb: 209743872s\nSector size (logical\/physical): 512B\/512B\nPartition Table: msdos\nDisk Flags: \nNumber  Start  End         Size        Type     File system  Flags\n1      63s    209717247s  209717185s  primary  ext2\n(parted) quit                                                             \nInformation: You may need to update \/etc\/fstab.\n\nPRODUCTION atl4mysqlv101 ~ # fdisk -l                                         \nDisk \/dev\/sda: 292.3 GB, 292326211584 bytes\n255 heads, 63 sectors\/track, 35539 cylinders, total 570949632 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x77e3ed41\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sda1              63     8016434     4008186   83  Linux\n\/dev\/sda2         8016435    16032869     4008217+  83  Linux\n\/dev\/sda3        16032870    20049119     2008125   82  Linux swap \/ Solaris\n\/dev\/sda4        20049120   570934034   275442457+   5  Extended\n\/dev\/sda5        20049183    36065924     8008371   83  Linux\n\/dev\/sda6        36065988    52082729     8008371   83  Linux\n\/dev\/sda7        52082793   570934034   259425621   83  Linux\nDisk \/dev\/sdb: 107.4 GB, 107388862464 bytes\n255 heads, 63 sectors\/track, 13055 cylinders, total 209743872 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0005ed03\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/sdb1             63  209717247   104858592+  83  Linux\nPRODUCTION mysqlv101 ~ #\n\nFootnotes:\nIf the end sector matches what it was previous, I've had to use fdisk just to see what the End value is of the extended LUN, then use parted to ensure the use of the correct starting cyl.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Article ID: 83 by: Reese K. Posted: 07 Jan, 2013 Last updated: 13 Mar, 2014 Views: 4849<\/p>\n<p>How To Resize an iscsi LUN in Linux NetApp storage systems also allow you to resize a LUN dynamically; however, the iSCSI layer in Linux is not capable of detecting the change in the LUN size. To display [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4144"}],"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=4144"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4144\/revisions"}],"predecessor-version":[{"id":4145,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4144\/revisions\/4145"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}