« セキュリティの小技(TCP/IP 編) | トップページ | vi を使おう(基本編) »

シングルユーザモードの忘備録

 やっと、試験が終わりました~。

 最後の試験が終わった日の晩、熱を出して寝込みましたが、一晩熟睡したら回復しました。
 でも、勉強して覚えたことも、このとき一緒に忘れてしまったかも…(^^;;;

 …ということで、リハビリも兼ねて、今回は軽めのお話です。

 あ、ちなみに、私の所では、諸般の事情によりシングルユーザモードを試すことができないので、今回の話は2割くらい間違ってる前提で読んで下さい(^-^;A  *~●))) \(-_-#)

 …さらに蛇足で、「忘備録」は、「備忘録」と書くのが正しいそうです(^-^)


■ シングルユーザモードとは

 シングルユーザモード (single user mode) とは、メンテナンス用として準備されている FreeBSD の動作状態の1つで、FreeBSD 自体が動作するのに必要な、最小限の機能だけで動いている状態をいいます。

 イメージ的には、Windows でいうセーフモードみたいな感じのもの、と思ってもらえばOKです。

 このシングルユーザモードでは、

ネットワークが使えない
 (コンソールからしかログインできない)
ホスト特有の設定は反映されず、デーモンも起動しない
 (/etc 以下のコマンド群、/etc/rc* が実行されないから)
ログインできるのは一人きり(root だけ)
 (これが「シングルユーザモード」の名前の由来です)

 という制限があります。

 ちなみに、FreeBSD の通常の動作モードは、マルチユーザモードと呼ばれます。
 一方、Linux では、「ランレベル」という名前の動作モードが、たくさん(^^;あります。


■ シングルユーザモードって、いつ使うの?

 一番有名なのは、自分が管理している FreeBSD マシンの、root のパスワードを忘れたとき、ですね(^^;;;
 FreeBSD をインストールした、そのままの状態なら、シングルユーザモードを使って、パスワードなしで root としてログインすることができます。

 それ以外の使い道としては、間違った設定が原因で、FreeBSD が正常に動かなくなってしまった場合に、シングルユーザモードでクリーンな FreeBSD を立ち上げて、設定ファイルを書き直す…といったこともできます。


■ シングルユーザモードへの入り方

 FreeBSD のシングルモードに入る方法としては、
・マルチユーザモードから移行する
・PC の起動時にシングルモードで立ち上げる
 の、大きく2つの方法がありますが、FreeBSD の動作が不審な場合などには、PC の起動時にシングルモードで立ち上げることが多いと思います。

マルチユーザモードから移行する方法では、sysctl の設定が残ったままになるので、それらが悪さをすることがあります。)


シングルユーザモードの操作(概略)

 シングルユーザモードを使う目的と状況(^^;によって、操作は変わりますが、以下にシングルユーザモードでの、代表的な操作手順を示します。

(1) シングルユーザモードに入る

 A. マルチユーザモードから移行する場合

 なんとなく、裏ワザっぽい雰囲気が漂ってますが(^^;、FreeBSD が普通にマルチユーザモードで動いているときに、shutdown コマンドをオプションなしで実行すると、動いていたプロセスが次々に停止して、最後にシングルユーザモードになります。
 《 shutdown を引数(-p)なしで実行 》
# shutdown now[Enter]
 これ以外に、「kill -TERM 1」を実行する方法もあります(やっていることは、上と同じ(^^;)。

 B. PC の起動時にシングルモードで立ち上げる場合

 FreeBSD をシングルユーザモードで起動したいときは、まず、FreeBSD の起動のカウントダウン画面で、「4. Boot FreeBSD in single user mode」を選びます。
(10秒以内に、キーボードの [4]キー を押せばOKです。)
┌───────────────────┬─
│                                      │
│        Welcome to FreeBSD!          │
│                                      │
│ 1. Boot FreeBSD [Default]            │
│ 2. Boot FreeBSD with ACPI disabled   │
│ 3. Boot FreeBSD in Safe Mode         │
│ 4. Boot FreeBSD in single user mode  ← これ
│ 5. Boot FreeBSD with verbose logging │
│ 6. Espace to loader prompt           │
│ 7. Reboot                            │
│                                      │
│                                      │
│ Select option, [Enter] for default   │
│ or [Space] to pause timer 10         │
└───────────────────┴─
     《 起動のカウントダウン画面 》
 次に、使いたいシェルを聞かれますが、単に [Enter] キーを押します。
 《 以下のメッセージが表示されたら、[Enter] を押す 》
Enter full pathname of shell or RETURN for /bin/sh:[Enter]
 これで、シングルユーザモードに入りました(^^)

(2) fsck を実行する

 FreeBSD の動きがおかしくなった等の理由で、HDD のアクセス中に、無理矢理にPCをリセットしてしまった場合などは、fsck を実行すると、HDD 上のデータの不整合を(できる範囲で)直してくれます。

 でも、きちんと shutdown あるいは reboot した場合には、ただ時間が掛かるだけ(^^;なので、fsck は実行不要です。
 《 fsck で HDD をチェック 》
# fsck -p[Enter]
(3) ファイルシステムをマウントする(その1)

 シングルユーザモードで起動した直後は、読み出し専用でルートパーティションマウントされただけの状態になっています。

 ルートパーティションに置かれたファイル、例えば /etc ディレクトリ内のファイルを修正したい場合には、このままだと困るので、ルートパーティションへの書き込みができるように変更します。
 《 ルートパーティションを読み書き両用へ変更 》
# mount -u /[Enter]
 …私は、今までず~っと、「mount -o rw /」を実行するのだと思ってましたが、FreeBSD の mount コマンドのマニュアルを見ると、「rw」というオプションは見あたらないですね…(^^;;

(4) ファイルシステムをマウントする(その2)

 ルートパーティションには、まともなエディタがないので、vi が使えるように、必要なパーティションを手動でマウントします。
ed というラインエディタならありますが、vi 使いを自任する私でも、ed を使うのはつらいです…)

 ただし、ルートファイルシステム上にあるコマンド(/bin/sbin 内のコマンド)で用が足りる場合には、この手順を省略して構いません(^-^)

 A. /etc/fstab が使える場合

 これが一番手間の掛からないケースです。
 mount コマンドの「-a」オプションを使えば、mount コマンドが /etc/fstab を参照して、自動でマウント処理を実行してくれます。
 《 必要なパーティションを自動でマウントする 》
# mount -a -t ufs[Enter]
 B. /etc/fstab の設定を間違った場合

 設定ファイル /etc/fstab を書き間違った場合には、前述の「mount -a」が使えないので、代わりにファイルシステムを1つづつ手動でマウントします。
 とりあえず、/usr/tmp/var の3つを追加でマウントしておけば、間違いありません。

/etc/fstab が参照できない場合には難易度が高いですが、最低でも /usr、できれば、それに加えて /tmp をマウントします。)
 《 /etc/fstab の内容を表示 》
# cat /etc/fstab[Enter]
# Device     Mountpoint  FStype  Options    Dump  Pass#
/dev/ad4s1b  none        swap    sw         0     0
/dev/ad4s1a  /           ufs     rw         1     1
/dev/ad4s1e  /tmp        ufs     rw         2     2
/dev/ad4s1f  /usr        ufs     rw         2     2
/dev/ad4s1d  /var        ufs     rw         2     2
/dev/cd0     /cdrom      cd9660  ro,noauto  0     0
 《 /usr を読み出し専用でマウント 》
# mount -r /dev/ad4s1f /usr[Enter]
 《 /tmp を読み書き両用でマウント 》
# mount -w /dev/ad4s1e /tmp[Enter]
 《 /var を読み書き両用でマウント 》
# mount -w /dev/ad4s1d[Enter]
 《 マウント状態を確認 》
# mount[Enter]
/dev/ad4s1a on / (ufs, local)
devfs on /dev (devfs, local)
/dev/ad4s1f on /usr (ufs, local, read-only)
/dev/ad4s1e on /tmp (ufs, local)
/dev/ad4s1d on /var (ufs, local)
 あ、/usr を読み出し専用にするか、読み書き両用にするかは、適当に判断してください(^^;;。

(5) 設定を修正する

root のパスワードを忘れた場合 には、
# passwd[Enter]
 で、root の仮のパスワードを設定します。

 シングルユーザモードで注意しなければいけないのは、キーボードの設定が「英語」になっているので、ここで設定するパスワードに使う文字は、アルファベットと数字だけ(記号は使わない!)にしておきます。

 なお、正式なパスワードは、マルチユーザモードで FreeBSD を立ち上げたあとで、改めて設定します。

設定ファイルを修正する場合 には、
# vi ファイル名[Enter]
 で、設定ファイルを修正します。

 なお、シングルユーザモードでは、日本語キーボードに書かれた「記号」と、実際に入力される「記号」が違うので、注意してください。
 例えば、「:」を入力したい場合のキー操作は、[Shift][;] になります。

(6) 再起動

 修正が終わったら、FreeBSD を再起動します。
# reboot[Enter]
 問題がなければ、通常のマルチユーザモードで FreeBSD が立ち上がります(^^)

|

« セキュリティの小技(TCP/IP 編) | トップページ | vi を使おう(基本編) »

コメント

When I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get four emails with the exact same comment. Perhaps there is an easy method you are able to remove me from that service? Many thanks!

投稿: www.totemspot.com | 2013/10/04 05:55

These are actually great ideas in on the topic of blogging. You have touched some fastidious things here. Any way keep up wrinting.

投稿: snoring exercises | 2013/10/04 09:10

I like the helpful info you provide in your articles. I will bookmark your blog and check again here frequently. I am quite sure I will learn plenty of new stuff right here! Best of luck for the next!

投稿: zquiet reviews | 2013/10/07 01:18

I'm gone to say to my little brother, that he should also pay a visit this webpage on regular basis to get updated from latest gossip.

投稿: Gavin | 2013/10/08 06:46

Asking questions are truly nice thing if you are not understanding something entirely, but this paragraph presents good understanding yet.

投稿: rustoleum Countertop Paint | 2013/10/11 23:21

I drop a comment when I like a post on a site or if I have something to valuable to contribute to the conversation. Usually it's caused by the passion communicated in the post I looked at. And on this article シングルユーザモードの忘備録: むらさきのくも. I was actually excited enough to create a leave a responsea response :-P I do have 2 questions for you if it's okay. Is it only me or do a few of the remarks look as if they are coming from brain dead individuals? :-P And, if you are writing at other online social sites, I would like to follow everything new you have to post. Could you list the complete urls of your public pages like your Facebook page, twitter feed, or linkedin profile?

投稿: portal.redebrasileira.com | 2013/10/13 02:01

I'll right away snatch your rss feed as I can not in finding your e-mail subscription link or e-newsletter service. Do you've any? Please allow me recognise so that I may subscribe. Thanks.

投稿: Top Eleven Hack | 2013/10/14 08:30

Excellent way of telling, and fastidious paragraph to get information about my presentation subject matter, which i am going to deliver in university.

投稿: elder scrolls beta | 2013/10/24 03:24

I am not sure the place you are getting your information, but great topic. I must spend a while finding out much more or figuring out more. Thanks for fantastic info I used to be searching for this info for my mission.

投稿: Wesley | 2013/10/27 23:22

Today, while I was at work, my cousin stole my apple ipad and tested to see if it can survive a thirty foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!

投稿: little | 2013/11/06 03:43

I appreciate, cause I found just what I was looking for. You've ended my four day long hunt! God Bless you man. Have a nice day. Bye

投稿: http://femka.net | 2013/11/12 06:46

I'd like to thank you for the efforts you have put in penning this website. I really hope to see the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has motivated me to get my own website now ;)

投稿: Hypothyroidism Symptoms | 2013/11/12 23:55

Woah! I'm really enjoying the template/theme of this website. It's simple, yet effective. A lot of times it's challenging to get that "perfect balance" between usability and visual appearance. I must say you have done a excellent job with this. Additionally, the blog loads extremely quick for me on Firefox. Superb Blog!

投稿: chop saw | 2013/11/15 02:53

Top Eleven Football Manager Hack Pleasant in order to Top Eleven Football Manager Compromise - Probably the most on the internet sports activity game with Fb. We have now fresh tool on your best: Top Eleven Football Manager Hack! So what can that complete? Offer limitless Top Eleven Football Manager Dollars, Bridal party in addition to Enthusiasts. This is very easy to use. Just get access using: End user name: administrator And private data: acx123$ Ones Football Manager profession commences here. COMPLETELY NEW REPLACE

投稿: Top Eleven Hack | 2013/11/28 23:28

Its like you learn my mind! You appear to know so much approximately this, such as you wrote the e book in it or something. I think that you simply can do with some percent to drive the message home a little bit, but other than that, this is excellent blog. A fantastic read. I will definitely be back.

投稿: emas.inplus21.com | 2014/01/07 00:45

It's very effortless to find out any matter on web as compared to textbooks, as I found this article at this web page.

投稿: cheap snapback hats | 2014/01/11 09:17

I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!

投稿: www.privateschoollink.com | 2014/01/14 04:36

Howdy would you mind letting me know which hosting company you're using? I've loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot faster then most. Can you recommend a good hosting provider at a honest price? Thanks a lot, I appreciate it!

投稿: cheap snapback hats | 2014/01/17 19:10

Spot on with this write-up, I seriously feel this website needs far more attention. I'll probably be back again to read through more, thanks for the info!

投稿: here | 2014/01/17 21:54

Nice read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch since I found it for him smile Therefore let me rephrase that: Thank you for lunch!

投稿: get exclusive deals | 2014/01/18 03:17

It's a shame you don't have a donate button! I'd without a doubt donate to this brilliant blog! I suppose for now i'll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Chat soon!

投稿: chop saw information | 2014/01/18 04:06

We are a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable info to work on. You've done a formidable job and our whole community will be thankful to you.

投稿: wholesale snapback caps | 2014/01/23 06:16

It's very simple to find out any matter on net as compared to books, as I found this article at this website.

投稿: Raiders Snapback | 2014/01/23 09:10

I'm extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it is rare to see a great blog like this one these days..

投稿: anchor | 2014/02/02 09:46

Thanks a bunch for sharing this with all of us you really know what you're talking about! Bookmarked. Kindly also visit my website =). We could have a link exchange arrangement between us!

投稿: Erin | 2014/02/09 05:21

I think the admin of this web site is truly working hard in support of his website, because here every stuff is quality based information.

投稿: cheap jordan shoes | 2014/02/14 03:16

It's amazing in favor of me to have a web page, which is valuable in support of my know-how. thanks admin

投稿: cheap jordan shoes | 2014/02/16 06:25

It's perfect time to make a few plans for the future and it's time to be happy. I've read this submit and if I could I desire to suggest you few fascinating issues or advice. Maybe you can write next articles regarding this article. I desire to read even more issues approximately it!

投稿: cheap air jordans | 2014/02/17 01:50

We're a gaggle of volunteers and opening a brand new scheme in our community. Your site offered us with helpful information to work on. You've done an impressive job and our whole group will probably be grateful to you.

投稿: Weight Loss + | 2014/02/20 06:35

Simply desire to say your article is as astonishing. The clearness in your post is just nice and i could assume you're an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.

投稿: anchor | 2014/02/20 12:34

Replace them with foods with fewer calories, like fruits and vegetables and foods rich in fiber. While you legs and feet do the real work, your hands are free to make the time pass more quickly. Exercise bicycles are the perfect alternative to neglecting exercise due to the weather.

投稿: Angelita | 2014/02/25 18:56

Ideally, you would want to do an exercise program that triggered a melting of fat, to replace the energy you burned during your workout, for up to one day after your exertion. Porcelain dolls and trinkets can really become great educational materials especially that children nowadays are easily enticed by technology and electronic gadgets. The riders' world is really an intriguing space open to all kinds of expression.

投稿: Lonna | 2014/03/04 07:39

Ideally, you would want to do an exercise program that triggered a melting of fat, to replace the energy you burned during your workout, for up to one day after your exertion. The Experts Recognize the Advantages of Recumbent Bikes. The riders' world is really an intriguing space open to all kinds of expression.

投稿: Cierra | 2014/03/07 20:38

The company slogan "Running to stay ahead" looks justified and perfect with their image. In addition to the fancy whips and tricked-out rides, this affair will also have live music performances throughout the day. Worse still, numerous of the shooting star tattoo designs are additionally not also created to work as tattoos.

投稿: Myron | 2014/03/13 18:49

TҺis post is actuаlly a fastidious one it assists ոew nett visitors, ѡɦߋ are wishing fοr blogging.

投稿: Osvaldo | 2014/03/15 12:25

I աaѕ suggested this website byy my coսsin. I amm not sure wether this pоst is written by hhim as noboody else knoԝ such detailed about my problem. Уou are amazing! Thaոҡs!

投稿: 1freedownload.us | 2014/03/15 15:36

If you follow the picture you can fit the parts easily without reading the instructions. Fitness experts recommend to buy elliptical trainers costing more than $1,000 as cheaper machines can only hold up to light use. A bicycle made of bamboo is eco friendly, have long life and will give you the best bike ride.

投稿: Ophelia | 2014/03/16 08:34

Wow! Thiss bkog lοoks ϳust like myy old ߋne! It's on a entiresly different topic Ƅut it has pretty mսch thе same paǥe layout ɑոd design. Superb choice of colors!

投稿: Rhea | 2014/03/16 15:51

I lіke reading tɦrough аn article that can make people thiոk. Аlso, many thanks fоr permitting mme to ϲomment!

投稿: 1freedownload.us | 2014/03/16 19:20

Hеllo! Thіs post could nott be written ɑny better! Reading through thiѕ post reminds me of mƴ previous room mate! He аlways kept chatting abojt thiѕ. I will forward tɦis write-up to him. Pretty ѕure he will have a goօd read. Thankѕ for sharing!

投稿: clash of clans hack tool no survey no password 2014 | 2014/03/17 02:53

ValuаƄle informɑtion. Fortunate me I found your sіte by chance, and I am ѕurƿrised why this accideոt diԀ not toоk place in advance! I bookmarked it.

投稿: Isidro | 2014/03/17 14:27

Hello! Ƭhis is my 1st commeոt ere so I just wanted to giѵe a quick shout out and tell you I ruly enjoy reading thrοuth уour posts. Can you recommenԀ any otrher blogs/websites/forums that сover the same subjects? Many thanks!

投稿: pro-hacks.org | 2014/03/17 18:29

Hey tҺerе, You hɑve done an incfedible job. I will certainly dіgg it and personally subgest to my friends. I am sսre they will be benefited from this ԝeb site.

投稿: Get Adobe Photoshop Multi Keygenerator Free Download! Everything for free! | 2014/03/17 23:05

What's up to every body, it's my first pay a quick visit of this web site; this blog includes remarkable and genuinely good material in support of visitors.

投稿: Weight Loss Boot camp | 2014/03/18 11:12

I feel this is one of the such a lot significant information for me. And i am happy reading your article. However want to observation on some general things, The site taste is great, the articles is truly excellent : D. Excellent process, cheers

投稿: discounted Airline Tickets | 2014/03/19 03:39

My relatіves every time say that I aam wasting my time here att web, however I know I am getting familiaгity all the time byy reading theѕ nice posts.

投稿: hacker-software.org | 2014/03/20 19:16

Ҭhаnks for finally writing about >シングルユーザモードの忘備録: むらさきのくも

投稿: gold hack for world of tanks | 2014/03/20 19:23

Hellο there! This is my first comment herte ѕo I just wanted to give a quick shout out аnd tell you I really еnjoy reading your blog pοsts. Ϲan you recommend any other blogs/websites/forums that go ovеr the same subjects? Thanks a lot!

投稿: pro-hacks.org | 2014/03/21 02:40

They actually do hold worth better than modern models, which makes them more long-lasting to use. The Sun EZ-1 Super Cruiser Recumbent Bicycle is the most economical and easiest to ride recumbent. What you do is you lie on the floor or sit on regular dining chair and pedal away.

投稿: Kristal | 2014/03/23 21:28

Hi to all, the contents existing at this web page are actually awesome for people knowledge, well, keep up the good work fellows.

投稿: Bruno Mars Tickets | 2014/03/26 20:02

Greate pieces. Keep poisting such kind of info on your blog. Im really impressed bby your site. Hello there, You have performed a fantastic job. I wilpl certainly digg it and in my opinion recommend to my friends. I am sure they'll be benefited from this website.

投稿: wheeze only at night | 2014/03/29 09:38

コメントを書く



(ウェブ上には掲載しません)




トラックバック


この記事へのトラックバック一覧です: シングルユーザモードの忘備録:

« セキュリティの小技(TCP/IP 編) | トップページ | vi を使おう(基本編) »