Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:~#
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.
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?
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).
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
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?
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!
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.