LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2012, 06:58 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Rep: Reputation: 51
fdisk /dev/sda << __EOF__: What does this do?


Code:
fdisk /dev/sda << __EOF__
n
p
1

+64M
t
e
p
w
__EOF__
What does this do? Can somebody tell me? I have tried 'fdisk /dev/sda << __EOF__', where /dev/sda is a micro SD memory card connected to the host through USB. A '>' prompt appeared. Then I typed '__EOF__' and I was back in the shell prompt:
Code:
root@darkstar:~# fdisk /dev/sda << __EOF__
> __EOF__

Command (m for help): Command (m for help): Command (m for help): 
got EOF thrice - exiting..
root@darkstar:~#

Kernel 2.6.21.5, Slackware 12.0
 
Old 03-04-2012, 07:06 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

That is a so called HERE-Document construct.

All between both __EOF__ is given to fdisk in this case.

Have a look here: ABSG - Chapter 19. Here Documents

Hope this helps.
 
Old 03-04-2012, 07:11 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,630

Rep: Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529
From 'man bash'
Quote:
Here Strings
A variant of here documents, the format is:

<<<word

The word is expanded and supplied to the command on its standard input.
The code is running fdisk and giving all the commands to fdisk up to __EOF__

Too slow! druuna was quicker.
 
Old 03-04-2012, 07:16 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Original Poster
Rep: Reputation: 51
OK. But then I must take it that n, p, 1, et cetera are commands to fdisk? I do not think so because fdisk only accepts options.
 
Old 03-04-2012, 07:21 AM   #5
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,630

Rep: Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529Reputation: 1529
Reread the quote from 'man bash'. fdisk is receiving commands from standard input.
Those are commands you can type when you run fdisk.
 
Old 03-04-2012, 07:22 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,
Quote:
Originally Posted by stf92 View Post
OK. But then I must take it that n, p, 1, et cetera are commands to fdisk? I do not think so because fdisk only accepts options.
Yes, those are fdisk commands.

From the top of my head:
n - new partition
p 1 - primary, partition no 1
64 Mb (size)
t e - change partition id to "e" (see list for explanation)
p - show partition layout
w - write changes and exit.

Hope this helps.


Too slow! allend was quicker

Last edited by druuna; 03-04-2012 at 07:24 AM.
 
1 members found this post helpful.
Old 03-04-2012, 07:38 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Original Poster
Rep: Reputation: 51
According to its manual, fdisk invoked as 'fdisk /dev/sda' is a menu driven program. So I did:
Code:
root@darkstar:~# fdisk /dev/sda

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): q

root@darkstar:~#
and I see that is the only way to know the commands, for they're not explained in the manual. E.g., how do I know that the p command takes an argument, '1' in the example?
 
Old 03-04-2012, 07:51 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

A here-document is mostly used to automate commands you do often by hand. It does assume that you do know the particulars.

If this is the first time you use fdisk I would advise you not to use a here document but get familiar with fdisk first.

BTW the p used in your here-document is _not_ the p print the partition table option. It is part of the n add a new partition option. After using n more questions are asked (the p and 1 being answers to those questions).

Have a look here: Linux Partition HOWTO - 5. Partitioning with fdisk

Hope this helps.
 
Old 03-04-2012, 08:05 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Original Poster
Rep: Reputation: 51
Here is a more complete part of the story:
Code:
First blank the MMC card's partition table with parted: (/dev/sdX as an example)

sudo parted -s /dev/sdX mklabel msdos

With fdisk: (note: GNU Fdisk doesn't work..)

sudo fdisk /dev/sdX << __EOF__
n
p
1

+64M
t
e
p
w
__EOF__
I've read, in my system's documentation, that cfdisk is a more reliable tool than fdisk. Add to this that I've a high degree of familiarity with cfdisk. So, I intend to use cfdisk. And thanks to druuna:

Quote:
Originally Posted by druuna View Post
Hi,Yes, those are fdisk commands.

From the top of my head:
n - new partition
p 1 - primary, partition no 1
64 Mb (size)
t e - change partition id to "e" (see list for explanation)
p - show partition layout
w - write changes and exit.
I know exactly what to do, except for the t e command. In the quoted post, it is read:

t e - change partition id to "e"

Could you druuna, or someone else, expand a little? The partition id... isn't it, for instance, 0x83 for ext2/ext3, or 0x82 for a linux swap? But what can "e" possibly be?
 
Old 03-04-2012, 08:13 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

The e when using fdisk's t option sets the W95 FAT16 (LBA) system ID.

Have a look at the bold parts:
Code:
$ fdisk /dev/sdb
.
.
.
Command (m for help): t
Partition number (1-8): 7
Hex code (type L to list codes): L

 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot   
 1  FAT12           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 2  XENIX root      39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 5  Extended        41  PPC PReP Boot   85  Linux extended  c7  Syrinx         
 6  FAT16           42  SFS             86  NTFS volume set da  Non-FS data    
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e1  DOS access     
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          e4  SpeedStor      
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  EFI GPT        
10  OPUS            55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f4  SpeedStor      
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fd  Linux raid auto
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fe  LANstep        
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid ff  BBT            
1c  Hidden W95 FAT3 75  PC/IX
I'm not familiar with cfdisk but I'm assuming that all the fdisk functionality is present and can be used the way it is with fdisk in the here-document code. Do make sure you don't make typo's when automating this!

Hope this helps.
 
1 members found this post helpful.
Old 03-04-2012, 09:22 AM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Original Poster
Rep: Reputation: 51
Druuna: you may be wondering what am I aiming at. Briefly stated: I have a very little board called Beagleboard xM, build around an ARM processor, launched on the market by Texas Instruments. A friend of mine asked me to load Linux onto it (Linux embedded), unfortunately of the variety called Ubuntu. OK. To do the job, I decided to follow the instructions contained in this document, 6 Method 3: Manual Install (no automatic scripts).

Following the procedure, I did
Code:
parted -s /dev/sda mklabel msdos
/dev/sda is a micro SD card (just flash memory). The following step in the procedure is the famous fdisk /dev/sda << __EOF__ thing which, having changed my mind, I followed verbatim.

Well, to see what I had done, I used cfdisk to inspect the SD card, and every thing seems alright. The t e command: I did not realize 'e' is just 0x0e!

In the process, I learned what a here-document is and tried my hand with fdisk. No questions, then, in this post except for this: what could the procedure author mean by
Quote:
With fdisk: (note: GNU Fdisk doesn't work..)

sudo fdisk /dev/sdX << __EOF__
And how do I know if the fdisk in my system is GNU? Of course, many thanks for your posts, which I extend to the other people who have written in the thread.
 
Old 03-04-2012, 09:35 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,
Quote:
Originally Posted by stf92 View Post
No questions, then, in this post except for this: what could the procedure author mean by

And how do I know if the fdisk in my system is GNU? Of course, many thanks for your posts, which I extend to the other people who have written in the thread.
There are 2 programs called fdisk. One that can be found in the util-package and a different one from GNU, which is an alternative to the first.

Most linux distro's use the util-linux package. On my Debian box:
Code:
$ /sbin/fdisk -v
fdisk (util-linux-ng 2.17.2)
Hope this helps.
 
1 members found this post helpful.
Old 03-04-2012, 10:04 AM   #13
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,604

Original Poster
Rep: Reputation: 51
On my box I only get
Code:
root@darkstar:~# fdisk -v
fdisk v2.12r
But
Code:
root@darkstar:~# grep -irl fdisk /var/log/packages/
/var/log/packages/util-linux-2.12r-i486-6
So, I think I can be sure its not the GNU fdisk. Thanks again and best regards.
 
Old 03-04-2012, 10:11 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
You're welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to see last cylinder in fdisk /dev/sda parkarnoor Linux - Newbie 1 02-28-2012 01:30 PM
RHEL 6 after boot primary partition shows /dev/sdb instead of /dev/sda vipul_patel Red Hat 1 04-26-2011 09:48 AM
MacBook Pro - fdisk: Unable to open /dev/sda totalboon Slackware - Installation 5 01-04-2011 02:34 AM
fdisk unable to read /dev/sda frankie_DJ Slackware 1 09-08-2005 08:44 PM
Sandisk USB card Reader not linking /dev/sg0 to /dev/sda acidraven Linux - Hardware 1 06-19-2004 03:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration